@ms-cloudpack/api-server 0.7.2 → 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.
Files changed (168) hide show
  1. package/lib/apis/addPackageOverride.d.ts +85 -34
  2. package/lib/apis/addPackageOverride.d.ts.map +1 -1
  3. package/lib/apis/addPackageOverride.js +21 -10
  4. package/lib/apis/addPackageOverride.js.map +1 -1
  5. package/lib/apis/getData.d.ts +66 -0
  6. package/lib/apis/getData.d.ts.map +1 -0
  7. package/lib/apis/getData.js +11 -0
  8. package/lib/apis/getData.js.map +1 -0
  9. package/lib/apis/getSessionId.d.ts +54 -0
  10. package/lib/apis/getSessionId.d.ts.map +1 -0
  11. package/lib/apis/getSessionId.js +8 -0
  12. package/lib/apis/getSessionId.js.map +1 -0
  13. package/lib/apis/index.d.ts +10 -0
  14. package/lib/apis/index.d.ts.map +1 -0
  15. package/lib/apis/index.js +10 -0
  16. package/lib/apis/index.js.map +1 -0
  17. package/lib/apis/onDataChanged.d.ts +69 -0
  18. package/lib/apis/onDataChanged.d.ts.map +1 -0
  19. package/lib/apis/onDataChanged.js +20 -0
  20. package/lib/apis/onDataChanged.js.map +1 -0
  21. package/lib/apis/openCodeEditor.d.ts +69 -34
  22. package/lib/apis/openCodeEditor.d.ts.map +1 -1
  23. package/lib/apis/openCodeEditor.js +9 -8
  24. package/lib/apis/openCodeEditor.js.map +1 -1
  25. package/lib/apis/openConfigEditor.d.ts +39 -24
  26. package/lib/apis/openConfigEditor.d.ts.map +1 -1
  27. package/lib/apis/openConfigEditor.js +6 -2
  28. package/lib/apis/openConfigEditor.js.map +1 -1
  29. package/lib/apis/openFilePath.d.ts +50 -30
  30. package/lib/apis/openFilePath.d.ts.map +1 -1
  31. package/lib/apis/openFilePath.js +9 -8
  32. package/lib/apis/openFilePath.js.map +1 -1
  33. package/lib/apis/reportMetric.d.ts +55 -31
  34. package/lib/apis/reportMetric.d.ts.map +1 -1
  35. package/lib/apis/reportMetric.js +7 -6
  36. package/lib/apis/reportMetric.js.map +1 -1
  37. package/lib/apis/validatePackageOverride.d.ts +73 -36
  38. package/lib/apis/validatePackageOverride.d.ts.map +1 -1
  39. package/lib/apis/validatePackageOverride.js +11 -8
  40. package/lib/apis/validatePackageOverride.js.map +1 -1
  41. package/lib/index.d.ts +7 -3
  42. package/lib/index.d.ts.map +1 -1
  43. package/lib/index.js +6 -2
  44. package/lib/index.js.map +1 -1
  45. package/lib/{trpc.d.ts → trpc/common.d.ts} +29 -11
  46. package/lib/trpc/common.d.ts.map +1 -0
  47. package/lib/{trpc.js → trpc/common.js} +2 -2
  48. package/lib/trpc/common.js.map +1 -0
  49. package/lib/trpc/connectBusToClient.d.ts +8 -0
  50. package/lib/trpc/connectBusToClient.d.ts.map +1 -0
  51. package/lib/trpc/connectBusToClient.js +28 -0
  52. package/lib/trpc/connectBusToClient.js.map +1 -0
  53. package/lib/trpc/createAppRouter.d.ts +453 -0
  54. package/lib/trpc/createAppRouter.d.ts.map +1 -0
  55. package/lib/trpc/createAppRouter.js +9 -0
  56. package/lib/trpc/createAppRouter.js.map +1 -0
  57. package/lib/trpc/createCloudpackClient.d.ts +13 -0
  58. package/lib/trpc/createCloudpackClient.d.ts.map +1 -0
  59. package/lib/trpc/createCloudpackClient.js +53 -0
  60. package/lib/trpc/createCloudpackClient.js.map +1 -0
  61. package/lib/trpc/createCloudpackServer.d.ts +63 -0
  62. package/lib/trpc/createCloudpackServer.d.ts.map +1 -0
  63. package/lib/trpc/createCloudpackServer.js +52 -0
  64. package/lib/trpc/createCloudpackServer.js.map +1 -0
  65. package/lib/{createContextFactory.d.ts → trpc/createContextFactory.d.ts} +10 -5
  66. package/lib/trpc/createContextFactory.d.ts.map +1 -0
  67. package/lib/{createContextFactory.js → trpc/createContextFactory.js} +8 -15
  68. package/lib/trpc/createContextFactory.js.map +1 -0
  69. package/lib/trpc/createRouterFromApis.d.ts +26 -0
  70. package/lib/trpc/createRouterFromApis.d.ts.map +1 -0
  71. package/lib/trpc/createRouterFromApis.js +9 -0
  72. package/lib/trpc/createRouterFromApis.js.map +1 -0
  73. package/lib/{trpc-adapters → trpc}/httpAdapter.d.ts +10 -5
  74. package/lib/trpc/httpAdapter.d.ts.map +1 -0
  75. package/lib/trpc/httpAdapter.js +59 -0
  76. package/lib/trpc/httpAdapter.js.map +1 -0
  77. package/lib/types/BundleResultExtended.d.ts +23 -0
  78. package/lib/types/BundleResultExtended.d.ts.map +1 -0
  79. package/lib/types/BundleResultExtended.js +2 -0
  80. package/lib/types/BundleResultExtended.js.map +1 -0
  81. package/lib/types/TaskDescription.d.ts +133 -7
  82. package/lib/types/TaskDescription.d.ts.map +1 -1
  83. package/lib/types/TaskDescription.js +14 -1
  84. package/lib/types/TaskDescription.js.map +1 -1
  85. package/lib/types/TaskEndDescription.d.ts +84 -5
  86. package/lib/types/TaskEndDescription.d.ts.map +1 -1
  87. package/lib/types/TaskEndDescription.js +7 -1
  88. package/lib/types/TaskEndDescription.js.map +1 -1
  89. package/lib/types/TaskError.d.ts +18 -2
  90. package/lib/types/TaskError.d.ts.map +1 -1
  91. package/lib/types/TaskError.js +9 -1
  92. package/lib/types/TaskError.js.map +1 -1
  93. package/lib/types/TaskMessage.d.ts +166 -0
  94. package/lib/types/TaskMessage.d.ts.map +1 -0
  95. package/lib/types/TaskMessage.js +17 -0
  96. package/lib/types/TaskMessage.js.map +1 -0
  97. package/lib/types/TaskMessageLocation.d.ts +25 -0
  98. package/lib/types/TaskMessageLocation.d.ts.map +1 -0
  99. package/lib/types/TaskMessageLocation.js +10 -0
  100. package/lib/types/TaskMessageLocation.js.map +1 -0
  101. package/lib/types/TaskResponse.d.ts +471 -0
  102. package/lib/types/TaskResponse.d.ts.map +1 -0
  103. package/lib/types/TaskResponse.js +8 -0
  104. package/lib/types/TaskResponse.js.map +1 -0
  105. package/lib/types/TaskResult.d.ts +339 -0
  106. package/lib/types/TaskResult.d.ts.map +1 -0
  107. package/lib/types/TaskResult.js +7 -0
  108. package/lib/types/TaskResult.js.map +1 -0
  109. package/lib/types/TaskStartDescription.d.ts +17 -5
  110. package/lib/types/TaskStartDescription.d.ts.map +1 -1
  111. package/lib/types/TaskStartDescription.js +7 -1
  112. package/lib/types/TaskStartDescription.js.map +1 -1
  113. package/lib/types/TaskStats.d.ts +22 -0
  114. package/lib/types/TaskStats.d.ts.map +1 -0
  115. package/lib/types/TaskStats.js +9 -0
  116. package/lib/types/TaskStats.js.map +1 -0
  117. package/lib/types/Timing.d.ts +23 -0
  118. package/lib/types/Timing.d.ts.map +1 -0
  119. package/lib/types/Timing.js +12 -0
  120. package/lib/types/Timing.js.map +1 -0
  121. package/lib/types/Timings.d.ts +20 -0
  122. package/lib/types/Timings.d.ts.map +1 -0
  123. package/lib/types/Timings.js +5 -0
  124. package/lib/types/Timings.js.map +1 -0
  125. package/lib/utilities/ignoreSelfSignedCertErrors.d.ts +5 -0
  126. package/lib/utilities/ignoreSelfSignedCertErrors.d.ts.map +1 -0
  127. package/lib/utilities/ignoreSelfSignedCertErrors.js +15 -0
  128. package/lib/utilities/ignoreSelfSignedCertErrors.js.map +1 -0
  129. package/package.json +1 -1
  130. package/lib/apis/bus.d.ts +0 -41
  131. package/lib/apis/bus.d.ts.map +0 -1
  132. package/lib/apis/bus.js +0 -23
  133. package/lib/apis/bus.js.map +0 -1
  134. package/lib/apis/restartAllTasks.d.ts +0 -31
  135. package/lib/apis/restartAllTasks.d.ts.map +0 -1
  136. package/lib/apis/restartAllTasks.js +0 -18
  137. package/lib/apis/restartAllTasks.js.map +0 -1
  138. package/lib/apis/restartTask.d.ts +0 -37
  139. package/lib/apis/restartTask.d.ts.map +0 -1
  140. package/lib/apis/restartTask.js +0 -14
  141. package/lib/apis/restartTask.js.map +0 -1
  142. package/lib/appRouter.d.ts +0 -335
  143. package/lib/appRouter.d.ts.map +0 -1
  144. package/lib/appRouter.js +0 -22
  145. package/lib/appRouter.js.map +0 -1
  146. package/lib/createCloudpackClient.d.ts +0 -17
  147. package/lib/createCloudpackClient.d.ts.map +0 -1
  148. package/lib/createCloudpackClient.js +0 -57
  149. package/lib/createCloudpackClient.js.map +0 -1
  150. package/lib/createCloudpackServer.d.ts +0 -49
  151. package/lib/createCloudpackServer.d.ts.map +0 -1
  152. package/lib/createCloudpackServer.js +0 -26
  153. package/lib/createCloudpackServer.js.map +0 -1
  154. package/lib/createCloudpackWebClient.d.ts +0 -2
  155. package/lib/createCloudpackWebClient.d.ts.map +0 -1
  156. package/lib/createCloudpackWebClient.js +0 -9
  157. package/lib/createCloudpackWebClient.js.map +0 -1
  158. package/lib/createContextFactory.d.ts.map +0 -1
  159. package/lib/createContextFactory.js.map +0 -1
  160. package/lib/trpc-adapters/httpAdapter.d.ts.map +0 -1
  161. package/lib/trpc-adapters/httpAdapter.js +0 -37
  162. package/lib/trpc-adapters/httpAdapter.js.map +0 -1
  163. package/lib/trpc-adapters/httpsAdapter.d.ts +0 -1
  164. package/lib/trpc-adapters/httpsAdapter.d.ts.map +0 -1
  165. package/lib/trpc-adapters/httpsAdapter.js +0 -2
  166. package/lib/trpc-adapters/httpsAdapter.js.map +0 -1
  167. package/lib/trpc.d.ts.map +0 -1
  168. package/lib/trpc.js.map +0 -1
