@ms-cloudpack/api-server 0.54.10 → 0.56.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 +4 -19
- package/lib/apis/ensurePackageBundled.d.ts +0 -16
- package/lib/apis/ensurePackageBundled.d.ts.map +1 -1
- package/lib/apis/ensurePackageBundled.js +1 -59
- package/lib/apis/ensurePackageBundled.js.map +1 -1
- package/lib/apis/getData.d.ts +4 -16
- package/lib/apis/getSessionId.d.ts +4 -14
- package/lib/apis/index.d.ts +1 -4
- package/lib/apis/index.d.ts.map +1 -1
- package/lib/apis/index.js +2 -4
- package/lib/apis/index.js.map +1 -1
- package/lib/apis/linkPath.d.ts +4 -19
- package/lib/apis/onDataChanged.d.ts +4 -16
- package/lib/apis/openCodeEditor.d.ts +4 -19
- package/lib/apis/openConfigEditor.d.ts +4 -14
- package/lib/apis/openConfigEditor.d.ts.map +1 -1
- package/lib/apis/openFilePath.d.ts +4 -17
- package/lib/apis/reportSpan.d.ts +36 -0
- package/lib/apis/reportSpan.d.ts.map +1 -0
- package/lib/apis/reportSpan.js +28 -0
- package/lib/apis/reportSpan.js.map +1 -0
- package/lib/apis/restartAllTasks.d.ts +4 -14
- package/lib/apis/restartAllTasks.d.ts.map +1 -1
- package/lib/apis/restartTask.d.ts +4 -17
- package/lib/apis/syncDownload.d.ts +2 -31
- package/lib/apis/syncDownload.d.ts.map +1 -1
- package/lib/apis/syncDownload.js +1 -8
- package/lib/apis/syncDownload.js.map +1 -1
- package/lib/apis/syncUpload.d.ts +2 -31
- package/lib/apis/syncUpload.d.ts.map +1 -1
- package/lib/apis/syncUpload.js +1 -8
- package/lib/apis/syncUpload.js.map +1 -1
- package/lib/apis/unlinkPath.d.ts +4 -19
- package/lib/apis/validatePackageOverride.d.ts +4 -20
- package/lib/data/busSources.d.ts +5 -4
- package/lib/data/busSources.d.ts.map +1 -1
- package/lib/data/busSources.js +1 -2
- package/lib/data/busSources.js.map +1 -1
- package/lib/index.browser.d.ts +0 -8
- package/lib/index.browser.d.ts.map +1 -1
- package/lib/index.browser.js.map +1 -1
- package/lib/index.d.ts +8 -22
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -7
- package/lib/index.js.map +1 -1
- package/lib/trpc/common.d.ts +14 -19
- package/lib/trpc/common.d.ts.map +1 -1
- package/lib/trpc/common.js +1 -1
- package/lib/trpc/common.js.map +1 -1
- package/lib/trpc/connectBusToClient.d.ts +3 -3
- package/lib/trpc/connectBusToClient.d.ts.map +1 -1
- package/lib/trpc/connectBusToClient.js.map +1 -1
- package/lib/trpc/createCloudpackClient.d.ts +3 -5
- package/lib/trpc/createCloudpackClient.d.ts.map +1 -1
- package/lib/trpc/createCloudpackClient.js +4 -2
- package/lib/trpc/createCloudpackClient.js.map +1 -1
- package/lib/trpc/createCloudpackServer.d.ts +5 -66
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
- package/lib/trpc/createCloudpackServer.js +5 -16
- package/lib/trpc/createCloudpackServer.js.map +1 -1
- package/lib/types/AppRouter.d.ts +6 -0
- package/lib/types/AppRouter.d.ts.map +1 -0
- package/lib/types/AppRouter.js +2 -0
- package/lib/types/AppRouter.js.map +1 -0
- package/lib/types/SyncInput.d.ts +6 -0
- package/lib/types/SyncInput.d.ts.map +1 -0
- package/lib/types/SyncInput.js +2 -0
- package/lib/types/SyncInput.js.map +1 -0
- package/package.json +13 -13
- package/lib/apis/reportMetric.d.ts +0 -43
- package/lib/apis/reportMetric.d.ts.map +0 -1
- package/lib/apis/reportMetric.js +0 -23
- package/lib/apis/reportMetric.js.map +0 -1
- package/lib/trpc/createAppRouter.d.ts +0 -325
- package/lib/trpc/createAppRouter.d.ts.map +0 -1
- package/lib/trpc/createAppRouter.js +0 -9
- package/lib/trpc/createAppRouter.js.map +0 -1
- package/lib/trpc/createRouterFromApis.d.ts +0 -12
- package/lib/trpc/createRouterFromApis.d.ts.map +0 -1
- package/lib/trpc/createRouterFromApis.js +0 -9
- package/lib/trpc/createRouterFromApis.js.map +0 -1
- package/lib/types/ApiServer.d.ts +0 -6
- package/lib/types/ApiServer.d.ts.map +0 -1
- package/lib/types/ApiServer.js +0 -2
- package/lib/types/ApiServer.js.map +0 -1
- package/lib/types/ErrorEntry.d.ts +0 -4
- package/lib/types/ErrorEntry.d.ts.map +0 -1
- package/lib/types/ErrorEntry.js +0 -3
- package/lib/types/ErrorEntry.js.map +0 -1
- package/lib/types/ZodLoginMethod.d.ts +0 -3
- package/lib/types/ZodLoginMethod.d.ts.map +0 -1
- package/lib/types/ZodLoginMethod.js +0 -3
- package/lib/types/ZodLoginMethod.js.map +0 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { DataBus } from '@ms-cloudpack/data-bus';
|
|
2
1
|
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
3
|
-
import type {
|
|
4
|
-
import type { AppRouter } from '
|
|
5
|
-
export type CloudpackClient =
|
|
6
|
-
bus: DataBus;
|
|
2
|
+
import type { CreateTRPCClient } from '@trpc/client';
|
|
3
|
+
import type { AppRouter } from '../types/AppRouter.js';
|
|
4
|
+
export type CloudpackClient = CreateTRPCClient<AppRouter> & {
|
|
7
5
|
close: () => Promise<void>;
|
|
8
6
|
};
|
|
9
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC,SAAS,CAAC,GAAG;IAC1D,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,CAAC,CAmD3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
2
|
-
import {
|
|
2
|
+
import { createTRPCClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';
|
|
3
3
|
import { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';
|
|
4
4
|
import { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';
|
|
5
5
|
/**
|
|
@@ -10,18 +10,20 @@ export async function createCloudpackClient(options) {
|
|
|
10
10
|
await ensureWebsocketDefined();
|
|
11
11
|
ignoreSelfSignedCertErrors({ reporter: options.reporter });
|
|
12
12
|
// Create the client.
|
|
13
|
+
// eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109
|
|
13
14
|
const wsClient = createWSClient(options);
|
|
14
15
|
const tempUrl = makeUrl(options.url);
|
|
15
16
|
// Replace the protocol with http so that we can use the same url for http requests.
|
|
16
17
|
const isSSL = tempUrl.protocol === 'wss:';
|
|
17
18
|
tempUrl.protocol = isSSL ? 'https:' : 'http:';
|
|
18
19
|
const url = tempUrl.toString().replace(/\/$/, '');
|
|
19
|
-
const client =
|
|
20
|
+
const client = createTRPCClient({
|
|
20
21
|
links: [
|
|
21
22
|
splitLink({
|
|
22
23
|
condition(op) {
|
|
23
24
|
return op.type === 'subscription';
|
|
24
25
|
},
|
|
26
|
+
// eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109
|
|
25
27
|
true: wsLink({
|
|
26
28
|
client: wsClient,
|
|
27
29
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAOxF;;GAEG;AACH,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,6FAA6F;IAC7F,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,gBAAgB,CAAY;QACzC,KAAK,EAAE;YACL,SAAS,CAAC;gBACR,SAAS,CAAC,EAAE;oBACV,OAAO,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC;gBACpC,CAAC;gBACD,6FAA6F;gBAC7F,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 { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CreateTRPCClient } from '@trpc/client';\nimport { createTRPCClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';\nimport { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';\nimport { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport type CloudpackClient = CreateTRPCClient<AppRouter> & {\n close: () => Promise<void>;\n};\n\n/**\n * Creates a cloudpack client that can be used to communicate with the cloudpack server using trpc.\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 // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109\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 = createTRPCClient<AppRouter>({\n links: [\n splitLink({\n condition(op) {\n return op.type === 'subscription';\n },\n // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109\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,74 +1,13 @@
|
|
|
1
1
|
import type { Context } from '../types/Context.js';
|
|
2
|
+
export interface CloudpackServer {
|
|
3
|
+
url: string;
|
|
4
|
+
close: () => Promise<void>;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Creates a cloudpack server that can be used to communicate with the cloudpack client using trpc.
|
|
4
8
|
*/
|
|
5
9
|
export declare function createCloudpackServer(options: {
|
|
6
10
|
/** Custom port(s) to try for the API server. */
|
|
7
11
|
port?: number | number[];
|
|
8
|
-
}, context: Context): Promise<
|
|
9
|
-
url: string;
|
|
10
|
-
port: number;
|
|
11
|
-
close: () => Promise<void>;
|
|
12
|
-
addPackageOverride: (options: {
|
|
13
|
-
packageName: string;
|
|
14
|
-
importPath: string;
|
|
15
|
-
version?: string | undefined;
|
|
16
|
-
issuerUrl?: string | undefined;
|
|
17
|
-
}) => Promise<boolean>;
|
|
18
|
-
ensurePackageBundled: (options: import("../index.js").EnsurePackageBundledInput) => Promise<import("../index.js").EnsurePackageBundledOutput>;
|
|
19
|
-
getData: (options: {
|
|
20
|
-
path: string[];
|
|
21
|
-
}) => any;
|
|
22
|
-
getSessionId: (options: void) => string | undefined;
|
|
23
|
-
linkPath: (options: {
|
|
24
|
-
linkedPath: import("@ms-cloudpack/common-types").LinkedPath;
|
|
25
|
-
}) => Promise<{
|
|
26
|
-
resolveMap: import("@ms-cloudpack/common-types").ResolveMap;
|
|
27
|
-
linkedPaths: import("@ms-cloudpack/common-types").LinkedPath[];
|
|
28
|
-
}>;
|
|
29
|
-
onDataChanged: (options: {
|
|
30
|
-
path: string[];
|
|
31
|
-
}) => any;
|
|
32
|
-
openCodeEditor: (options: {
|
|
33
|
-
rootPath: string;
|
|
34
|
-
line?: number | undefined;
|
|
35
|
-
column?: number | undefined;
|
|
36
|
-
relativePath?: string | undefined;
|
|
37
|
-
}) => Promise<void>;
|
|
38
|
-
openConfigEditor: (options: void) => Promise<void>;
|
|
39
|
-
openFilePath: (options: {
|
|
40
|
-
rootPath: string;
|
|
41
|
-
relativePath?: string | undefined;
|
|
42
|
-
}) => Promise<void>;
|
|
43
|
-
reportMetric: (options: {
|
|
44
|
-
value: number;
|
|
45
|
-
metric: string;
|
|
46
|
-
additionalProperties?: Record<string, string | number | boolean> | undefined;
|
|
47
|
-
}) => void;
|
|
48
|
-
restartAllTasks: (options: void) => Promise<void>;
|
|
49
|
-
restartTask: (options: {
|
|
50
|
-
id: string;
|
|
51
|
-
inputPath: string;
|
|
52
|
-
}) => void;
|
|
53
|
-
syncDownload: (options: {
|
|
54
|
-
loginMethod: "interactive" | "azure-cli" | "device-code";
|
|
55
|
-
}) => Promise<void>;
|
|
56
|
-
syncUpload: (options: {
|
|
57
|
-
loginMethod: "interactive" | "azure-cli" | "device-code";
|
|
58
|
-
}) => Promise<void>;
|
|
59
|
-
unlinkPath: (options: {
|
|
60
|
-
linkedPath: import("@ms-cloudpack/common-types").LinkedPath;
|
|
61
|
-
}) => Promise<{
|
|
62
|
-
resolveMap: import("@ms-cloudpack/common-types").ResolveMap;
|
|
63
|
-
linkedPaths: import("@ms-cloudpack/common-types").LinkedPath[];
|
|
64
|
-
}>;
|
|
65
|
-
validatePackageOverride: (options: {
|
|
66
|
-
packageName: string;
|
|
67
|
-
importPath: string;
|
|
68
|
-
issuerUrl?: string | undefined;
|
|
69
|
-
}) => Promise<{
|
|
70
|
-
fixable: boolean;
|
|
71
|
-
}>;
|
|
72
|
-
}>;
|
|
73
|
-
export type CloudpackServer = ReturnType<typeof createCloudpackServer>;
|
|
12
|
+
}, context: Context): Promise<CloudpackServer>;
|
|
74
13
|
//# sourceMappingURL=createCloudpackServer.d.ts.map
|
|
@@ -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":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE;IACP,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B,EACD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAgD1B"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { applyWSSHandler } from '@trpc/server/adapters/ws';
|
|
2
2
|
import getPort from 'get-port';
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
|
-
import { createAppRouter } from './createAppRouter.js';
|
|
5
4
|
import { createContextFactory } from './createContextFactory.js';
|
|
6
5
|
import { createHTTPServer } from './httpAdapter.js';
|
|
7
6
|
import cors from 'cors';
|
|
8
7
|
import { getDomain } from '@ms-cloudpack/create-express-app';
|
|
8
|
+
import * as apis from '../apis/index.js';
|
|
9
|
+
import { createRouter } from './common.js';
|
|
9
10
|
/**
|
|
10
11
|
* Creates a cloudpack server that can be used to communicate with the cloudpack client using trpc.
|
|
11
12
|
*/
|
|
@@ -18,7 +19,9 @@ export async function createCloudpackServer(options, context) {
|
|
|
18
19
|
const createContext = await createContextFactory(context);
|
|
19
20
|
const hostname = getDomain(context.session.config?.server?.domain);
|
|
20
21
|
const https = context.session.config?.server?.https;
|
|
21
|
-
const
|
|
22
|
+
const procedures = Object.fromEntries(Object.entries(apis).map(([name, api]) => [name, api.procedure]));
|
|
23
|
+
// AppRouter is the correct type, but doesn't get inferred correctly after Object.entries
|
|
24
|
+
const router = createRouter(procedures);
|
|
22
25
|
const { server, listen } = await createHTTPServer({
|
|
23
26
|
domain: hostname,
|
|
24
27
|
middleware: cors(),
|
|
@@ -34,15 +37,11 @@ export async function createCloudpackServer(options, context) {
|
|
|
34
37
|
router,
|
|
35
38
|
createContext,
|
|
36
39
|
});
|
|
37
|
-
const localCallContext = await createContext();
|
|
38
|
-
const apisWithContext = withContext(apis, localCallContext);
|
|
39
40
|
const webSocketProtocol = https ? 'wss' : 'ws';
|
|
40
41
|
const url = `${webSocketProtocol}://${hostname}:${port}`;
|
|
41
42
|
context.session.urls.apiServer = url;
|
|
42
43
|
return {
|
|
43
|
-
...apisWithContext,
|
|
44
44
|
url,
|
|
45
|
-
port,
|
|
46
45
|
close: async () => {
|
|
47
46
|
await new Promise((resolve, reject) => {
|
|
48
47
|
wss.clients.forEach((socket) => socket.terminate());
|
|
@@ -52,14 +51,4 @@ export async function createCloudpackServer(options, context) {
|
|
|
52
51
|
},
|
|
53
52
|
};
|
|
54
53
|
}
|
|
55
|
-
/** Helper to tie the local call context with the apis so callers don't have to cache them. */
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
function withContext(apis, ctx) {
|
|
58
|
-
return Object.entries(apis).reduce((acc, [key, apiFunction]) => {
|
|
59
|
-
acc[key] = (input) =>
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
61
|
-
apiFunction({ input, ctx });
|
|
62
|
-
return acc;
|
|
63
|
-
}, {});
|
|
64
|
-
}
|
|
65
54
|
//# sourceMappingURL=createCloudpackServer.js.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"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","sourcesContent":["import { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\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';\nimport * as apis from '../apis/index.js';\nimport { createRouter } from './common.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport interface CloudpackServer {\n url: string;\n close: () => Promise<void>;\n}\n\n/**\n * Creates a cloudpack server that can be used to communicate with the cloudpack client using trpc.\n */\nexport async function createCloudpackServer(\n options: {\n /** Custom port(s) to try for the API server. */\n port?: number | number[];\n },\n context: Context,\n): Promise<CloudpackServer> {\n const portArg = Array.isArray(options.port) ? options.port : options.port ? [options.port] : undefined;\n const port = await getPort({ port: portArg || [9890, 9891, 9892, 9893] });\n if (portArg && !portArg.includes(port)) {\n throw new Error(`No ports from range ${JSON.stringify(portArg)} are available`);\n }\n\n const createContext = await createContextFactory(context);\n const hostname = getDomain(context.session.config?.server?.domain);\n const https = context.session.config?.server?.https;\n\n const procedures = Object.fromEntries(Object.entries(apis).map(([name, api]) => [name, api.procedure]));\n // AppRouter is the correct type, but doesn't get inferred correctly after Object.entries\n const router = createRouter(procedures) as unknown as AppRouter;\n\n const { server, listen } = await createHTTPServer({\n domain: hostname,\n middleware: cors(),\n router,\n createContext,\n https,\n cwd: context.session.config.appPath,\n });\n\n await listen(port, hostname);\n\n const wss = new WebSocketServer({ server });\n\n applyWSSHandler<AppRouter>({\n wss,\n router,\n createContext,\n });\n\n const webSocketProtocol = https ? 'wss' : 'ws';\n const url = `${webSocketProtocol}://${hostname}:${port}`;\n context.session.urls.apiServer = url;\n\n return {\n url,\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"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as apis from '../apis/index.js';
|
|
2
|
+
import type { createRouter } from '../trpc/common.js';
|
|
3
|
+
export type AppRouter = ReturnType<typeof createRouter<{
|
|
4
|
+
[key in keyof typeof apis]: (typeof apis)[key]['procedure'];
|
|
5
|
+
}>>;
|
|
6
|
+
//# sourceMappingURL=AppRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRouter.d.ts","sourceRoot":"","sources":["../../src/types/AppRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG,UAAU,CAChC,OAAO,YAAY,CAAC;KACjB,GAAG,IAAI,MAAM,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;CAC5D,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRouter.js","sourceRoot":"","sources":["../../src/types/AppRouter.ts"],"names":[],"mappings":"","sourcesContent":["import type * as apis from '../apis/index.js';\nimport type { createRouter } from '../trpc/common.js';\n\nexport type AppRouter = ReturnType<\n typeof createRouter<{\n [key in keyof typeof apis]: (typeof apis)[key]['procedure'];\n }>\n>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncInput.d.ts","sourceRoot":"","sources":["../../src/types/SyncInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,iDAAiD;AACjD,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,WAAW,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncInput.js","sourceRoot":"","sources":["../../src/types/SyncInput.ts"],"names":[],"mappings":"","sourcesContent":["import type { LoginMethod } from '@ms-cloudpack/remote-cache';\n\n/** Input for `syncUpload` and `syncDownload`. */\nexport interface SyncInput {\n loginMethod: LoginMethod;\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.56.0",
|
|
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,23 +27,23 @@
|
|
|
27
27
|
"@lage-run/logger": "^1.3.0",
|
|
28
28
|
"@lage-run/scheduler": "^1.2.1",
|
|
29
29
|
"@lage-run/target-graph": "^0.9.0",
|
|
30
|
-
"@ms-cloudpack/bundler": "^0.23.
|
|
31
|
-
"@ms-cloudpack/common-types": "^0.23.
|
|
32
|
-
"@ms-cloudpack/config": "^0.31.
|
|
33
|
-
"@ms-cloudpack/create-express-app": "^1.10.
|
|
30
|
+
"@ms-cloudpack/bundler": "^0.23.10",
|
|
31
|
+
"@ms-cloudpack/common-types": "^0.23.2",
|
|
32
|
+
"@ms-cloudpack/config": "^0.31.7",
|
|
33
|
+
"@ms-cloudpack/create-express-app": "^1.10.3",
|
|
34
34
|
"@ms-cloudpack/data-bus": "^0.4.2",
|
|
35
35
|
"@ms-cloudpack/file-watcher": "^0.1.2",
|
|
36
|
-
"@ms-cloudpack/import-map": "^0.8.
|
|
36
|
+
"@ms-cloudpack/import-map": "^0.8.10",
|
|
37
37
|
"@ms-cloudpack/json-utilities": "^0.1.8",
|
|
38
|
-
"@ms-cloudpack/package-hashes": "^0.7.
|
|
39
|
-
"@ms-cloudpack/package-utilities": "^10.2.
|
|
38
|
+
"@ms-cloudpack/package-hashes": "^0.7.5",
|
|
39
|
+
"@ms-cloudpack/package-utilities": "^10.2.7",
|
|
40
40
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
41
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
42
|
-
"@ms-cloudpack/remote-cache": "^0.9.
|
|
41
|
+
"@ms-cloudpack/path-utilities": "^2.7.51",
|
|
42
|
+
"@ms-cloudpack/remote-cache": "^0.9.4",
|
|
43
43
|
"@ms-cloudpack/task-reporter": "^0.14.5",
|
|
44
|
-
"@ms-cloudpack/telemetry": "^0.
|
|
45
|
-
"@trpc/client": "
|
|
46
|
-
"@trpc/server": "
|
|
44
|
+
"@ms-cloudpack/telemetry": "^0.8.1",
|
|
45
|
+
"@trpc/client": "11.0.0-rc.593",
|
|
46
|
+
"@trpc/server": "11.0.0-rc.593",
|
|
47
47
|
"cors": "^2.8.5",
|
|
48
48
|
"es-module-lexer": "^1.4.1",
|
|
49
49
|
"filenamify": "^6.0.0",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ApiParams } from '../types/ApiParams.js';
|
|
3
|
-
declare const ZodReportMetricInput: z.ZodObject<{
|
|
4
|
-
metric: z.ZodString;
|
|
5
|
-
value: z.ZodNumber;
|
|
6
|
-
additionalProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
7
|
-
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
value: number;
|
|
9
|
-
metric: string;
|
|
10
|
-
additionalProperties?: Record<string, string | number | boolean> | undefined;
|
|
11
|
-
}, {
|
|
12
|
-
value: number;
|
|
13
|
-
metric: string;
|
|
14
|
-
additionalProperties?: Record<string, string | number | boolean> | undefined;
|
|
15
|
-
}>;
|
|
16
|
-
export type ReportMetricInput = z.infer<typeof ZodReportMetricInput>;
|
|
17
|
-
export declare function reportMetric(params: ApiParams<ReportMetricInput, 'telemetryClient' | 'session'>): void;
|
|
18
|
-
export declare namespace reportMetric {
|
|
19
|
-
var procedure: import("@trpc/server").BuildProcedure<"mutation", {
|
|
20
|
-
_config: import("@trpc/server").RootConfig<{
|
|
21
|
-
ctx: import("../index.js").Context;
|
|
22
|
-
meta: object;
|
|
23
|
-
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
24
|
-
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
25
|
-
}>;
|
|
26
|
-
_meta: object;
|
|
27
|
-
_ctx_out: import("../index.js").Context;
|
|
28
|
-
_input_in: {
|
|
29
|
-
value: number;
|
|
30
|
-
metric: string;
|
|
31
|
-
additionalProperties?: Record<string, string | number | boolean> | undefined;
|
|
32
|
-
};
|
|
33
|
-
_input_out: {
|
|
34
|
-
value: number;
|
|
35
|
-
metric: string;
|
|
36
|
-
additionalProperties?: Record<string, string | number | boolean> | undefined;
|
|
37
|
-
};
|
|
38
|
-
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
39
|
-
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
40
|
-
}, void>;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
43
|
-
//# sourceMappingURL=reportMetric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reportMetric.d.ts","sourceRoot":"","sources":["../../src/apis/reportMetric.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,QAAA,MAAM,oBAAoB;;;;;;;;;;;;EAIxB,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAErE,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,CAAC,GAAG,IAAI,CAatG;yBAbe,YAAY"}
|
package/lib/apis/reportMetric.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { publicProcedure } from '../trpc/common.js';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
const ZodReportMetricInput = z.object({
|
|
4
|
-
metric: z.string(),
|
|
5
|
-
value: z.number(),
|
|
6
|
-
additionalProperties: z.optional(z.record(z.union([z.string(), z.number(), z.boolean()]))),
|
|
7
|
-
});
|
|
8
|
-
export function reportMetric(params) {
|
|
9
|
-
const { input, ctx } = params;
|
|
10
|
-
const { metric, value, additionalProperties } = input;
|
|
11
|
-
const { telemetryClient, session } = ctx;
|
|
12
|
-
telemetryClient.performance.record({
|
|
13
|
-
name: metric,
|
|
14
|
-
value,
|
|
15
|
-
additionalProperties: {
|
|
16
|
-
...additionalProperties,
|
|
17
|
-
sequence: session.sequence,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
// Attach a trpc procedure to the function.
|
|
22
|
-
reportMetric.procedure = publicProcedure.input(ZodReportMetricInput).mutation(reportMetric);
|
|
23
|
-
//# sourceMappingURL=reportMetric.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reportMetric.js","sourceRoot":"","sources":["../../src/apis/reportMetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,oBAAoB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;CAC3F,CAAC,CAAC;AAIH,MAAM,UAAU,YAAY,CAAC,MAAmE;IAC9F,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAEzC,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC;QACjC,IAAI,EAAE,MAAM;QACZ,KAAK;QACL,oBAAoB,EAAE;YACpB,GAAG,oBAAoB;YACvB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B;KACF,CAAC,CAAC;AACL,CAAC;AAED,2CAA2C;AAC3C,YAAY,CAAC,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC","sourcesContent":["import { publicProcedure } from '../trpc/common.js';\nimport { z } from 'zod';\nimport type { ApiParams } from '../types/ApiParams.js';\n\nconst ZodReportMetricInput = z.object({\n metric: z.string(),\n value: z.number(),\n additionalProperties: z.optional(z.record(z.union([z.string(), z.number(), z.boolean()]))),\n});\n\nexport type ReportMetricInput = z.infer<typeof ZodReportMetricInput>;\n\nexport function reportMetric(params: ApiParams<ReportMetricInput, 'telemetryClient' | 'session'>): void {\n const { input, ctx } = params;\n const { metric, value, additionalProperties } = input;\n const { telemetryClient, session } = ctx;\n\n telemetryClient.performance.record({\n name: metric,\n value,\n additionalProperties: {\n ...additionalProperties,\n sequence: session.sequence,\n },\n });\n}\n\n// Attach a trpc procedure to the function.\nreportMetric.procedure = publicProcedure.input(ZodReportMetricInput).mutation(reportMetric);\n"]}
|