@ms-cloudpack/api-server 0.8.0 → 0.9.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/addPackageOverride.d.ts +85 -96
- package/lib/apis/addPackageOverride.d.ts.map +1 -1
- package/lib/apis/addPackageOverride.js +21 -10
- package/lib/apis/addPackageOverride.js.map +1 -1
- package/lib/apis/getData.d.ts +66 -0
- package/lib/apis/getData.d.ts.map +1 -0
- package/lib/apis/getData.js +11 -0
- package/lib/apis/getData.js.map +1 -0
- package/lib/apis/getSessionId.d.ts +54 -0
- package/lib/apis/getSessionId.d.ts.map +1 -0
- package/lib/apis/getSessionId.js +8 -0
- package/lib/apis/getSessionId.js.map +1 -0
- package/lib/apis/index.d.ts +10 -0
- package/lib/apis/index.d.ts.map +1 -0
- package/lib/apis/index.js +10 -0
- package/lib/apis/index.js.map +1 -0
- package/lib/apis/onDataChanged.d.ts +69 -0
- package/lib/apis/onDataChanged.d.ts.map +1 -0
- package/lib/apis/onDataChanged.js +20 -0
- package/lib/apis/onDataChanged.js.map +1 -0
- package/lib/apis/openCodeEditor.d.ts +69 -96
- package/lib/apis/openCodeEditor.d.ts.map +1 -1
- package/lib/apis/openCodeEditor.js +9 -8
- package/lib/apis/openCodeEditor.js.map +1 -1
- package/lib/apis/openConfigEditor.d.ts +39 -86
- package/lib/apis/openConfigEditor.d.ts.map +1 -1
- package/lib/apis/openConfigEditor.js +6 -2
- package/lib/apis/openConfigEditor.js.map +1 -1
- package/lib/apis/openFilePath.d.ts +50 -92
- package/lib/apis/openFilePath.d.ts.map +1 -1
- package/lib/apis/openFilePath.js +9 -8
- package/lib/apis/openFilePath.js.map +1 -1
- package/lib/apis/reportMetric.d.ts +55 -93
- package/lib/apis/reportMetric.d.ts.map +1 -1
- package/lib/apis/reportMetric.js +7 -6
- package/lib/apis/reportMetric.js.map +1 -1
- package/lib/apis/validatePackageOverride.d.ts +73 -98
- package/lib/apis/validatePackageOverride.d.ts.map +1 -1
- package/lib/apis/validatePackageOverride.js +11 -8
- package/lib/apis/validatePackageOverride.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/trpc/common.d.ts +68 -0
- package/lib/trpc/common.d.ts.map +1 -0
- package/lib/{trpc.js → trpc/common.js} +2 -2
- package/lib/trpc/common.js.map +1 -0
- package/lib/trpc/connectBusToClient.d.ts +8 -0
- package/lib/trpc/connectBusToClient.d.ts.map +1 -0
- package/lib/trpc/connectBusToClient.js +28 -0
- package/lib/trpc/connectBusToClient.js.map +1 -0
- package/lib/trpc/createAppRouter.d.ts +453 -0
- package/lib/trpc/createAppRouter.d.ts.map +1 -0
- package/lib/trpc/createAppRouter.js +9 -0
- package/lib/trpc/createAppRouter.js.map +1 -0
- package/lib/trpc/createCloudpackClient.d.ts +13 -0
- package/lib/trpc/createCloudpackClient.d.ts.map +1 -0
- package/lib/trpc/createCloudpackClient.js +53 -0
- package/lib/trpc/createCloudpackClient.js.map +1 -0
- package/lib/trpc/createCloudpackServer.d.ts +63 -0
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -0
- package/lib/trpc/createCloudpackServer.js +52 -0
- package/lib/trpc/createCloudpackServer.js.map +1 -0
- package/lib/trpc/createContextFactory.d.ts +32 -0
- package/lib/trpc/createContextFactory.d.ts.map +1 -0
- package/lib/{createContextFactory.js → trpc/createContextFactory.js} +8 -15
- package/lib/trpc/createContextFactory.js.map +1 -0
- package/lib/trpc/createRouterFromApis.d.ts +26 -0
- package/lib/trpc/createRouterFromApis.d.ts.map +1 -0
- package/lib/trpc/createRouterFromApis.js +9 -0
- package/lib/trpc/createRouterFromApis.js.map +1 -0
- package/lib/{trpc-adapters → trpc}/httpAdapter.d.ts +10 -5
- package/lib/trpc/httpAdapter.d.ts.map +1 -0
- package/lib/trpc/httpAdapter.js +59 -0
- package/lib/trpc/httpAdapter.js.map +1 -0
- package/lib/utilities/ignoreSelfSignedCertErrors.d.ts +5 -0
- package/lib/utilities/ignoreSelfSignedCertErrors.d.ts.map +1 -0
- package/lib/utilities/ignoreSelfSignedCertErrors.js +15 -0
- package/lib/utilities/ignoreSelfSignedCertErrors.js.map +1 -0
- package/package.json +1 -1
- package/lib/apis/bus.d.ts +0 -103
- package/lib/apis/bus.d.ts.map +0 -1
- package/lib/apis/bus.js +0 -23
- package/lib/apis/bus.js.map +0 -1
- package/lib/apis/restartAllTasks.d.ts +0 -93
- package/lib/apis/restartAllTasks.d.ts.map +0 -1
- package/lib/apis/restartAllTasks.js +0 -18
- package/lib/apis/restartAllTasks.js.map +0 -1
- package/lib/apis/restartTask.d.ts +0 -99
- package/lib/apis/restartTask.d.ts.map +0 -1
- package/lib/apis/restartTask.js +0 -14
- package/lib/apis/restartTask.js.map +0 -1
- package/lib/appRouter.d.ts +0 -924
- package/lib/appRouter.d.ts.map +0 -1
- package/lib/appRouter.js +0 -22
- package/lib/appRouter.js.map +0 -1
- package/lib/createCloudpackClient.d.ts +0 -17
- package/lib/createCloudpackClient.d.ts.map +0 -1
- package/lib/createCloudpackClient.js +0 -57
- package/lib/createCloudpackClient.js.map +0 -1
- package/lib/createCloudpackServer.d.ts +0 -49
- package/lib/createCloudpackServer.d.ts.map +0 -1
- package/lib/createCloudpackServer.js +0 -26
- package/lib/createCloudpackServer.js.map +0 -1
- package/lib/createCloudpackWebClient.d.ts +0 -2
- package/lib/createCloudpackWebClient.d.ts.map +0 -1
- package/lib/createCloudpackWebClient.js +0 -9
- package/lib/createCloudpackWebClient.js.map +0 -1
- package/lib/createContextFactory.d.ts +0 -58
- package/lib/createContextFactory.d.ts.map +0 -1
- package/lib/createContextFactory.js.map +0 -1
- package/lib/trpc-adapters/httpAdapter.d.ts.map +0 -1
- package/lib/trpc-adapters/httpAdapter.js +0 -37
- package/lib/trpc-adapters/httpAdapter.js.map +0 -1
- package/lib/trpc-adapters/httpsAdapter.d.ts +0 -1
- package/lib/trpc-adapters/httpsAdapter.d.ts.map +0 -1
- package/lib/trpc-adapters/httpsAdapter.js +0 -2
- package/lib/trpc-adapters/httpsAdapter.js.map +0 -1
- package/lib/trpc.d.ts +0 -143
- package/lib/trpc.d.ts.map +0 -1
- package/lib/trpc.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { applyWSSHandler } from '@trpc/server/adapters/ws';
|
|
2
|
+
import getPort from 'get-port';
|
|
3
|
+
import { WebSocketServer } from 'ws';
|
|
4
|
+
import { createAppRouter } from './createAppRouter.js';
|
|
5
|
+
import { createContextFactory } from './createContextFactory.js';
|
|
6
|
+
import { createHTTPServer } from './httpAdapter.js';
|
|
7
|
+
import cors from 'cors';
|
|
8
|
+
export async function createCloudpackServer(options) {
|
|
9
|
+
const createContext = await createContextFactory(options);
|
|
10
|
+
const hostname = options.session.config?.devServer?.domain || 'localhost';
|
|
11
|
+
const https = options.session.config?.devServer?.https;
|
|
12
|
+
const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
13
|
+
const { router, apis } = createAppRouter();
|
|
14
|
+
const { server, listen } = createHTTPServer({
|
|
15
|
+
middleware: cors(),
|
|
16
|
+
router,
|
|
17
|
+
createContext,
|
|
18
|
+
https,
|
|
19
|
+
});
|
|
20
|
+
const webSocketProtocol = https ? 'wss' : 'ws';
|
|
21
|
+
const wss = new WebSocketServer({ server });
|
|
22
|
+
applyWSSHandler({
|
|
23
|
+
wss,
|
|
24
|
+
router,
|
|
25
|
+
createContext,
|
|
26
|
+
});
|
|
27
|
+
listen(port, hostname);
|
|
28
|
+
const localCallContext = await createContext();
|
|
29
|
+
const apisWithContext = withContext(apis, localCallContext);
|
|
30
|
+
return {
|
|
31
|
+
...apisWithContext,
|
|
32
|
+
url: `${webSocketProtocol}://${hostname}:${port}`,
|
|
33
|
+
port,
|
|
34
|
+
ctx: localCallContext,
|
|
35
|
+
close: async () => {
|
|
36
|
+
await localCallContext.dispose();
|
|
37
|
+
server.close();
|
|
38
|
+
wss.close();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Helper to tie the local call context with the apis so callers don't have to cache them. */
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
function withContext(apis, ctx) {
|
|
45
|
+
return Object.entries(apis).reduce((acc, [key, apiFunction]) => {
|
|
46
|
+
acc[key] = (input) =>
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
48
|
+
apiFunction({ input, ctx });
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=createCloudpackServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,eAAe,EAAkB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAK3C;IACC,MAAM,aAAa,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,WAAW,CAAC;IAC1E,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,IAAI,EAAE,GAAG,eAAe,EAAE,CAAC;IAC3C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC;QAC1C,UAAU,EAAE,IAAI,EAAE;QAClB,MAAM;QACN,aAAa;QACb,KAAK;KACN,CAAC,CAAC;IACH,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,MAAM,GAAG,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAE5C,eAAe,CAAY;QACzB,GAAG;QACH,MAAM;QACN,aAAa;KACd,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEvB,MAAM,gBAAgB,GAAG,MAAM,aAAa,EAAE,CAAC;IAC/C,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAE5D,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,EAAE,GAAG,iBAAiB,MAAM,QAAQ,IAAI,IAAI,EAAE;QACjD,IAAI;QACJ,GAAG,EAAE,gBAAgB;QAErB,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8FAA8F;AAC9F,8DAA8D;AAC9D,SAAS,WAAW,CAClB,IAAW,EACX,GAAa;IAEb,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAChC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;QAC1B,GAAG,CAAC,GAAkB,CAAC,GAAG,CAAC,KAAgD,EAAE,EAAE;QAC7E,+DAA+D;QAC/D,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAuG,CACxG,CAAC;AACJ,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { Span } from '@ms-cloudpack/telemetry';\nimport { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\nimport type { Session } from '../types/Session.js';\nimport { createAppRouter, type AppRouter } from './createAppRouter.js';\nimport { createContextFactory } from './createContextFactory.js';\nimport { createHTTPServer } from './httpAdapter.js';\nimport cors from 'cors';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport async function createCloudpackServer(options: {\n session: Session;\n rootSpan: Span | undefined;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}) {\n const createContext = await createContextFactory(options);\n const hostname = options.session.config?.devServer?.domain || 'localhost';\n const https = options.session.config?.devServer?.https;\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const { router, apis } = createAppRouter();\n const { server, listen } = createHTTPServer({\n middleware: cors(),\n router,\n createContext,\n https,\n });\n const webSocketProtocol = https ? 'wss' : 'ws';\n const wss = new WebSocketServer({ server });\n\n applyWSSHandler<AppRouter>({\n wss,\n router,\n createContext,\n });\n\n listen(port, hostname);\n\n const localCallContext = await createContext();\n const apisWithContext = withContext(apis, localCallContext);\n\n return {\n ...apisWithContext,\n url: `${webSocketProtocol}://${hostname}:${port}`,\n port,\n ctx: localCallContext,\n\n close: async () => {\n await localCallContext.dispose();\n server.close();\n wss.close();\n },\n };\n}\n\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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import type { Span } from '@ms-cloudpack/telemetry';
|
|
3
|
+
import type { Session } from '../types/Session.js';
|
|
4
|
+
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
5
|
+
/**
|
|
6
|
+
* Creates the server context and returns a connection context factory.
|
|
7
|
+
* The context object is accessible to apis and serves as a way to share stateful
|
|
8
|
+
* objects across them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createContextFactory(options: {
|
|
11
|
+
session: Session;
|
|
12
|
+
reporter: TaskReporter;
|
|
13
|
+
rootSpan?: Span;
|
|
14
|
+
packages: PackageDefinitionsCache;
|
|
15
|
+
}): Promise<() => Promise<{
|
|
16
|
+
session: Session;
|
|
17
|
+
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
18
|
+
rootSpan: Span | undefined;
|
|
19
|
+
reporter: TaskReporter;
|
|
20
|
+
watcher: {
|
|
21
|
+
watch({ path, watchPaths, }: {
|
|
22
|
+
path: string;
|
|
23
|
+
watchPaths?: string[] | undefined;
|
|
24
|
+
}, onPackageChanged: () => void): () => Promise<void>;
|
|
25
|
+
unwatchAll(): Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
packages: PackageDefinitionsCache;
|
|
28
|
+
dispose(): Promise<void>;
|
|
29
|
+
}>>;
|
|
30
|
+
export type CreateContext = Awaited<ReturnType<typeof createContextFactory>>;
|
|
31
|
+
export type Context = Awaited<ReturnType<CreateContext>>;
|
|
32
|
+
//# sourceMappingURL=createContextFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContextFactory.d.ts","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;GAIG;AAEH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,uBAAuB,CAAC;CACnC;;;;;;;;;;;;;;IAyCA;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDataBus } from '@ms-cloudpack/data-bus';
|
|
2
|
-
import {
|
|
2
|
+
import { createWatcher } from '@ms-cloudpack/file-watcher';
|
|
3
3
|
/**
|
|
4
4
|
* Creates the server context and returns a connection context factory.
|
|
5
5
|
* The context object is accessible to apis and serves as a way to share stateful
|
|
@@ -11,37 +11,30 @@ export async function createContextFactory(options) {
|
|
|
11
11
|
// const host = config?.devServer?.domain || 'localhost';
|
|
12
12
|
// const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
13
13
|
// const bus = createDataBus();
|
|
14
|
-
const allTasks = new Map();
|
|
15
|
-
const taskRunner = new TaskRunner();
|
|
16
14
|
const bus = createDataBus();
|
|
17
|
-
|
|
18
|
-
bus.publish([session.id, 'status'], {
|
|
19
|
-
status: 'idle',
|
|
20
|
-
remainingTasks: 0,
|
|
21
|
-
totalTasks: 0,
|
|
22
|
-
totalErrors: 0,
|
|
23
|
-
totalWarnings: 0,
|
|
24
|
-
});
|
|
15
|
+
const watcher = createWatcher();
|
|
25
16
|
// Return the factory function which creates a context object per connection. This allows
|
|
26
17
|
// us to choose what we expose to each client from server context, but also allows us to
|
|
27
18
|
// add additional context to each connection.
|
|
28
19
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
29
20
|
async function createContext() {
|
|
30
|
-
console.log('creating outer context');
|
|
31
21
|
return {
|
|
32
22
|
// session manager
|
|
33
23
|
session,
|
|
34
24
|
// data bus
|
|
35
25
|
bus,
|
|
36
|
-
// tasks
|
|
37
|
-
allTasks,
|
|
38
|
-
taskRunner,
|
|
39
26
|
// telemetry
|
|
40
27
|
rootSpan,
|
|
41
28
|
// logging
|
|
42
29
|
reporter,
|
|
30
|
+
// file watcher
|
|
31
|
+
watcher,
|
|
43
32
|
// packages
|
|
44
33
|
packages,
|
|
34
|
+
// dispose things that the context creates.
|
|
35
|
+
async dispose() {
|
|
36
|
+
await watcher.unwatchAll();
|
|
37
|
+
},
|
|
45
38
|
};
|
|
46
39
|
}
|
|
47
40
|
return createContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D;;;;GAIG;AACH,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAK1C;IACC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC1D,yDAAyD;IACzD,kEAAkE;IAClE,+BAA+B;IAE/B,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAEhC,yFAAyF;IACzF,wFAAwF;IACxF,6CAA6C;IAC7C,4DAA4D;IAC5D,KAAK,UAAU,aAAa;QAC1B,OAAO;YACL,kBAAkB;YAClB,OAAO;YAEP,WAAW;YACX,GAAG;YAEH,YAAY;YACZ,QAAQ;YAER,UAAU;YACV,QAAQ;YAER,eAAe;YACf,OAAO;YAEP,WAAW;YACX,QAAQ;YAER,2CAA2C;YAC3C,KAAK,CAAC,OAAO;gBACX,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;YAC7B,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { Span } from '@ms-cloudpack/telemetry';\nimport type { Session } from '../types/Session.js';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport { createWatcher } from '@ms-cloudpack/file-watcher';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\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 rootSpan?: Span;\n packages: PackageDefinitionsCache;\n}) {\n const { session, rootSpan, reporter, packages } = options;\n // const host = config?.devServer?.domain || 'localhost';\n // const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n // const bus = createDataBus();\n\n const bus = createDataBus();\n const watcher = createWatcher();\n\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 async function createContext() {\n return {\n // session manager\n session,\n\n // data bus\n bus,\n\n // telemetry\n rootSpan,\n\n // logging\n reporter,\n\n // file watcher\n watcher,\n\n // packages\n packages,\n\n // dispose things that the context creates.\n async dispose() {\n await watcher.unwatchAll();\n },\n };\n }\n\n return createContext;\n}\n\nexport type CreateContext = Awaited<ReturnType<typeof createContextFactory>>;\n\nexport type Context = Awaited<ReturnType<CreateContext>>;\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AnyProcedure } from '@trpc/server';
|
|
2
|
+
export declare function createRouterFromApis<TData extends {
|
|
3
|
+
[key: string]: {
|
|
4
|
+
procedure: AnyProcedure;
|
|
5
|
+
};
|
|
6
|
+
}>(apis: TData): import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
7
|
+
ctx: {
|
|
8
|
+
session: import("../index.js").Session;
|
|
9
|
+
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
10
|
+
rootSpan: import("@opentelemetry/api").Span | undefined;
|
|
11
|
+
reporter: import("@ms-cloudpack/task-reporter").TaskReporter;
|
|
12
|
+
watcher: {
|
|
13
|
+
watch({ path, watchPaths, }: {
|
|
14
|
+
path: string;
|
|
15
|
+
watchPaths?: string[] | undefined;
|
|
16
|
+
}, onPackageChanged: () => void): () => Promise<void>;
|
|
17
|
+
unwatchAll(): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
packages: import("@ms-cloudpack/bundler-types").PackageDefinitionsCache;
|
|
20
|
+
dispose(): Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
meta: object;
|
|
23
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
24
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
25
|
+
}>, { [key in keyof TData]: TData[key]["procedure"]; }>;
|
|
26
|
+
//# sourceMappingURL=createRouterFromApis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRouterFromApis.d.ts","sourceRoot":"","sources":["../../src/trpc/createRouterFromApis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,wBAAgB,oBAAoB,CAAC,KAAK,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,YAAY,CAAA;KAAE,CAAA;CAAE,EAAE,IAAI,EAAE,KAAK;;;;;;;;;;;;;;;;;;;wDAU7G"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { router } from './common.js';
|
|
2
|
+
export function createRouterFromApis(apis) {
|
|
3
|
+
const procedures = Object.entries(apis).reduce((acc, [name, api]) => {
|
|
4
|
+
acc[name] = api.procedure;
|
|
5
|
+
return acc;
|
|
6
|
+
}, {});
|
|
7
|
+
return router(procedures);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=createRouterFromApis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRouterFromApis.js","sourceRoot":"","sources":["../../src/trpc/createRouterFromApis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,oBAAoB,CAA+D,IAAW;IAC5G,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAC5C,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE;QACnB,GAAG,CAAC,IAAmB,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC;QACzC,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAuD,CACxD,CAAC;IAEF,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { AnyProcedure } from '@trpc/server';\nimport { router } from './common.js';\n\nexport function createRouterFromApis<TData extends { [key: string]: { procedure: AnyProcedure } }>(apis: TData) {\n const procedures = Object.entries(apis).reduce(\n (acc, [name, api]) => {\n acc[name as keyof TData] = api.procedure;\n return acc;\n },\n {} as { [key in keyof TData]: TData[key]['procedure'] },\n );\n\n return router(procedures);\n}\n"]}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { AnyRouter } from '@trpc/server';
|
|
3
4
|
import { type NodeHTTPCreateContextFnOptions, type NodeHTTPHandlerOptions } from '@trpc/server/adapters/node-http';
|
|
4
5
|
import http from 'http';
|
|
5
|
-
|
|
6
|
+
import https from 'https';
|
|
7
|
+
import { type HttpsConfig } from '@ms-cloudpack/create-express-app';
|
|
8
|
+
export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse> & {
|
|
9
|
+
https?: HttpsConfig;
|
|
10
|
+
};
|
|
6
11
|
export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
|
|
7
|
-
export declare function createHTTPHandler<TRouter extends AnyRouter>(
|
|
8
|
-
export declare function createHTTPServer<TRouter extends AnyRouter>(
|
|
9
|
-
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
10
|
-
listen: (port: number,
|
|
12
|
+
export declare function createHTTPHandler<TRouter extends AnyRouter>(options: CreateHTTPHandlerOptions<TRouter>): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
13
|
+
export declare function createHTTPServer<TRouter extends AnyRouter>(options: CreateHTTPHandlerOptions<TRouter>): {
|
|
14
|
+
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
15
|
+
listen: (port: number, host?: string) => {
|
|
11
16
|
port: number;
|
|
12
17
|
close: () => void;
|
|
13
18
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAdapter.d.ts","sourceRoot":"","sources":["../../src/trpc/httpAdapter.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,sBAAsB,EAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAEtF,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAAI,sBAAsB,CACtF,OAAO,EACP,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,GAAG;IAAE,KAAK,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAE5B,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAEjH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC,SAClF,KAAK,eAAe,OAAO,KAAK,cAAc,mBAgBlE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC;;mBAgCnF,MAAM,SAAS,MAAM;;;;EAavC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { nodeHTTPRequestHandler, } from '@trpc/server/adapters/node-http';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import https from 'https';
|
|
4
|
+
import { parseHttpsConfig } from '@ms-cloudpack/create-express-app';
|
|
5
|
+
export function createHTTPHandler(options) {
|
|
6
|
+
return async (req, res) => {
|
|
7
|
+
// if no hostname, set a dummy one so that we can consistently parse the pathname.
|
|
8
|
+
const url = req.url;
|
|
9
|
+
const href = url.startsWith('/') ? `http://127.0.0.1${url}` : url;
|
|
10
|
+
// get procedure path and remove the leading slash
|
|
11
|
+
// /procedure -> procedure
|
|
12
|
+
const path = new URL(href).pathname.slice(1);
|
|
13
|
+
await nodeHTTPRequestHandler({
|
|
14
|
+
...options,
|
|
15
|
+
req,
|
|
16
|
+
res,
|
|
17
|
+
path,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function createHTTPServer(options) {
|
|
22
|
+
const handler = createHTTPHandler(options);
|
|
23
|
+
const { https: httpsOptions } = options;
|
|
24
|
+
let server;
|
|
25
|
+
if (httpsOptions) {
|
|
26
|
+
const { key, cert, passphrase } = parseHttpsConfig(httpsOptions);
|
|
27
|
+
if (!key || !cert) {
|
|
28
|
+
console.error('Invalid https config in cloudpack.config.json. Make sure key and cert are valid.');
|
|
29
|
+
throw new Error('Invalid https config.');
|
|
30
|
+
}
|
|
31
|
+
server = https.createServer({
|
|
32
|
+
key,
|
|
33
|
+
cert,
|
|
34
|
+
passphrase,
|
|
35
|
+
},
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
37
|
+
handler);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
server = http.createServer(
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
42
|
+
handler);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
server,
|
|
46
|
+
listen: (port, host) => {
|
|
47
|
+
server.listen(port, host);
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
49
|
+
const actualPort = port === 0 ? server.address().port : port;
|
|
50
|
+
return {
|
|
51
|
+
port: actualPort,
|
|
52
|
+
close: () => {
|
|
53
|
+
server.close();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=httpAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAdapter.js","sourceRoot":"","sources":["../../src/trpc/httpAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAGvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAoB,MAAM,kCAAkC,CAAC;AAUtF,MAAM,UAAU,iBAAiB,CAA4B,OAA0C;IACrG,OAAO,KAAK,EAAE,GAAyB,EAAE,GAAwB,EAAE,EAAE;QACnE,kFAAkF;QAClF,MAAM,GAAG,GAAG,GAAG,CAAC,GAAa,CAAC;QAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAElE,kDAAkD;QAClD,0BAA0B;QAC1B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE7C,MAAM,sBAAsB,CAAC;YAC3B,GAAG,OAAO;YACV,GAAG;YACH,GAAG;YACH,IAAI;SACL,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAA4B,OAA0C;IACpG,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAExC,IAAI,MAAkC,CAAC;IAEvC,IAAI,YAAY,EAAE;QAChB,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAEjE,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAC;YAElG,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;SAC1C;QACD,MAAM,GAAG,KAAK,CAAC,YAAY,CACzB;YACE,GAAG;YACH,IAAI;YACJ,UAAU;SACX;QACD,kEAAkE;QAClE,OAAO,CACR,CAAC;KACH;SAAM;QACL,MAAM,GAAG,IAAI,CAAC,YAAY;QACxB,kEAAkE;QAClE,OAAO,CACR,CAAC;KACH;IAED,OAAO;QACL,MAAM;QACN,MAAM,EAAE,CAAC,IAAY,EAAE,IAAa,EAAE,EAAE;YACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1B,0GAA0G;YAC1G,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAG,MAAM,CAAC,OAAO,EAAU,CAAC,IAAe,CAAC,CAAC,CAAC,IAAI,CAAC;YAElF,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,GAAG,EAAE;oBACV,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AnyRouter } from '@trpc/server';\nimport {\n nodeHTTPRequestHandler,\n type NodeHTTPCreateContextFnOptions,\n type NodeHTTPHandlerOptions,\n} from '@trpc/server/adapters/node-http';\nimport http from 'http';\nimport https from 'https';\nimport { parseHttpsConfig, type HttpsConfig } from '@ms-cloudpack/create-express-app';\n\nexport type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<\n TRouter,\n http.IncomingMessage,\n http.ServerResponse\n> & { https?: HttpsConfig };\n\nexport type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;\n\nexport function createHTTPHandler<TRouter extends AnyRouter>(options: CreateHTTPHandlerOptions<TRouter>) {\n return async (req: http.IncomingMessage, res: http.ServerResponse) => {\n // if no hostname, set a dummy one so that we can consistently parse the pathname.\n const url = req.url as string;\n const href = url.startsWith('/') ? `http://127.0.0.1${url}` : url;\n\n // get procedure path and remove the leading slash\n // /procedure -> procedure\n const path = new URL(href).pathname.slice(1);\n\n await nodeHTTPRequestHandler({\n ...options,\n req,\n res,\n path,\n });\n };\n}\n\nexport function createHTTPServer<TRouter extends AnyRouter>(options: CreateHTTPHandlerOptions<TRouter>) {\n const handler = createHTTPHandler(options);\n const { https: httpsOptions } = options;\n\n let server: http.Server | https.Server;\n\n if (httpsOptions) {\n const { key, cert, passphrase } = parseHttpsConfig(httpsOptions);\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 server = https.createServer(\n {\n key,\n cert,\n passphrase,\n },\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n handler,\n );\n } else {\n server = http.createServer(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n handler,\n );\n }\n\n return {\n server,\n listen: (port: number, host?: string) => {\n server.listen(port, host);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const actualPort = port === 0 ? ((server.address() as any).port as number) : port;\n\n return {\n port: actualPort,\n close: () => {\n server.close();\n },\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignoreSelfSignedCertErrors.d.ts","sourceRoot":"","sources":["../../src/utilities/ignoreSelfSignedCertErrors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,wBAAgB,0BAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,YAAY,CAAA;CAAE,QAcnF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function ignoreSelfSignedCertErrors({ reporter }) {
|
|
2
|
+
if (typeof process !== 'undefined') {
|
|
3
|
+
// When using self-signed certificates for the api server, node fails to make requests unless we set
|
|
4
|
+
// `process.env.TLS_REJECT_UNAUTHORIZED` to 0.
|
|
5
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
6
|
+
// When we do this, node creates a console.error that we need to ignore:
|
|
7
|
+
//
|
|
8
|
+
// (node:26988) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0'
|
|
9
|
+
// makes TLS connections and HTTPS requests insecure by disabling certificate verification.
|
|
10
|
+
if (reporter) {
|
|
11
|
+
reporter.ignoreLogMessage('Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ignoreSelfSignedCertErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignoreSelfSignedCertErrors.js","sourceRoot":"","sources":["../../src/utilities/ignoreSelfSignedCertErrors.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,0BAA0B,CAAC,EAAE,QAAQ,EAA+B;IAClF,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAClC,oGAAoG;QACpG,8CAA8C;QAC9C,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,GAAG,CAAC;QAE/C,wEAAwE;QACxE,EAAE;QACF,6FAA6F;QAC7F,2FAA2F;QAC3F,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,gBAAgB,CAAC,wEAAwE,CAAC,CAAC;SACrG;KACF;AACH,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\n\nexport function ignoreSelfSignedCertErrors({ reporter }: { reporter?: TaskReporter }) {\n if (typeof process !== 'undefined') {\n // When using self-signed certificates for the api server, node fails to make requests unless we set\n // `process.env.TLS_REJECT_UNAUTHORIZED` to 0.\n process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';\n\n // When we do this, node creates a console.error that we need to ignore:\n //\n // (node:26988) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0'\n // makes TLS connections and HTTPS requests insecure by disabling certificate verification.\n if (reporter) {\n reporter.ignoreLogMessage('Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable');\n }\n }\n}\n"]}
|
package/package.json
CHANGED
package/lib/apis/bus.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "bus" is a resource, defined as a procedure. This is where
|
|
3
|
-
* TRPC gets a little awkward. By defining "bus" as a noun
|
|
4
|
-
* rather than a verb+noun, the client can subscribe to it
|
|
5
|
-
* using a reasonable syntax: client.bus.subscribe().
|
|
6
|
-
*/
|
|
7
|
-
export declare const bus: import("@trpc/server").BuildProcedure<"subscription", {
|
|
8
|
-
_config: import("@trpc/server").RootConfig<{
|
|
9
|
-
ctx: {
|
|
10
|
-
session: import("../index.js").Session;
|
|
11
|
-
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
12
|
-
allTasks: Map<string, {
|
|
13
|
-
id: string;
|
|
14
|
-
startTime: number;
|
|
15
|
-
status?: "pending" | "complete" | undefined;
|
|
16
|
-
name?: string | undefined;
|
|
17
|
-
inputPath?: string | undefined;
|
|
18
|
-
outputPath?: string | undefined;
|
|
19
|
-
timings?: {
|
|
20
|
-
name: string;
|
|
21
|
-
start: number;
|
|
22
|
-
end?: number | undefined;
|
|
23
|
-
threwException?: boolean | undefined;
|
|
24
|
-
}[] | undefined;
|
|
25
|
-
durationMilliseconds?: number | undefined;
|
|
26
|
-
lastUpdated?: number | undefined;
|
|
27
|
-
errors?: {
|
|
28
|
-
message: string;
|
|
29
|
-
pluginName: string;
|
|
30
|
-
stack: string;
|
|
31
|
-
fileLocation: string;
|
|
32
|
-
lineNumber: number;
|
|
33
|
-
columnNumber: number;
|
|
34
|
-
}[] | undefined;
|
|
35
|
-
warnings?: {
|
|
36
|
-
message: string;
|
|
37
|
-
pluginName: string;
|
|
38
|
-
stack: string;
|
|
39
|
-
fileLocation: string;
|
|
40
|
-
lineNumber: number;
|
|
41
|
-
columnNumber: number;
|
|
42
|
-
}[] | undefined;
|
|
43
|
-
}>;
|
|
44
|
-
taskRunner: import("../utilities/TaskRunner.js").TaskRunner;
|
|
45
|
-
rootSpan: import("@opentelemetry/api").Span | undefined;
|
|
46
|
-
reporter: import("@ms-cloudpack/task-reporter").TaskReporter;
|
|
47
|
-
packages: import("@ms-cloudpack/bundler-types").PackageDefinitionsCache;
|
|
48
|
-
};
|
|
49
|
-
meta: object;
|
|
50
|
-
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
51
|
-
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
52
|
-
}>;
|
|
53
|
-
_meta: object;
|
|
54
|
-
_ctx_out: {
|
|
55
|
-
session: import("../index.js").Session;
|
|
56
|
-
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
57
|
-
allTasks: Map<string, {
|
|
58
|
-
id: string;
|
|
59
|
-
startTime: number;
|
|
60
|
-
status?: "pending" | "complete" | undefined;
|
|
61
|
-
name?: string | undefined;
|
|
62
|
-
inputPath?: string | undefined;
|
|
63
|
-
outputPath?: string | undefined;
|
|
64
|
-
timings?: {
|
|
65
|
-
name: string;
|
|
66
|
-
start: number;
|
|
67
|
-
end?: number | undefined;
|
|
68
|
-
threwException?: boolean | undefined;
|
|
69
|
-
}[] | undefined;
|
|
70
|
-
durationMilliseconds?: number | undefined;
|
|
71
|
-
lastUpdated?: number | undefined;
|
|
72
|
-
errors?: {
|
|
73
|
-
message: string;
|
|
74
|
-
pluginName: string;
|
|
75
|
-
stack: string;
|
|
76
|
-
fileLocation: string;
|
|
77
|
-
lineNumber: number;
|
|
78
|
-
columnNumber: number;
|
|
79
|
-
}[] | undefined;
|
|
80
|
-
warnings?: {
|
|
81
|
-
message: string;
|
|
82
|
-
pluginName: string;
|
|
83
|
-
stack: string;
|
|
84
|
-
fileLocation: string;
|
|
85
|
-
lineNumber: number;
|
|
86
|
-
columnNumber: number;
|
|
87
|
-
}[] | undefined;
|
|
88
|
-
}>;
|
|
89
|
-
taskRunner: import("../utilities/TaskRunner.js").TaskRunner;
|
|
90
|
-
rootSpan: import("@opentelemetry/api").Span | undefined;
|
|
91
|
-
reporter: import("@ms-cloudpack/task-reporter").TaskReporter;
|
|
92
|
-
packages: import("@ms-cloudpack/bundler-types").PackageDefinitionsCache;
|
|
93
|
-
};
|
|
94
|
-
_input_in: {
|
|
95
|
-
path: string[];
|
|
96
|
-
};
|
|
97
|
-
_input_out: {
|
|
98
|
-
path: string[];
|
|
99
|
-
};
|
|
100
|
-
_output_in: any;
|
|
101
|
-
_output_out: any;
|
|
102
|
-
}, import("@trpc/server/observable").Observable<any, unknown>>;
|
|
103
|
-
//# sourceMappingURL=bus.d.ts.map
|
package/lib/apis/bus.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bus.d.ts","sourceRoot":"","sources":["../../src/apis/bus.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8DAgBZ,CAAC"}
|
package/lib/apis/bus.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { publicProcedure, z } from '../trpc.js';
|
|
2
|
-
import { observable } from '@trpc/server/observable';
|
|
3
|
-
/**
|
|
4
|
-
* "bus" is a resource, defined as a procedure. This is where
|
|
5
|
-
* TRPC gets a little awkward. By defining "bus" as a noun
|
|
6
|
-
* rather than a verb+noun, the client can subscribe to it
|
|
7
|
-
* using a reasonable syntax: client.bus.subscribe().
|
|
8
|
-
*/
|
|
9
|
-
export const bus = publicProcedure
|
|
10
|
-
.input(z.object({
|
|
11
|
-
path: z.array(z.string()),
|
|
12
|
-
}))
|
|
13
|
-
.output(z.any())
|
|
14
|
-
.subscription(({ input: { path }, ctx: { bus } }) => {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
return observable((emit) => {
|
|
17
|
-
const dispose = bus.subscribe(path, (value) => {
|
|
18
|
-
emit.next(value);
|
|
19
|
-
});
|
|
20
|
-
return dispose;
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=bus.js.map
|
package/lib/apis/bus.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bus.js","sourceRoot":"","sources":["../../src/apis/bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe;KAC/B,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAC1B,CAAC,CACH;KACA,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;KACf,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE;IAClD,8DAA8D;IAC9D,OAAO,UAAU,CAAM,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { publicProcedure, z } from '../trpc.js';\nimport { observable } from '@trpc/server/observable';\n\n/**\n * \"bus\" is a resource, defined as a procedure. This is where\n * TRPC gets a little awkward. By defining \"bus\" as a noun\n * rather than a verb+noun, the client can subscribe to it\n * using a reasonable syntax: client.bus.subscribe().\n */\nexport const bus = publicProcedure\n .input(\n z.object({\n path: z.array(z.string()),\n }),\n )\n .output(z.any())\n .subscription(({ input: { path }, ctx: { bus } }) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return observable<any>((emit) => {\n const dispose = bus.subscribe(path, (value) => {\n emit.next(value);\n });\n\n return dispose;\n });\n });\n"]}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
export declare const restartAllTasks: import("@trpc/server").BuildProcedure<"mutation", {
|
|
2
|
-
_config: import("@trpc/server").RootConfig<{
|
|
3
|
-
ctx: {
|
|
4
|
-
session: import("../index.js").Session;
|
|
5
|
-
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
6
|
-
allTasks: Map<string, {
|
|
7
|
-
id: string;
|
|
8
|
-
startTime: number;
|
|
9
|
-
status?: "pending" | "complete" | undefined;
|
|
10
|
-
name?: string | undefined;
|
|
11
|
-
inputPath?: string | undefined;
|
|
12
|
-
outputPath?: string | undefined;
|
|
13
|
-
timings?: {
|
|
14
|
-
name: string;
|
|
15
|
-
start: number;
|
|
16
|
-
end?: number | undefined;
|
|
17
|
-
threwException?: boolean | undefined;
|
|
18
|
-
}[] | undefined;
|
|
19
|
-
durationMilliseconds?: number | undefined;
|
|
20
|
-
lastUpdated?: number | undefined;
|
|
21
|
-
errors?: {
|
|
22
|
-
message: string;
|
|
23
|
-
pluginName: string;
|
|
24
|
-
stack: string;
|
|
25
|
-
fileLocation: string;
|
|
26
|
-
lineNumber: number;
|
|
27
|
-
columnNumber: number;
|
|
28
|
-
}[] | undefined;
|
|
29
|
-
warnings?: {
|
|
30
|
-
message: string;
|
|
31
|
-
pluginName: string;
|
|
32
|
-
stack: string;
|
|
33
|
-
fileLocation: string;
|
|
34
|
-
lineNumber: number;
|
|
35
|
-
columnNumber: number;
|
|
36
|
-
}[] | undefined;
|
|
37
|
-
}>;
|
|
38
|
-
taskRunner: import("../utilities/TaskRunner.js").TaskRunner;
|
|
39
|
-
rootSpan: import("@opentelemetry/api").Span | undefined;
|
|
40
|
-
reporter: import("@ms-cloudpack/task-reporter").TaskReporter;
|
|
41
|
-
packages: import("@ms-cloudpack/bundler-types").PackageDefinitionsCache;
|
|
42
|
-
};
|
|
43
|
-
meta: object;
|
|
44
|
-
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
45
|
-
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
46
|
-
}>;
|
|
47
|
-
_ctx_out: {
|
|
48
|
-
session: import("../index.js").Session;
|
|
49
|
-
bus: import("@ms-cloudpack/data-bus").DataBus;
|
|
50
|
-
allTasks: Map<string, {
|
|
51
|
-
id: string;
|
|
52
|
-
startTime: number;
|
|
53
|
-
status?: "pending" | "complete" | undefined;
|
|
54
|
-
name?: string | undefined;
|
|
55
|
-
inputPath?: string | undefined;
|
|
56
|
-
outputPath?: string | undefined;
|
|
57
|
-
timings?: {
|
|
58
|
-
name: string;
|
|
59
|
-
start: number;
|
|
60
|
-
end?: number | undefined;
|
|
61
|
-
threwException?: boolean | undefined;
|
|
62
|
-
}[] | undefined;
|
|
63
|
-
durationMilliseconds?: number | undefined;
|
|
64
|
-
lastUpdated?: number | undefined;
|
|
65
|
-
errors?: {
|
|
66
|
-
message: string;
|
|
67
|
-
pluginName: string;
|
|
68
|
-
stack: string;
|
|
69
|
-
fileLocation: string;
|
|
70
|
-
lineNumber: number;
|
|
71
|
-
columnNumber: number;
|
|
72
|
-
}[] | undefined;
|
|
73
|
-
warnings?: {
|
|
74
|
-
message: string;
|
|
75
|
-
pluginName: string;
|
|
76
|
-
stack: string;
|
|
77
|
-
fileLocation: string;
|
|
78
|
-
lineNumber: number;
|
|
79
|
-
columnNumber: number;
|
|
80
|
-
}[] | undefined;
|
|
81
|
-
}>;
|
|
82
|
-
taskRunner: import("../utilities/TaskRunner.js").TaskRunner;
|
|
83
|
-
rootSpan: import("@opentelemetry/api").Span | undefined;
|
|
84
|
-
reporter: import("@ms-cloudpack/task-reporter").TaskReporter;
|
|
85
|
-
packages: import("@ms-cloudpack/bundler-types").PackageDefinitionsCache;
|
|
86
|
-
};
|
|
87
|
-
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
88
|
-
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
89
|
-
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
90
|
-
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
91
|
-
_meta: object;
|
|
92
|
-
}, void>;
|
|
93
|
-
//# sourceMappingURL=restartAllTasks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restartAllTasks.d.ts","sourceRoot":"","sources":["../../src/apis/restartAllTasks.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAgB1B,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { emptyDir } from 'fs-extra/esm';
|
|
2
|
-
import { publicProcedure } from '../trpc.js';
|
|
3
|
-
import { getCachePath } from '../utilities/getCachePath.js';
|
|
4
|
-
import { notifyReload } from '../utilities/notifyReload.js';
|
|
5
|
-
export const restartAllTasks = publicProcedure.mutation(async ({ ctx: { allTasks, session, bus, taskRunner } }) => {
|
|
6
|
-
console.log('ApiServer: Restarting all tasks');
|
|
7
|
-
// Clear entire local cache.
|
|
8
|
-
await emptyDir(getCachePath());
|
|
9
|
-
// All tasks can be removed as notifyReload()
|
|
10
|
-
// will cause the client to add the tasks again.
|
|
11
|
-
allTasks.forEach((_, id) => {
|
|
12
|
-
taskRunner.remove(id);
|
|
13
|
-
});
|
|
14
|
-
// Update session version.
|
|
15
|
-
session.incrementSessionVersion();
|
|
16
|
-
notifyReload({ bus });
|
|
17
|
-
});
|
|
18
|
-
//# sourceMappingURL=restartAllTasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,YAAY,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE;IAChH,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAE/C,4BAA4B;IAC5B,MAAM,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;IAE/B,6CAA6C;IAC7C,gDAAgD;IAChD,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;QACzB,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAElC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC","sourcesContent":["import { emptyDir } from 'fs-extra/esm';\nimport { publicProcedure } from '../trpc.js';\nimport { getCachePath } from '../utilities/getCachePath.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\n\nexport const restartAllTasks = publicProcedure.mutation(async ({ ctx: { allTasks, session, bus, taskRunner } }) => {\n console.log('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 allTasks.forEach((_, id) => {\n taskRunner.remove(id);\n });\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload({ bus });\n});\n"]}
|