@ms-cloudpack/app-server 0.20.0 → 0.20.2

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 (60) hide show
  1. package/lib/renderRoute/getErrorResponse.d.ts +20 -0
  2. package/lib/renderRoute/getErrorResponse.d.ts.map +1 -0
  3. package/lib/renderRoute/getErrorResponse.js +44 -0
  4. package/lib/renderRoute/getErrorResponse.js.map +1 -0
  5. package/lib/renderRoute/injectScripts.d.ts +8 -0
  6. package/lib/renderRoute/injectScripts.d.ts.map +1 -0
  7. package/lib/renderRoute/injectScripts.js +81 -0
  8. package/lib/renderRoute/injectScripts.js.map +1 -0
  9. package/lib/renderRoute/isHtmlAcceptable.d.ts +11 -0
  10. package/lib/renderRoute/isHtmlAcceptable.d.ts.map +1 -0
  11. package/lib/renderRoute/isHtmlAcceptable.js +26 -0
  12. package/lib/renderRoute/isHtmlAcceptable.js.map +1 -0
  13. package/lib/renderRoute/renderRoute.d.ts +1 -1
  14. package/lib/renderRoute/renderRoute.d.ts.map +1 -1
  15. package/lib/renderRoute/renderRoute.js +17 -174
  16. package/lib/renderRoute/renderRoute.js.map +1 -1
  17. package/lib/renderRoute/ssr/bundleServerEntry.d.ts +7 -0
  18. package/lib/renderRoute/ssr/bundleServerEntry.d.ts.map +1 -0
  19. package/lib/renderRoute/ssr/bundleServerEntry.js +54 -0
  20. package/lib/renderRoute/ssr/bundleServerEntry.js.map +1 -0
  21. package/lib/renderRoute/{renderCustomScript.d.ts → ssr/renderCustomScript.d.ts} +1 -0
  22. package/lib/renderRoute/ssr/renderCustomScript.d.ts.map +1 -0
  23. package/lib/renderRoute/{renderCustomScript.js → ssr/renderCustomScript.js} +19 -16
  24. package/lib/renderRoute/ssr/renderCustomScript.js.map +1 -0
  25. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts +1 -1
  26. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts.map +1 -1
  27. package/lib/renderRoute/ssr/runServerEntryInWorker.js +8 -18
  28. package/lib/renderRoute/ssr/runServerEntryInWorker.js.map +1 -1
  29. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts +7 -2
  30. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts.map +1 -1
  31. package/lib/renderRoute/ssr/types/RunServerEntryOptions.js.map +1 -1
  32. package/lib/renderRoute/ssr/worker/importMapLoader.d.ts +36 -0
  33. package/lib/renderRoute/ssr/worker/importMapLoader.d.ts.map +1 -0
  34. package/lib/renderRoute/ssr/worker/importMapLoader.js +64 -0
  35. package/lib/renderRoute/ssr/worker/importMapLoader.js.map +1 -0
  36. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts +13 -0
  37. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts.map +1 -0
  38. package/lib/renderRoute/ssr/{runServerEntry.js → worker/runServerEntry.js} +18 -8
  39. package/lib/renderRoute/ssr/worker/runServerEntry.js.map +1 -0
  40. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.d.ts +2 -0
  41. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.d.ts.map +1 -0
  42. package/lib/renderRoute/ssr/worker/{workerEntry.js → ssrWorkerEntry.js} +4 -4
  43. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.js.map +1 -0
  44. package/package.json +4 -4
  45. package/lib/renderRoute/getHtmlErrorResponse.d.ts +0 -6
  46. package/lib/renderRoute/getHtmlErrorResponse.d.ts.map +0 -1
  47. package/lib/renderRoute/getHtmlErrorResponse.js +0 -22
  48. package/lib/renderRoute/getHtmlErrorResponse.js.map +0 -1
  49. package/lib/renderRoute/renderCustomScript.d.ts.map +0 -1
  50. package/lib/renderRoute/renderCustomScript.js.map +0 -1
  51. package/lib/renderRoute/ssr/importMapLoader.d.ts +0 -13
  52. package/lib/renderRoute/ssr/importMapLoader.d.ts.map +0 -1
  53. package/lib/renderRoute/ssr/importMapLoader.js +0 -37
  54. package/lib/renderRoute/ssr/importMapLoader.js.map +0 -1
  55. package/lib/renderRoute/ssr/runServerEntry.d.ts +0 -4
  56. package/lib/renderRoute/ssr/runServerEntry.d.ts.map +0 -1
  57. package/lib/renderRoute/ssr/runServerEntry.js.map +0 -1
  58. package/lib/renderRoute/ssr/worker/workerEntry.d.ts +0 -2
  59. package/lib/renderRoute/ssr/worker/workerEntry.d.ts.map +0 -1
  60. package/lib/renderRoute/ssr/worker/workerEntry.js.map +0 -1
