MCPcopy Index your code
hub / github.com/upstash/jstack / dynamic

Function dynamic

packages/jstack/src/server/dynamic.ts:18–48  ·  view source on GitHub ↗
(
  importFn: () => Promise<{ [key: string]: T }>,
)

Source from the content-addressed store, hash-verified

16 * })
17 */
18export const dynamic = <T extends Router>(
19 importFn: () => Promise<{ [key: string]: T }>,
20) => {
21 return async () => {
22 const module = await importFn()
23 const routers = Object.values(module)
24
25 if (routers.length === 0) {
26 throw new Error(
27 "Error dynamically loading router: Invalid router module - Expected a default or named export of a Router, but received an empty module. Did you forget to export your router?",
28 )
29 }
30
31 if (routers.length > 1) {
32 throw new Error(
33 `Error dynamically loading router: Multiple Router exports detected in module (${Object.keys(module).join(", ")}). ` +
34 "Please export only one Router instance per module."
35 )
36 }
37
38 const router = routers[0]
39 if (!(router instanceof Router)) {
40 throw new Error(
41 "Error dynamically loading router: Invalid router module - Expected exported value to be a Router instance, " +
42 `but received ${router === null ? "null" : typeof router}. Are you exporting multiple functions from this file?`,
43 )
44 }
45
46 return router
47 }
48}

Callers

nothing calls this directly

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected