@ms-cloudpack/api-server 0.54.9 → 0.55.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 +0 -3
- package/lib/apis/index.d.ts.map +1 -1
- package/lib/apis/index.js +1 -3
- 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/reportMetric.d.ts +4 -18
- 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/lib/utilities/getImportsAndExports.d.ts.map +1 -1
- package/lib/utilities/getImportsAndExports.js +5 -4
- package/lib/utilities/getImportsAndExports.js.map +1 -1
- package/package.json +5 -5
- 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,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":"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,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;AAE7D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAGC,EACD,OAAgB;IAEhB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,C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AAI,EAAE,QAAQ,CAAC,CAAC;IAE7B,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,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,MAAM,GAAG,GAAG,GAAG,iBAAiB,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;IACzD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAErC,OAAO;QACL,GAAG;QACH,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC1C,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;gBACpD,GAAG,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;gBACpD,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsAndExports.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CACN;IACE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC,GACD,SAAS,CACZ,
|
|
1
|
+
{"version":3,"file":"getImportsAndExports.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CACN;IACE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC,GACD,SAAS,CACZ,CAuIA"}
|
|
@@ -34,7 +34,7 @@ export async function getImportsAndExports(filePath, packagePath) {
|
|
|
34
34
|
// es-module-lexer doesn't handle export * from statements correctly as it parses them as
|
|
35
35
|
// imports but not as exports. We need to handle them separately.
|
|
36
36
|
// TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed
|
|
37
|
-
|
|
37
|
+
const exportStarImport = [];
|
|
38
38
|
const imports = [];
|
|
39
39
|
const dynamicImports = [];
|
|
40
40
|
for (const imprt of new Set(rawImports)) {
|
|
@@ -101,7 +101,7 @@ export async function getImportsAndExports(filePath, packagePath) {
|
|
|
101
101
|
}
|
|
102
102
|
// Handling export * from import statements
|
|
103
103
|
if (importCode.includes('export * from')) {
|
|
104
|
-
exportStarImport
|
|
104
|
+
exportStarImport.push(importPath);
|
|
105
105
|
}
|
|
106
106
|
// Parse the import string into its component parts.
|
|
107
107
|
const importedNames = parseNamedImports(importCode);
|
|
@@ -127,8 +127,9 @@ export async function getImportsAndExports(filePath, packagePath) {
|
|
|
127
127
|
console.debug(`Found an export that didn't parse correctly:\nFilename: ${filePath}\nExport:\n ${source.slice(exprt.s, exprt.e)}`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
for (const exportPath of exportStarImport) {
|
|
131
|
+
// This follows the following convention: https://github.com/guybedford/es-module-lexer/issues/76#issuecomment-868561807
|
|
132
|
+
exportNames.add(`*${exportPath}`);
|
|
132
133
|
}
|
|
133
134
|
return { exportNames, imports, dynamicImports };
|
|
134
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsAndExports.js","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,KAAK,EAA8C,MAAM,iBAAiB,CAAC;AACpF,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAqB,MAAM,YAAY,CAAC;AAClE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAgB,EAChB,WAAoB;IASpB,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oDAAoD;QACpD,OAAO,CAAC,IAAI,CAAC,kBAAkB,QAAQ,GAAG,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IAED,IAAI,UAAsC,CAAC;IAC3C,IAAI,UAAsC,CAAC;IAC3C,IAAI,CAAC;QACH,8DAA8D;QAC9D,2DAA2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,gBAAgB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CACpH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc,EAAE,QAAgB;IACxD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,EAAE,CAAC;YACP,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import { parseImportString, parseNamedImports } from '@ms-cloudpack/path-string-parsing';\nimport { parse, type ImportSpecifier, type ExportSpecifier } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport { SourceMapConsumer, type RawSourceMap } from 'source-map';\nimport path from 'path';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport type { ConsumedImport, DynamicImport } from '../types/BundleInfo.js';\n\n/**\n * Get info about imports and exports from a file.\n * Returns undefined if the file doesn't exist or can't be parsed.\n */\nexport async function getImportsAndExports(\n filePath: string,\n packagePath?: string,\n): Promise<\n | {\n exportNames: Set<string>;\n imports: ConsumedImport[];\n dynamicImports: DynamicImport[];\n }\n | undefined\n> {\n let source: string;\n try {\n source = await fsPromises.readFile(filePath, 'utf-8');\n } catch (err) {\n // This could happen if a package is missing a file.\n console.warn(`Failed to read ${filePath}:`, err);\n return;\n }\n\n let rawImports: readonly ImportSpecifier[];\n let rawExports: readonly ExportSpecifier[];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // https://github.com/guybedford/es-module-lexer/issues/155\n // eslint-disable-next-line @typescript-eslint/await-thenable\n [rawImports, rawExports] = await parse(source);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n console.warn(`Failed to parse ${filePath}: ${err}\\nSource is:\\n${source}`);\n return;\n }\n\n // es-module-lexer doesn't handle export * from statements correctly as it parses them as\n // imports but not as exports. We need to handle them separately.\n // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed\n let exportStarImport = false;\n\n const imports: ConsumedImport[] = [];\n const dynamicImports: DynamicImport[] = [];\n for (const imprt of new Set(rawImports)) {\n // es-module-lexer returns entries where the \"n\" property equals the import source.\n // This includes the package name and path. For example, in this case:\n // import { Button } from '@fluentui/react/lib/Button';\n // imprt.n is \"@fluentui/react/lib/Button\"\n let importPath = imprt.n;\n // ss and se point to the entire import string's start/end\n const importCode = source.slice(imprt.ss, imprt.se);\n // s and e point to the specificer's start/end, including quotes -- e.g. \"@fluentui/react/lib/Button\"\n const importSpecifier = source.slice(imprt.s, imprt.e);\n\n if (!importPath) {\n if (imprt.d === -2) {\n continue; // -2 means import.meta, which we don't care about\n }\n\n // Currently when the import source is a backtick string, the path (\"n\" property) is undefined.\n // This is a limitation in es-module-lexer.\n if (/^`[^$`]+`$/.test(importSpecifier)) {\n // If it's a static string which happened to use backticks for some reason, we can parse that.\n importPath = importSpecifier.slice(1, -1);\n } else if (packagePath) {\n // Find the original source of the import.\n let rawSourceMap: RawSourceMap;\n let originalSource: string | null = null;\n try {\n rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8')) as RawSourceMap;\n const consumer = await new SourceMapConsumer(rawSourceMap);\n const pos = getLineAndColumn(source, imprt.s);\n const originalPos = consumer.originalPositionFor(pos);\n originalSource = originalPos.source;\n consumer.destroy(); // Clean up the consumer\n if (originalSource === null) {\n console.debug(`Failed to find original source for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`);\n }\n } catch (err) {\n console.debug(`Failed to read sourcemap for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`, err);\n }\n\n // Original source where the import was found.\n const absoluteImportSpecifier = originalSource\n ? path.resolve(path.dirname(filePath), originalSource)\n : filePath;\n\n let packageName = '.'; // Default to local package\n // Remove leading quote from the import specifier if it exists.\n const lazyCleanImportSpecifier = importSpecifier.replace(/^[\"'`]/, '');\n if (!lazyCleanImportSpecifier.startsWith('.')) {\n packageName = parseImportString(lazyCleanImportSpecifier).packageName;\n }\n dynamicImports.push({\n packageName,\n // Relative path from package path to file with import. Prefer original source if available.\n // or use the file path if original source is not available.\n importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),\n importSpecifier,\n });\n continue;\n } else {\n console.debug(\n `Found an import that didn't have a static path:\\nFilename:${filePath}\\nImport:\\n ${importCode}`,\n );\n continue;\n }\n }\n\n // Handling export * from import statements\n if (importCode.includes('export * from')) {\n exportStarImport = true;\n }\n\n // Parse the import string into its component parts.\n const importedNames = parseNamedImports(importCode);\n if (imprt.d >= 0 && !importedNames.length) {\n // This is a dynamic import. In this case we don't know which names are used, so assume all of them.\n importedNames.push('*');\n }\n\n imports.push({\n ...parseImportString(importPath),\n names: Array.from(new Set<string>(importedNames)),\n });\n }\n\n // Processing exports is cheap as we already have to parse the source.\n // Helps find exports uncaught by output files.\n const exportNames = new Set<string>();\n for (const exprt of rawExports) {\n if (exprt.n) {\n // Exports don't need to be parsed as it is\n // already in the format we need.\n exportNames.add(exprt.n);\n } else {\n console.debug(\n `Found an export that didn't parse correctly:\\nFilename: ${filePath}\\nExport:\\n ${source.slice(exprt.s, exprt.e)}`,\n );\n }\n }\n\n if (exportStarImport) {\n exportNames.add('*');\n }\n\n return { exportNames, imports, dynamicImports };\n}\n\nfunction getLineAndColumn(source: string, position: number): { line: number; column: number } {\n let line = 1;\n let column = 1;\n\n for (let i = 0; i < position; i++) {\n if (source[i] === '\\n') {\n line++;\n column = 1;\n } else {\n column++;\n }\n }\n\n return { line, column };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getImportsAndExports.js","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,KAAK,EAA8C,MAAM,iBAAiB,CAAC;AACpF,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAqB,MAAM,YAAY,CAAC;AAClE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAgB,EAChB,WAAoB;IASpB,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oDAAoD;QACpD,OAAO,CAAC,IAAI,CAAC,kBAAkB,QAAQ,GAAG,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IAED,IAAI,UAAsC,CAAC;IAC3C,IAAI,UAAsC,CAAC;IAC3C,IAAI,CAAC;QACH,8DAA8D;QAC9D,2DAA2D;QAC3D,6DAA6D;QAC7D,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,sDAAsD;QACtD,OAAO,CAAC,IAAI,CAAC,mBAAmB,QAAQ,KAAK,GAAG,iBAAiB,MAAM,EAAE,CAAC,CAAC;QAC3E,OAAO;IACT,CA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;IACpC,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc,EAAE,QAAgB;IACxD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,EAAE,CAAC;YACP,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import { parseImportString, parseNamedImports } from '@ms-cloudpack/path-string-parsing';\nimport { parse, type ImportSpecifier, type ExportSpecifier } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport { SourceMapConsumer, type RawSourceMap } from 'source-map';\nimport path from 'path';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport type { ConsumedImport, DynamicImport } from '../types/BundleInfo.js';\n\n/**\n * Get info about imports and exports from a file.\n * Returns undefined if the file doesn't exist or can't be parsed.\n */\nexport async function getImportsAndExports(\n filePath: string,\n packagePath?: string,\n): Promise<\n | {\n exportNames: Set<string>;\n imports: ConsumedImport[];\n dynamicImports: DynamicImport[];\n }\n | undefined\n> {\n let source: string;\n try {\n source = await fsPromises.readFile(filePath, 'utf-8');\n } catch (err) {\n // This could happen if a package is missing a file.\n console.warn(`Failed to read ${filePath}:`, err);\n return;\n }\n\n let rawImports: readonly ImportSpecifier[];\n let rawExports: readonly ExportSpecifier[];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // https://github.com/guybedford/es-module-lexer/issues/155\n // eslint-disable-next-line @typescript-eslint/await-thenable\n [rawImports, rawExports] = await parse(source);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n console.warn(`Failed to parse ${filePath}: ${err}\\nSource is:\\n${source}`);\n return;\n }\n\n // es-module-lexer doesn't handle export * from statements correctly as it parses them as\n // imports but not as exports. We need to handle them separately.\n // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed\n const exportStarImport = [];\n\n const imports: ConsumedImport[] = [];\n const dynamicImports: DynamicImport[] = [];\n for (const imprt of new Set(rawImports)) {\n // es-module-lexer returns entries where the \"n\" property equals the import source.\n // This includes the package name and path. For example, in this case:\n // import { Button } from '@fluentui/react/lib/Button';\n // imprt.n is \"@fluentui/react/lib/Button\"\n let importPath = imprt.n;\n // ss and se point to the entire import string's start/end\n const importCode = source.slice(imprt.ss, imprt.se);\n // s and e point to the specificer's start/end, including quotes -- e.g. \"@fluentui/react/lib/Button\"\n const importSpecifier = source.slice(imprt.s, imprt.e);\n\n if (!importPath) {\n if (imprt.d === -2) {\n continue; // -2 means import.meta, which we don't care about\n }\n\n // Currently when the import source is a backtick string, the path (\"n\" property) is undefined.\n // This is a limitation in es-module-lexer.\n if (/^`[^$`]+`$/.test(importSpecifier)) {\n // If it's a static string which happened to use backticks for some reason, we can parse that.\n importPath = importSpecifier.slice(1, -1);\n } else if (packagePath) {\n // Find the original source of the import.\n let rawSourceMap: RawSourceMap;\n let originalSource: string | null = null;\n try {\n rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8')) as RawSourceMap;\n const consumer = await new SourceMapConsumer(rawSourceMap);\n const pos = getLineAndColumn(source, imprt.s);\n const originalPos = consumer.originalPositionFor(pos);\n originalSource = originalPos.source;\n consumer.destroy(); // Clean up the consumer\n if (originalSource === null) {\n console.debug(`Failed to find original source for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`);\n }\n } catch (err) {\n console.debug(`Failed to read sourcemap for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`, err);\n }\n\n // Original source where the import was found.\n const absoluteImportSpecifier = originalSource\n ? path.resolve(path.dirname(filePath), originalSource)\n : filePath;\n\n let packageName = '.'; // Default to local package\n // Remove leading quote from the import specifier if it exists.\n const lazyCleanImportSpecifier = importSpecifier.replace(/^[\"'`]/, '');\n if (!lazyCleanImportSpecifier.startsWith('.')) {\n packageName = parseImportString(lazyCleanImportSpecifier).packageName;\n }\n dynamicImports.push({\n packageName,\n // Relative path from package path to file with import. Prefer original source if available.\n // or use the file path if original source is not available.\n importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),\n importSpecifier,\n });\n continue;\n } else {\n console.debug(\n `Found an import that didn't have a static path:\\nFilename:${filePath}\\nImport:\\n ${importCode}`,\n );\n continue;\n }\n }\n\n // Handling export * from import statements\n if (importCode.includes('export * from')) {\n exportStarImport.push(importPath);\n }\n\n // Parse the import string into its component parts.\n const importedNames = parseNamedImports(importCode);\n if (imprt.d >= 0 && !importedNames.length) {\n // This is a dynamic import. In this case we don't know which names are used, so assume all of them.\n importedNames.push('*');\n }\n\n imports.push({\n ...parseImportString(importPath),\n names: Array.from(new Set<string>(importedNames)),\n });\n }\n\n // Processing exports is cheap as we already have to parse the source.\n // Helps find exports uncaught by output files.\n const exportNames = new Set<string>();\n for (const exprt of rawExports) {\n if (exprt.n) {\n // Exports don't need to be parsed as it is\n // already in the format we need.\n exportNames.add(exprt.n);\n } else {\n console.debug(\n `Found an export that didn't parse correctly:\\nFilename: ${filePath}\\nExport:\\n ${source.slice(exprt.s, exprt.e)}`,\n );\n }\n }\n\n for (const exportPath of exportStarImport) {\n // This follows the following convention: https://github.com/guybedford/es-module-lexer/issues/76#issuecomment-868561807\n exportNames.add(`*${exportPath}`);\n }\n\n return { exportNames, imports, dynamicImports };\n}\n\nfunction getLineAndColumn(source: string, position: number): { line: number; column: number } {\n let line = 1;\n let column = 1;\n\n for (let i = 0; i < position; i++) {\n if (source[i] === '\\n') {\n line++;\n column = 1;\n } else {\n column++;\n }\n }\n\n return { line, column };\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.55.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",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@ms-cloudpack/package-utilities": "^10.2.6",
|
|
40
40
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
41
41
|
"@ms-cloudpack/path-utilities": "^2.7.50",
|
|
42
|
-
"@ms-cloudpack/remote-cache": "^0.9.
|
|
42
|
+
"@ms-cloudpack/remote-cache": "^0.9.3",
|
|
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.0",
|
|
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",
|