@@ -1,37 +0,0 @@
1
- /**
2
- * NOTE: This file is a custom loader for "bare" imports in nodejs
3
- * It should ONLY import types and not any runtime code.
4
- */
5
- let importMap = { imports: {} };
6
- export function initialize(context) {
7
- importMap = context.importMap || { imports: {} };
8
- }
9
- export function resolve(specifier, context, defaultResolve) {
10
- // TODO: Deal with scope
11
- const target = importMap?.imports?.[specifier];
12
- if (target) {
13
- console.log(`Import map redirect: ${specifier} -> ${target}`);
14
- return {
15
- url: target,
16
- shortCircuit: true,
17
- };
18
- }
19
- return defaultResolve(specifier, context);
20
- }
21
- export async function load(url, context, defaultLoad) {
22
- if (url.startsWith('http')) {
23
- console.log(`Importing from URL: ${url}`);
24
- const res = await fetch(url);
25
- if (!res.ok) {
26
- throw new Error(`Failed to fetch ${url} (Status: ${res.status})`);
27
- }
28
- const source = await res.text();
29
- return {
30
- format: 'module',
31
- source,
32
- shortCircuit: true,
33
- };
34
- }
35
- return defaultLoad(url, context);
36
- }
37
- //# sourceMappingURL=importMapLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"importMapLoader.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/importMapLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,IAAI,SAAS,GAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAC3C,MAAM,UAAU,UAAU,CAAC,OAA8B;IACvD,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACnD,CAAC;AAID,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,OAA2B,EAC3B,cAA8B;IAE9B,wBAAwB;IACxB,MAAM,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,OAAO,MAAM,EAAE,CAAC,CAAC;QAC9D,OAAO;YACL,GAAG,EAAE,MAAM;YACX,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAID,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,OAAwB,EAAE,WAAwB;IACxF,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAE1C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEhC,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,MAAM;YACN,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * NOTE: This file is a custom loader for \"bare\" imports in nodejs\n * It should ONLY import types and not any runtime code.\n */\n\nimport type { ResolveHookContext, LoadFnOutput, LoadHookContext, ResolveFnOutput } from 'module';\nimport type { ImportMap } from '@ms-cloudpack/common-types';\nimport type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';\n\nlet importMap: ImportMap = { imports: {} };\nexport function initialize(context: RunServerEntryOptions): void {\n importMap = context.importMap || { imports: {} };\n}\n\ntype DefaultResolve = (specifier: string, context: ResolveHookContext) => ResolveFnOutput;\n\nexport function resolve(\n specifier: string,\n context: ResolveHookContext,\n defaultResolve: DefaultResolve,\n): ResolveFnOutput {\n // TODO: Deal with scope\n const target = importMap?.imports?.[specifier];\n if (target) {\n console.log(`Import map redirect: ${specifier} -> ${target}`);\n return {\n url: target,\n shortCircuit: true,\n };\n }\n\n return defaultResolve(specifier, context);\n}\n\ntype DefaultLoad = (url: string, context: LoadHookContext) => Promise<LoadFnOutput>;\n\nexport async function load(url: string, context: LoadHookContext, defaultLoad: DefaultLoad): Promise<LoadFnOutput> {\n if (url.startsWith('http')) {\n console.log(`Importing from URL: ${url}`);\n\n const res = await fetch(url);\n if (!res.ok) {\n throw new Error(`Failed to fetch ${url} (Status: ${res.status})`);\n }\n\n const source = await res.text();\n\n return {\n format: 'module',\n source,\n shortCircuit: true,\n };\n }\n\n return defaultLoad(url, context);\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';
2
- import type { RunServerEntryResult } from './types/RunServerEntryResult.js';
3
- export declare function runServerEntry(options: RunServerEntryOptions): Promise<RunServerEntryResult>;
4
- //# sourceMappingURL=runServerEntry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runServerEntry.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAS5E,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA4BlG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"runServerEntry.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IACjE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEzE,0GAA0G;IAC1G,QAAQ,CAAC,UAAU,EAAE;QACnB,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QACzC,IAAI,EAAE,EAAE,SAAS,EAAE;KACpB,CAAC,CAAC;IAEH,0EAA0E;IAC1E,qEAAqE;IACrE,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;SACjD,IAAI,CAAC,CAAC,GAAiB,EAAE,EAAE;QAC1B,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACrC,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,eAAe,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEL,OAAO,EAAE,eAAe,EAAE,cAAc,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC","sourcesContent":["import { register } from 'node:module';\nimport type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';\nimport type { RunServerEntryResult } from './types/RunServerEntryResult.js';\nimport { pathToFileURL } from 'node:url';\nimport type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';\n\ntype RenderModule = {\n render?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n default?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n};\n\nexport async function runServerEntry(options: RunServerEntryOptions): Promise<RunServerEntryResult> {\n const { importMap, renderScriptUrl, loaderPath, renderParams } = options;\n\n // Registers the customer loader, which is responsible for handling base-imports in a nodejs environment..\n register(loaderPath, {\n parentURL: pathToFileURL(import.meta.url),\n data: { importMap },\n });\n\n // With the custom loader registered, we can now import the render script.\n // We support both named and default exports for the render function.\n const renderedResult = await import(renderScriptUrl)\n .then((mod: RenderModule) => {\n if (typeof mod.render === 'function') {\n return mod.render(renderParams);\n } else if (typeof mod.default === 'function') {\n return mod.default(renderParams);\n }\n throw new Error(`No render function found in module: ${renderScriptUrl}`);\n })\n .then((output) => {\n return output;\n })\n .catch((err) => {\n console.log('Error:', err);\n });\n\n return { renderedContent: renderedResult || '' };\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=workerEntry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workerEntry.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/workerEntry.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/workerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,kFAAkF;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE/C,gFAAgF;AAChF,gBAAgB,CAAC;IACf,OAAO,EAAE;QACP,cAAc;KACf;IACD,UAAU,EAAE,GAAG,EAAE;QACf,0FAA0F;QAC1F,mFAAmF;QACnF,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACd,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;IAC7B,CAAC;IACD,4FAA4F;IAC5F,+DAA+D;IAC/D,OAAO,EAAE,EAAE,GAAG,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { initializeWorker } from '@ms-cloudpack/worker-pool';\nimport { runServerEntry } from '../runServerEntry.js';\n\n// eslint-disable-next-line no-restricted-properties -- exit handling for a worker\nconst processExit = process.exit.bind(process);\n\n// Then initialize the worker with the appropriate listeners and api dictionary.\ninitializeWorker({\n methods: {\n runServerEntry,\n },\n beforeEach: () => {\n // Override process.exit calls to throw rather than exit the process, in case we load some\n // CJS code that calls process.exit. This gives an actual call stack for debugging.\n // eslint-disable-next-line no-restricted-properties\n process.exit = (code) => {\n throw new Error(`process.exit called with code ${code}`);\n };\n },\n afterEach: () => {\n // eslint-disable-next-line no-restricted-properties\n process.exit = processExit;\n },\n // Stop the worker after 30s. This is much longer than should usually be necessary, but it's\n // good to be conservative here in case of resource contention.\n timeout: 30 * 1000,\n});\n"]}