@@ -0,0 +1,53 @@
1
+ import { createDataBus } from '@ms-cloudpack/data-bus';
2
+ import { createTRPCProxyClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';
3
+ import { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';
4
+ import { connectBusToClient } from './connectBusToClient.js';
5
+ import { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';
6
+ export async function createCloudpackClient(options) {
7
+ // We polyfill websocket in node conditions.
8
+ await ensureWebsocketDefined();
9
+ ignoreSelfSignedCertErrors({ reporter: options.reporter });
10
+ //
11
+ // Create the client.
12
+ const wsClient = createWSClient(options);
13
+ const tempUrl = new URL(options.url);
14
+ // Replace the protocol with http so that we can use the same url for http requests.
15
+ const isSSL = tempUrl.protocol === 'wss:';
16
+ tempUrl.protocol = isSSL ? 'https:' : 'http:';
17
+ const url = tempUrl.toString().replace(/\/$/, '');
18
+ const client = createTRPCProxyClient({
19
+ links: [
20
+ splitLink({
21
+ condition(op) {
22
+ return op.type === 'subscription';
23
+ },
24
+ true: wsLink({
25
+ client: wsClient,
26
+ }),
27
+ false: httpBatchLink({
28
+ url,
29
+ }),
30
+ }),
31
+ ],
32
+ });
33
+ // Connect the bus to the client so that local requests are sent remotely.
34
+ const bus = createDataBus();
35
+ connectBusToClient({ bus, client });
36
+ // Ugh. This is a hack to get around the fact that the client is a proxy.
37
+ return new Proxy({
38
+ bus,
39
+ close: () => {
40
+ wsClient.close();
41
+ bus.dispose();
42
+ },
43
+ }, {
44
+ get(target, prop) {
45
+ // eslint-disable-next-line no-prototype-builtins
46
+ if (target.hasOwnProperty(prop)) {
47
+ return target[prop];
48
+ }
49
+ return client[prop];
50
+ },
51
+ });
52
+ }
53
+ //# sourceMappingURL=createCloudpackClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAQxF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAG3C;IACC,4CAA4C;IAC5C,MAAM,sBAAsB,EAAE,CAAC;IAE/B,0BAA0B,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE3D,EAAE;IACF,qBAA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F,CACiB,CAAC;AACvB,CAAC","sourcesContent":["import type { DataBus } from '@ms-cloudpack/data-bus';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport type { CreateTRPCProxyClient } from '@trpc/client';\nimport { createTRPCProxyClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';\nimport { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';\nimport type { AppRouter } from './createAppRouter.js';\nimport { connectBusToClient } from './connectBusToClient.js';\nimport { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\n\nexport type CloudpackClient = CreateTRPCProxyClient<AppRouter> & {\n bus: DataBus;\n close: () => Promise<void>;\n};\n\nexport async function createCloudpackClient(options: {\n url: string;\n reporter?: TaskReporter;\n}): Promise<CloudpackClient> {\n // We polyfill websocket in node conditions.\n await ensureWebsocketDefined();\n\n ignoreSelfSignedCertErrors({ reporter: options.reporter });\n\n //\n // Create the client.\n const wsClient = createWSClient(options);\n const tempUrl = new URL(options.url);\n\n // Replace the protocol with http so that we can use the same url for http requests.\n const isSSL = tempUrl.protocol === 'wss:';\n tempUrl.protocol = isSSL ? 'https:' : 'http:';\n\n const url = tempUrl.toString().replace(/\\/$/, '');\n const client = createTRPCProxyClient<AppRouter>({\n links: [\n splitLink({\n condition(op) {\n return op.type === 'subscription';\n },\n true: wsLink({\n client: wsClient,\n }),\n false: httpBatchLink({\n url,\n }),\n }),\n ],\n }) as unknown as CloudpackClient;\n\n // Connect the bus to the client so that local requests are sent remotely.\n const bus = createDataBus();\n\n connectBusToClient({ bus, client });\n\n // Ugh. This is a hack to get around the fact that the client is a proxy.\n return new Proxy(\n {\n bus,\n close: () => {\n wsClient.close();\n bus.dispose();\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"]}
@@ -0,0 +1,63 @@
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
+ export declare function createCloudpackServer(options: {
6
+ session: Session;
7
+ rootSpan: Span | undefined;
8
+ reporter: TaskReporter;
9
+ packages: PackageDefinitionsCache;
10
+ }): Promise<{
11
+ url: string;
12
+ port: number;
13
+ ctx: {
14
+ session: Session;
15
+ bus: import("@ms-cloudpack/data-bus").DataBus;
16
+ rootSpan: Span | undefined;
17
+ reporter: TaskReporter;
18
+ watcher: {
19
+ watch({ path, watchPaths, }: {
20
+ path: string;
21
+ watchPaths?: string[] | undefined;
22
+ }, onPackageChanged: () => void): () => Promise<void>;
23
+ unwatchAll(): Promise<void>;
24
+ };
25
+ packages: PackageDefinitionsCache;
26
+ dispose(): Promise<void>;
27
+ };
28
+ close: () => Promise<void>;
29
+ addPackageOverride: (options: {
30
+ packageName: string;
31
+ importPath: string;
32
+ filename?: string | undefined;
33
+ }) => Promise<void>;
34
+ getData: (options: {
35
+ path: string[];
36
+ }) => any;
37
+ getSessionId: (options: unknown) => string | undefined;
38
+ onDataChanged: (options: {
39
+ path: string[];
40
+ }) => any;
41
+ openCodeEditor: (options: {
42
+ rootPath: string;
43
+ relativePath?: string | undefined;
44
+ line?: number | undefined;
45
+ column?: number | undefined;
46
+ }) => Promise<void>;
47
+ openConfigEditor: (options: unknown) => Promise<void>;
48
+ openFilePath: (options: {
49
+ rootPath: string;
50
+ relativePath?: string | undefined;
51
+ }) => Promise<void>;
52
+ reportMetric: (options: {
53
+ metric: string;
54
+ value: number;
55
+ }) => void;
56
+ validatePackageOverride: (options: {
57
+ packageName: string;
58
+ importPath: string;
59
+ }) => Promise<{
60
+ fixable: boolean;
61
+ }>;
62
+ }>;
63
+ //# sourceMappingURL=createCloudpackServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAIpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,uBAAuB,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCA"}
@@ -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,IAA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B,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"]}
@@ -1,7 +1,6 @@
1
1
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
2
2
  import type { Span } from '@ms-cloudpack/telemetry';
3
- import type { Session, TaskDescription } from './index.js';
4
- import { TaskRunner } from './utilities/TaskRunner.js';
3
+ import type { Session } from '../types/Session.js';
5
4
  import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
6
5
  /**
7
6
  * Creates the server context and returns a connection context factory.
@@ -10,17 +9,23 @@ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
10
9
  */
11
10
  export declare function createContextFactory(options: {
12
11
  session: Session;
13
- rootSpan: Span | undefined;
14
12
  reporter: TaskReporter;
13
+ rootSpan?: Span;
15
14
  packages: PackageDefinitionsCache;
16
15
  }): Promise<() => Promise<{
17
16
  session: Session;
18
17
  bus: import("@ms-cloudpack/data-bus").DataBus;
19
- allTasks: Map<string, TaskDescription>;
20
- taskRunner: TaskRunner;
21
18
  rootSpan: Span | undefined;
22
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
+ };
23
27
  packages: PackageDefinitionsCache;
28
+ dispose(): Promise<void>;
24
29
  }>>;
25
30
  export type CreateContext = Awaited<ReturnType<typeof createContextFactory>>;
26
31
  export type Context = Awaited<ReturnType<CreateContext>>;
@@ -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 { TaskRunner } from './utilities/TaskRunner.js';
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
- // Push initial stats.
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
- export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
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>(opts: CreateHTTPHandlerOptions<TRouter>): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
8
- export declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): {
9
- server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
10
- listen: (port: number, hostname?: string) => {
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,C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ACL,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,23 @@
1
+ import type { BundleResult } from '@ms-cloudpack/bundler-types';
2
+ import type { TaskResult } from './TaskResult.js';
3
+ export interface BundleResultExtended extends TaskResult, BundleResult {
4
+ /**
5
+ * The dependencies of the package, computed in `bundleTask` by parsing the output of the bundle result.
6
+ */
7
+ dependencies?: string[];
8
+ /**
9
+ * The hash of the bundle input, computed in `bundleTask` by hashing the source input.
10
+ */
11
+ hash?: string;
12
+ /**
13
+ * Where the output originates from. In cases where we can leverage disk cache to avoid bundling, we will.
14
+ */
15
+ from?: 'bundle' | 'cache';
16
+ /**
17
+ * Whether the input was considered an external package. This affects how cached results
18
+ * are leveraged, whether file watching will be used, and how the bundle is retuned to the
19
+ * client.
20
+ */
21
+ isExternal: boolean;
22
+ }
23
+ //# sourceMappingURL=BundleResultExtended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleResultExtended.d.ts","sourceRoot":"","sources":["../../src/types/BundleResultExtended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,MAAM,WAAW,oBAAqB,SAAQ,UAAU,EAAE,YAAY;IACpE;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAE1B;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BundleResultExtended.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleResultExtended.js","sourceRoot":"","sources":["../../src/types/BundleResultExtended.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleResult } from '@ms-cloudpack/bundler-types';\nimport type { TaskResult } from './TaskResult.js';\nexport interface BundleResultExtended extends TaskResult, BundleResult {\n /**\n * The dependencies of the package, computed in `bundleTask` by parsing the output of the bundle result.\n */\n dependencies?: string[];\n\n /**\n * The hash of the bundle input, computed in `bundleTask` by hashing the source input.\n */\n hash?: string;\n\n /**\n * Where the output originates from. In cases where we can leverage disk cache to avoid bundling, we will.\n */\n from?: 'bundle' | 'cache';\n\n /**\n * Whether the input was considered an external package. This affects how cached results\n * are leveraged, whether file watching will be used, and how the bundle is retuned to the\n * client.\n */\n isExternal: boolean;\n}\n"]}
@@ -1,9 +1,135 @@
1
- import type { TaskStartDescription } from './TaskStartDescription.js';
2
- import type { TaskEndDescription } from './TaskEndDescription.js';
3
- export interface TaskDescription extends TaskStartDescription, TaskEndDescription {
4
- status: 'pending' | 'complete';
1
+ import z from 'zod';
2
+ export declare const ZodTaskDescription: z.ZodObject<{
3
+ status: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"pending">, z.ZodLiteral<"complete">]>>;
4
+ name: z.ZodOptional<z.ZodString>;
5
+ inputPath: z.ZodOptional<z.ZodString>;
6
+ outputPath: z.ZodOptional<z.ZodString>;
7
+ timings: z.ZodOptional<z.ZodArray<z.ZodObject<{
8
+ name: z.ZodString;
9
+ start: z.ZodNumber;
10
+ end: z.ZodOptional<z.ZodNumber>;
11
+ threwException: z.ZodOptional<z.ZodBoolean>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ name: string;
14
+ start: number;
15
+ end?: number | undefined;
16
+ threwException?: boolean | undefined;
17
+ }, {
18
+ name: string;
19
+ start: number;
20
+ end?: number | undefined;
21
+ threwException?: boolean | undefined;
22
+ }>, "many">>;
23
+ startTime: z.ZodNumber;
24
+ durationMilliseconds: z.ZodOptional<z.ZodNumber>;
25
+ lastUpdated: z.ZodOptional<z.ZodNumber>;
26
+ id: z.ZodString;
27
+ errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
+ message: z.ZodString;
29
+ pluginName: z.ZodString;
30
+ stack: z.ZodString;
31
+ fileLocation: z.ZodString;
32
+ lineNumber: z.ZodNumber;
33
+ columnNumber: z.ZodNumber;
34
+ }, "strip", z.ZodTypeAny, {
35
+ message: string;
36
+ pluginName: string;
37
+ stack: string;
38
+ fileLocation: string;
39
+ lineNumber: number;
40
+ columnNumber: number;
41
+ }, {
42
+ message: string;
43
+ pluginName: string;
44
+ stack: string;
45
+ fileLocation: string;
46
+ lineNumber: number;
47
+ columnNumber: number;
48
+ }>, "many">>;
49
+ warnings: z.ZodOptional<z.ZodArray<z.ZodObject<{
50
+ message: z.ZodString;
51
+ pluginName: z.ZodString;
52
+ stack: z.ZodString;
53
+ fileLocation: z.ZodString;
54
+ lineNumber: z.ZodNumber;
55
+ columnNumber: z.ZodNumber;
56
+ }, "strip", z.ZodTypeAny, {
57
+ message: string;
58
+ pluginName: string;
59
+ stack: string;
60
+ fileLocation: string;
61
+ lineNumber: number;
62
+ columnNumber: number;
63
+ }, {
64
+ message: string;
65
+ pluginName: string;
66
+ stack: string;
67
+ fileLocation: string;
68
+ lineNumber: number;
69
+ columnNumber: number;
70
+ }>, "many">>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ id: string;
5
73
  startTime: number;
6
- durationMilliseconds?: number;
7
- lastUpdated?: number;
8
- }
74
+ status?: "pending" | "complete" | undefined;
75
+ name?: string | undefined;
76
+ inputPath?: string | undefined;
77
+ outputPath?: string | undefined;
78
+ timings?: {
79
+ name: string;
80
+ start: number;
81
+ end?: number | undefined;
82
+ threwException?: boolean | undefined;
83
+ }[] | undefined;
84
+ durationMilliseconds?: number | undefined;
85
+ lastUpdated?: number | undefined;
86
+ errors?: {
87
+ message: string;
88
+ pluginName: string;
89
+ stack: string;
90
+ fileLocation: string;
91
+ lineNumber: number;
92
+ columnNumber: number;
93
+ }[] | undefined;
94
+ warnings?: {
95
+ message: string;
96
+ pluginName: string;
97
+ stack: string;
98
+ fileLocation: string;
99
+ lineNumber: number;
100
+ columnNumber: number;
101
+ }[] | undefined;
102
+ }, {
103
+ id: string;
104
+ startTime: number;
105
+ status?: "pending" | "complete" | undefined;
106
+ name?: string | undefined;
107
+ inputPath?: string | undefined;
108
+ outputPath?: string | undefined;
109
+ timings?: {
110
+ name: string;
111
+ start: number;
112
+ end?: number | undefined;
113
+ threwException?: boolean | undefined;
114
+ }[] | undefined;
115
+ durationMilliseconds?: number | undefined;
116
+ lastUpdated?: number | undefined;
117
+ errors?: {
118
+ message: string;
119
+ pluginName: string;
120
+ stack: string;
121
+ fileLocation: string;
122
+ lineNumber: number;
123
+ columnNumber: number;
124
+ }[] | undefined;
125
+ warnings?: {
126
+ message: string;
127
+ pluginName: string;
128
+ stack: string;
129
+ fileLocation: string;
130
+ lineNumber: number;
131
+ columnNumber: number;
132
+ }[] | undefined;
133
+ }>;
134
+ export type TaskDescription = z.infer<typeof ZodTaskDescription>;
9
135
  //# sourceMappingURL=TaskDescription.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskDescription.d.ts","sourceRoot":"","sources":["../../src/types/TaskDescription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,MAAM,WAAW,eAAgB,SAAQ,oBAAoB,EAAE,kBAAkB;IAC/E,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
1
+ {"version":3,"file":"TaskDescription.d.ts","sourceRoot":"","sources":["../../src/types/TaskDescription.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}