@aws/nx-plugin 0.112.1 → 0.114.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 (84) hide show
  1. package/LICENSE-THIRD-PARTY +957 -429
  2. package/generators.json +33 -1
  3. package/package.json +1 -1
  4. package/src/connection/generator.d.ts +2 -2
  5. package/src/connection/generator.js +19 -0
  6. package/src/connection/generator.js.map +1 -1
  7. package/src/py/project/generator.js +4 -0
  8. package/src/py/project/generator.js.map +1 -1
  9. package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +42 -20
  10. package/src/py/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentSnakeCase___client.py.template +6 -13
  11. package/src/py/strands-agent/a2a-connection/generator.js +1 -1
  12. package/src/py/strands-agent/files/a2a/main.py.template +24 -3
  13. package/src/py/strands-agent/files/ag-ui/main.py.template +3 -2
  14. package/src/py/strands-agent/files/common/agent.py.template +1 -2
  15. package/src/py/strands-agent/files/http/main.py.template +32 -13
  16. package/src/py/strands-agent/generator.js +11 -0
  17. package/src/py/strands-agent/generator.js.map +1 -1
  18. package/src/py/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +66 -59
  19. package/src/py/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerSnakeCase___client.py.template +6 -14
  20. package/src/py/strands-agent/mcp-connection/generator.js +3 -3
  21. package/src/smithy/project/__snapshots__/generator.spec.ts.snap +2 -2
  22. package/src/smithy/project/files/build.Dockerfile.template +1 -1
  23. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +4 -3
  24. package/src/ts/mcp-server/files/http.ts.template +1 -1
  25. package/src/ts/mcp-server/files/server.ts.template +1 -1
  26. package/src/ts/mcp-server/files/stdio.ts.template +2 -1
  27. package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +3 -2
  28. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +54 -44
  29. package/src/ts/rdb/files/src/prisma.ts.template +54 -46
  30. package/src/ts/rdb/generator.js +3 -0
  31. package/src/ts/rdb/generator.js.map +1 -1
  32. package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +117 -0
  33. package/src/ts/rdb/mcp-server-connection/generator.d.ts +10 -0
  34. package/src/ts/rdb/mcp-server-connection/generator.js +59 -0
  35. package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -0
  36. package/src/ts/rdb/mcp-server-connection/schema.d.ts +14 -0
  37. package/src/ts/rdb/mcp-server-connection/schema.json +22 -0
  38. package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +286 -0
  39. package/src/ts/rdb/smithy-connection/generator.d.ts +10 -0
  40. package/src/ts/rdb/smithy-connection/generator.js +72 -0
  41. package/src/ts/rdb/smithy-connection/generator.js.map +1 -0
  42. package/src/ts/rdb/smithy-connection/schema.d.ts +12 -0
  43. package/src/ts/rdb/smithy-connection/schema.json +18 -0
  44. package/src/ts/rdb/strands-agent-connection/__snapshots__/generator.spec.ts.snap +183 -0
  45. package/src/ts/rdb/strands-agent-connection/generator.d.ts +10 -0
  46. package/src/ts/rdb/strands-agent-connection/generator.js +65 -0
  47. package/src/ts/rdb/strands-agent-connection/generator.js.map +1 -0
  48. package/src/ts/rdb/strands-agent-connection/schema.d.ts +14 -0
  49. package/src/ts/rdb/strands-agent-connection/schema.json +22 -0
  50. package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +75 -0
  51. package/src/ts/rdb/trpc-connection/files/src/middleware/__rdbNameKebab__.ts.template +32 -0
  52. package/src/ts/rdb/trpc-connection/generator.d.ts +10 -0
  53. package/src/ts/rdb/trpc-connection/generator.js +41 -0
  54. package/src/ts/rdb/trpc-connection/generator.js.map +1 -0
  55. package/src/ts/rdb/trpc-connection/schema.d.ts +12 -0
  56. package/src/ts/rdb/trpc-connection/schema.json +18 -0
  57. package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +17 -7
  58. package/src/ts/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client.ts.template +6 -14
  59. package/src/ts/strands-agent/a2a-connection/generator.js +2 -3
  60. package/src/ts/strands-agent/a2a-connection/generator.js.map +1 -1
  61. package/src/ts/strands-agent/files/a2a/index.ts.template +12 -2
  62. package/src/ts/strands-agent/files/common/agent.ts.template +2 -4
  63. package/src/ts/strands-agent/files/http/init.ts.template +12 -1
  64. package/src/ts/strands-agent/files/http/router.ts.template +3 -2
  65. package/src/ts/strands-agent/generator.js +7 -0
  66. package/src/ts/strands-agent/generator.js.map +1 -1
  67. package/src/ts/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +46 -71
  68. package/src/ts/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client.ts.template +8 -19
  69. package/src/ts/strands-agent/mcp-connection/generator.js +1 -1
  70. package/src/ts/strands-agent/mcp-connection/generator.js.map +1 -1
  71. package/src/utils/agent-connection/agent-connection.js +22 -0
  72. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  73. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client.ts.template +46 -57
  74. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-client.ts.template +35 -51
  75. package/src/utils/agent-connection/files/core-runtime-config/session-context.ts.template +21 -0
  76. package/src/utils/agent-connection/files/core-runtime-config/with-session-id.ts.template +27 -0
  77. package/src/utils/agent-connection/files/py-core-a2a/agentcore_a2a_client.py.template +44 -15
  78. package/src/utils/agent-connection/files/py-core-mcp/agentcore_mcp_client.py.template +50 -43
  79. package/src/utils/agent-connection/files/py-core-runtime-config/session_context.py.template +22 -0
  80. package/src/utils/agent-connection/files/py-core-runtime-config/with_session_id.py.template +44 -0
  81. package/src/utils/ast.js +9 -2
  82. package/src/utils/ast.js.map +1 -1
  83. package/src/utils/bundle/bundle.js +1 -0
  84. package/src/utils/bundle/bundle.js.map +1 -1
@@ -3,9 +3,19 @@
3
3
  exports[`py#strands-agent#mcp-connection generator > should match snapshot for generated files > agent-connection-init.py 1`] = `
4
4
  """"Automatically generated by Nx."""
5
5
 
6
+ from .core.session_context import get_current_session_id, session_id_context
7
+
6
8
  from .app.inventory_mcp_client import InventoryMcpClient
7
9
 
8
- __all__ = ["InventoryMcpClient"]
10
+ from .core.with_session_id import with_session_id
11
+
12
+
13
+ __all__ = [
14
+ "get_current_session_id",
15
+ "session_id_context",
16
+ "with_session_id",
17
+ "InventoryMcpClient",
18
+ ]
9
19
  "
10
20
  `;
11
21
 
@@ -18,10 +28,32 @@ from mcp.client.streamable_http import streamablehttp_client
18
28
  from strands.tools.mcp.mcp_client import MCPClient
19
29
 
20
30
  from .auth import SigV4HTTPXAuth
31
+ from .session_context import get_current_session_id
32
+
33
+ SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"
34
+
35
+
36
+ class _SessionHeaderAuth(httpx.Auth):
37
+ """Stamps the AgentCore session header from the current async context."""
38
+
39
+ requires_request_body = True
40
+ requires_response_body = True
41
+
42
+ def __init__(self, inner: httpx.Auth | None = None):
43
+ self._inner = inner
44
+
45
+ def auth_flow(self, request: httpx.Request): # type: ignore[override]
46
+ sid = get_current_session_id()
47
+ if sid:
48
+ request.headers[SESSION_HEADER] = sid
49
+ if self._inner is None:
50
+ yield request
51
+ return
52
+ yield from self._inner.auth_flow(request)
21
53
 
22
54
 
23
55
  class AgentCoreMCPClient:
24
- """Factory for clients to call MCP servers hosted on Bedrock AgentCore Runtime."""
56
+ """Factory for MCP clients that forward the current async-context session."""
25
57
 
26
58
  @staticmethod
27
59
  def _build_url(agent_runtime_arn: str) -> tuple[str, str]:
@@ -31,74 +63,58 @@ class AgentCoreMCPClient:
31
63
  """
32
64
  region = agent_runtime_arn.split(":")[3]
33
65
  encoded_arn = agent_runtime_arn.replace(":", "%3A").replace("/", "%2F")
34
- url = f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/{encoded_arn}/invocations?qualifier=DEFAULT"
66
+ url = (
67
+ f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/"
68
+ f"{encoded_arn}/invocations?qualifier=DEFAULT"
69
+ )
35
70
  return region, url
36
71
 
37
72
  @staticmethod
38
- def _create(
39
- agent_runtime_arn: str,
40
- session_id: str,
41
- headers: dict | None = None,
42
- auth_handler: httpx.Auth | None = None,
43
- ) -> MCPClient:
44
- _, url = AgentCoreMCPClient._build_url(agent_runtime_arn)
73
+ def _create(url: str, auth: httpx.Auth | None = None) -> MCPClient:
45
74
  return MCPClient(
46
75
  lambda: streamablehttp_client(
47
76
  url,
48
- auth=auth_handler,
77
+ auth=_SessionHeaderAuth(auth),
49
78
  timeout=120,
50
79
  terminate_on_close=False,
51
- headers={
52
- "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id": session_id,
53
- **(headers if headers is not None else {}),
54
- },
55
80
  )
56
81
  )
57
82
 
58
83
  @staticmethod
59
- def with_iam_auth(agent_runtime_arn: str, session_id: str) -> MCPClient:
60
- """Create an MCP client with IAM (SigV4) authentication.
61
-
62
- Region and credentials are derived automatically from the ARN
63
- and the default credential provider chain.
64
- """
65
- region, _ = AgentCoreMCPClient._build_url(agent_runtime_arn)
66
- boto_session = boto3.Session(region_name=region)
67
- credentials = boto_session.get_credentials()
84
+ def with_iam_auth(agent_runtime_arn: str) -> MCPClient:
85
+ """SigV4-authenticated client for a Bedrock AgentCore runtime."""
86
+ region, url = AgentCoreMCPClient._build_url(agent_runtime_arn)
87
+ credentials = boto3.Session(region_name=region).get_credentials()
68
88
  return AgentCoreMCPClient._create(
69
- agent_runtime_arn=agent_runtime_arn,
70
- session_id=session_id,
71
- auth_handler=SigV4HTTPXAuth(credentials, "bedrock-agentcore", region),
89
+ url, SigV4HTTPXAuth(credentials, "bedrock-agentcore", region)
72
90
  )
73
91
 
74
92
  @staticmethod
75
93
  def with_jwt_auth(
76
- agent_runtime_arn: str,
77
- access_token_provider: Callable[[], str],
78
- session_id: str,
94
+ agent_runtime_arn: str, access_token_provider: Callable[[], str]
79
95
  ) -> MCPClient:
80
- """Create an MCP client with JWT authentication.
81
-
82
- Args:
83
- agent_runtime_arn: The ARN of the AgentCore runtime.
84
- access_token_provider: A callable that returns the JWT access token.
85
- session_id: Session ID for the connection.
86
- """
87
- access_token = access_token_provider()
88
- return AgentCoreMCPClient._create(
89
- agent_runtime_arn=agent_runtime_arn,
90
- session_id=session_id,
91
- headers={
92
- "Authorization": f"Bearer {access_token}",
93
- },
96
+ """Bearer-authenticated client for a Bedrock AgentCore runtime."""
97
+ _, url = AgentCoreMCPClient._build_url(agent_runtime_arn)
98
+ return MCPClient(
99
+ lambda: streamablehttp_client(
100
+ url,
101
+ auth=_SessionHeaderAuth(),
102
+ headers={"Authorization": f"Bearer {access_token_provider()}"},
103
+ timeout=120,
104
+ terminate_on_close=False,
105
+ )
94
106
  )
107
+
108
+ @staticmethod
109
+ def without_auth(url: str) -> MCPClient:
110
+ """Plain-HTTP client — for local dev."""
111
+ return AgentCoreMCPClient._create(url)
95
112
  "
96
113
  `;
97
114
 
98
115
  exports[`py#strands-agent#mcp-connection generator > should match snapshot for generated files > inventory_mcp_client.py 1`] = `
99
116
  "import os
100
117
 
101
- from mcp.client.streamable_http import streamablehttp_client
102
118
  from strands.tools.mcp.mcp_client import MCPClient
103
119
 
104
120
  from proj_agent_connection.core.agentcore_mcp_client import AgentCoreMCPClient
@@ -108,23 +124,14 @@ from proj_agent_connection.core.runtime_config import (
108
124
 
109
125
 
110
126
  class InventoryMcpClient:
111
- """Client for connecting to the InventoryMcp MCP server.
112
-
113
- In deployed mode: resolves the AgentCore runtime ARN from runtime config
114
- and uses SigV4-authenticated AgentCore transport.
115
-
116
- In local mode (SERVE_LOCAL env var set): connects directly
117
- to the local MCP server via Streamable HTTP.
118
- """
127
+ """Client for the InventoryMcp MCP server."""
119
128
 
120
129
  @staticmethod
121
- def create(session_id: str) -> MCPClient:
130
+ def create() -> MCPClient:
122
131
  if os.environ.get("SERVE_LOCAL") == "true":
123
- return MCPClient(lambda: streamablehttp_client("http://localhost:8082/mcp"))
124
-
132
+ return AgentCoreMCPClient.without_auth("http://localhost:8082/mcp")
125
133
  return AgentCoreMCPClient.with_iam_auth(
126
- agent_runtime_arn=get_connected_agent_runtime_arn("InventoryMcp"),
127
- session_id=session_id,
134
+ get_connected_agent_runtime_arn("InventoryMcp")
128
135
  )
129
136
  "
130
137
  `;
@@ -145,7 +152,7 @@ def subtract(a: int, b: int) -> int:
145
152
 
146
153
  @contextmanager
147
154
  def get_agent(session_id: str):
148
- inventory_mcp = InventoryMcpClient.create(session_id=session_id)
155
+ inventory_mcp = InventoryMcpClient.create()
149
156
  with (
150
157
  inventory_mcp,
151
158
  ):
@@ -1,6 +1,5 @@
1
1
  import os
2
2
 
3
- from mcp.client.streamable_http import streamablehttp_client
4
3
  from strands.tools.mcp.mcp_client import MCPClient
5
4
 
6
5
  from <%- agentConnectionModuleName %>.core.agentcore_mcp_client import AgentCoreMCPClient
@@ -10,21 +9,14 @@ from <%- agentConnectionModuleName %>.core.runtime_config import (
10
9
 
11
10
 
12
11
  class <%- mcpServerClassName %>Client:
13
- """Client for connecting to the <%- mcpServerClassName %> MCP server.
14
-
15
- In deployed mode: resolves the AgentCore runtime ARN from runtime config
16
- and uses SigV4-authenticated AgentCore transport.
17
-
18
- In local mode (SERVE_LOCAL env var set): connects directly
19
- to the local MCP server via Streamable HTTP.
20
- """
12
+ """Client for the <%- mcpServerClassName %> MCP server."""
21
13
 
22
14
  @staticmethod
23
- def create(session_id: str) -> MCPClient:
15
+ def create() -> MCPClient:
24
16
  if os.environ.get("SERVE_LOCAL") == "true":
25
- return MCPClient(lambda: streamablehttp_client("http://localhost:<%- mcpServerPort %>/mcp"))
26
-
17
+ return AgentCoreMCPClient.without_auth(
18
+ "http://localhost:<%- mcpServerPort %>/mcp"
19
+ )
27
20
  return AgentCoreMCPClient.with_iam_auth(
28
- agent_runtime_arn=get_connected_agent_runtime_arn("<%- mcpServerClassName %>"),
29
- session_id=session_id,
21
+ get_connected_agent_runtime_arn("<%- mcpServerClassName %>")
30
22
  )
@@ -141,9 +141,9 @@ const addMcpClientToGetAgent = async (tree, filePath, clientClassName, clientVar
141
141
  }`));
142
142
  if (addedToWith) {
143
143
  // Subsequent connection — also add creation line after the existing one
144
- await (0, ast_1.applyGritQL)(tree, filePath, py(`\`$var = $cls.create(session_id=session_id)\` as $stmt where {
144
+ await (0, ast_1.applyGritQL)(tree, filePath, py(`\`$var = $cls.create()\` as $stmt where {
145
145
  $program <: not contains \`${clientClassName}.create\`,
146
- $stmt += \`\n${clientVarName} = ${clientClassName}.create(session_id=session_id)\`
146
+ $stmt += \`\n${clientVarName} = ${clientClassName}.create()\`
147
147
  }`));
148
148
  return;
149
149
  }
@@ -155,7 +155,7 @@ const addMcpClientToGetAgent = async (tree, filePath, clientClassName, clientVar
155
155
  $body <: contains \`yield Agent($_)\`,
156
156
  $body <: not contains \`with ($_, ): $_\`
157
157
  } => \`def get_agent($params):
158
- ${clientVarName} = ${clientClassName}.create(session_id=session_id)
158
+ ${clientVarName} = ${clientClassName}.create()
159
159
  with (
160
160
  ${clientVarName},
161
161
  ):
@@ -154,7 +154,7 @@ RUN smithy-install/smithy/install
154
154
 
155
155
  # Add node dependencies for bundling
156
156
  WORKDIR /project
157
- RUN npm i -g pnpm@10.15.1 rolldown@1.0.0-beta.38
157
+ RUN npm i -g pnpm@11.1.1 rolldown@1.0.0-beta.38
158
158
 
159
159
  # Copy project files
160
160
  COPY smithy-build.json .
@@ -395,7 +395,7 @@ RUN smithy-install/smithy/install
395
395
 
396
396
  # Add node dependencies for bundling
397
397
  WORKDIR /project
398
- RUN npm i -g pnpm@10.15.1 rolldown@1.0.0-beta.38
398
+ RUN npm i -g pnpm@11.1.1 rolldown@1.0.0-beta.38
399
399
 
400
400
  # Copy project files
401
401
  COPY smithy-build.json .
@@ -16,7 +16,7 @@ RUN smithy-install/smithy/install
16
16
 
17
17
  # Add node dependencies for bundling
18
18
  WORKDIR /project
19
- RUN npm i -g pnpm@10.15.1 rolldown@1.0.0-beta.38
19
+ RUN npm i -g pnpm@11.1.1 rolldown@1.0.0-beta.38
20
20
 
21
21
  # Copy project files
22
22
  COPY smithy-build.json .
@@ -593,7 +593,7 @@ app.use(express.json());
593
593
 
594
594
  app.post('/mcp', async (req: Request, res: Response) => {
595
595
  try {
596
- const server = createServer();
596
+ const server = await createServer();
597
597
  const transport: StreamableHTTPServerTransport =
598
598
  new StreamableHTTPServerTransport({
599
599
  sessionIdGenerator: undefined,
@@ -682,7 +682,7 @@ import { registerSampleGuidanceResource } from './resources/sample-guidance';
682
682
  /**
683
683
  * Create the MCP Server
684
684
  */
685
- export const createServer = () => {
685
+ export const createServer = async () => {
686
686
  const server = new McpServer({
687
687
  name: 'snapshot-server',
688
688
  version: '1.0.0',
@@ -703,7 +703,8 @@ import { createServer } from './server';
703
703
 
704
704
  export const startMcpServer = async () => {
705
705
  const transport = new StdioServerTransport();
706
- await createServer().connect(transport);
706
+ const server = await createServer();
707
+ await server.connect(transport);
707
708
  console.error('MCP Server listening on STDIO');
708
709
  };
709
710
 
@@ -10,7 +10,7 @@ app.use(express.json());
10
10
 
11
11
  app.post('/mcp', async (req: Request, res: Response) => {
12
12
  try {
13
- const server = createServer();
13
+ const server = await createServer();
14
14
  const transport: StreamableHTTPServerTransport =
15
15
  new StreamableHTTPServerTransport({
16
16
  sessionIdGenerator: undefined,
@@ -5,7 +5,7 @@ import { registerSampleGuidanceResource } from './resources/sample-guidance<% if
5
5
  /**
6
6
  * Create the MCP Server
7
7
  */
8
- export const createServer = () => {
8
+ export const createServer = async () => {
9
9
  const server = new McpServer({
10
10
  name: "<%- name %>",
11
11
  version: "1.0.0"
@@ -4,7 +4,8 @@ import { createServer } from './server<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  export const startMcpServer = async () => {
6
6
  const transport = new StdioServerTransport();
7
- await createServer().connect(transport);
7
+ const server = await createServer();
8
+ await server.connect(transport);
8
9
  console.error('MCP Server listening on STDIO');
9
10
  };
10
11
 
@@ -13,7 +13,7 @@ app.use(express.json());
13
13
 
14
14
  app.post('/mcp', async (req: Request, res: Response) => {
15
15
  try {
16
- const server = createServer();
16
+ const server = await createServer();
17
17
  const transport: StreamableHTTPServerTransport =
18
18
  new StreamableHTTPServerTransport({
19
19
  sessionIdGenerator: undefined,
@@ -207,7 +207,8 @@ import { createServer } from './server';
207
207
 
208
208
  export const startMcpServer = async () => {
209
209
  const transport = new StdioServerTransport();
210
- await createServer().connect(transport);
210
+ const server = await createServer();
211
+ await server.connect(transport);
211
212
  console.error('MCP Server listening on STDIO');
212
213
  };
213
214
 
@@ -265,7 +265,7 @@ export const handler = async () => {
265
265
  exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/src/prisma.ts 1`] = `
266
266
  "import { PrismaMariaDb } from '@prisma/adapter-mariadb';
267
267
  import { Signer } from '@aws-sdk/rds-signer';
268
- import { PrismaClient } from '../generated/prisma/client.js';
268
+ import { Prisma, PrismaClient } from '../generated/prisma/client.js';
269
269
  import {
270
270
  DB_PACKAGE_NAME,
271
271
  LOCAL_DB_HOST,
@@ -276,7 +276,9 @@ import {
276
276
  } from './constants.js';
277
277
  import { getDatabaseConfig } from './utils.js';
278
278
 
279
- export const getPrisma = async (): Promise<PrismaClient> => {
279
+ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
280
+ log: LogOpts[] = ['warn', 'error'] as LogOpts[],
281
+ ): Promise<PrismaClient<LogOpts>> => {
280
282
  if (process.env.SERVE_LOCAL === 'true') {
281
283
  const adapter = new PrismaMariaDb({
282
284
  host: LOCAL_DB_HOST,
@@ -286,7 +288,10 @@ export const getPrisma = async (): Promise<PrismaClient> => {
286
288
  password: LOCAL_DB_PASSWORD,
287
289
  allowPublicKeyRetrieval: true,
288
290
  });
289
- return new PrismaClient({ adapter });
291
+ return new PrismaClient({
292
+ adapter,
293
+ log,
294
+ }) as unknown as PrismaClient<LogOpts>;
290
295
  }
291
296
 
292
297
  const { hostname, port, database, dbUser, region } =
@@ -309,7 +314,10 @@ export const getPrisma = async (): Promise<PrismaClient> => {
309
314
  },
310
315
  });
311
316
 
312
- return new PrismaClient({ adapter });
317
+ return new PrismaClient({
318
+ adapter,
319
+ log,
320
+ }) as unknown as PrismaClient<LogOpts>;
313
321
  };
314
322
  "
315
323
  `;
@@ -4078,8 +4086,8 @@ export const handler = async () => {
4078
4086
  exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/src/prisma.ts 1`] = `
4079
4087
  "import { PrismaPg } from '@prisma/adapter-pg';
4080
4088
  import { Signer } from '@aws-sdk/rds-signer';
4089
+ import { Prisma, PrismaClient } from '../generated/prisma/client.js';
4081
4090
  import { Pool } from 'pg';
4082
- import { PrismaClient } from '../generated/prisma/client.js';
4083
4091
  import {
4084
4092
  DB_PACKAGE_NAME,
4085
4093
  LOCAL_DB_HOST,
@@ -4090,52 +4098,54 @@ import {
4090
4098
  } from './constants.js';
4091
4099
  import { getDatabaseConfig } from './utils.js';
4092
4100
 
4093
- let prismaPromise: Promise<PrismaClient> | undefined;
4094
-
4095
- export const getPrisma = (): Promise<PrismaClient> => {
4096
- prismaPromise ??= (async () => {
4097
- if (process.env.SERVE_LOCAL === 'true') {
4098
- const adapter = new PrismaPg(
4099
- new Pool({
4100
- host: LOCAL_DB_HOST,
4101
- port: LOCAL_DB_PORT,
4102
- database: LOCAL_DB_NAME,
4103
- user: LOCAL_DB_USER,
4104
- password: LOCAL_DB_PASSWORD,
4105
- allowExitOnIdle: true,
4106
- }),
4107
- );
4108
- return new PrismaClient({ adapter });
4109
- }
4110
-
4111
- const { hostname, port, database, dbUser, region } =
4112
- await getDatabaseConfig(DB_PACKAGE_NAME);
4101
+ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
4102
+ log: LogOpts[] = ['warn', 'error'] as LogOpts[],
4103
+ ): Promise<PrismaClient<LogOpts>> => {
4104
+ if (process.env.SERVE_LOCAL === 'true') {
4113
4105
  const adapter = new PrismaPg(
4114
4106
  new Pool({
4115
- host: hostname,
4116
- port,
4117
- database,
4118
- user: dbUser,
4119
- ssl: {
4120
- rejectUnauthorized: true,
4121
- },
4107
+ host: LOCAL_DB_HOST,
4108
+ port: LOCAL_DB_PORT,
4109
+ database: LOCAL_DB_NAME,
4110
+ user: LOCAL_DB_USER,
4111
+ password: LOCAL_DB_PASSWORD,
4122
4112
  allowExitOnIdle: true,
4123
- password: async () => {
4124
- const token = await new Signer({
4125
- hostname,
4126
- port,
4127
- region,
4128
- username: dbUser,
4129
- }).getAuthToken();
4130
- return token;
4131
- },
4132
4113
  }),
4133
4114
  );
4115
+ return new PrismaClient({
4116
+ adapter,
4117
+ log,
4118
+ }) as unknown as PrismaClient<LogOpts>;
4119
+ }
4134
4120
 
4135
- return new PrismaClient({ adapter });
4136
- })();
4121
+ const { hostname, port, database, dbUser, region } =
4122
+ await getDatabaseConfig(DB_PACKAGE_NAME);
4123
+ const adapter = new PrismaPg(
4124
+ new Pool({
4125
+ host: hostname,
4126
+ port,
4127
+ database,
4128
+ user: dbUser,
4129
+ ssl: {
4130
+ rejectUnauthorized: true,
4131
+ },
4132
+ allowExitOnIdle: true,
4133
+ password: async () => {
4134
+ const token = await new Signer({
4135
+ hostname,
4136
+ port,
4137
+ region,
4138
+ username: dbUser,
4139
+ }).getAuthToken();
4140
+ return token;
4141
+ },
4142
+ }),
4143
+ );
4137
4144
 
4138
- return prismaPromise;
4145
+ return new PrismaClient({
4146
+ adapter,
4147
+ log,
4148
+ }) as unknown as PrismaClient<LogOpts>;
4139
4149
  };
4140
4150
  "
4141
4151
  `;
@@ -1,10 +1,8 @@
1
1
  import { <%= prismaAdapterClassName %> } from '<%= prismaAdapterPackage %>';
2
2
  import { Signer } from '@aws-sdk/rds-signer';
3
- <%_ if (engine === 'MySQL') { _%>
4
- import { PrismaClient } from '../generated/prisma/client.js';
5
- <%_ } else { _%>
3
+ import { Prisma, PrismaClient } from '../generated/prisma/client.js';
4
+ <%_ if (engine === 'PostgreSQL') { _%>
6
5
  import { Pool } from 'pg';
7
- import { PrismaClient } from '../generated/prisma/client.js';
8
6
  <%_ } _%>
9
7
  import {
10
8
  DB_PACKAGE_NAME,
@@ -17,7 +15,9 @@ import {
17
15
  import { getDatabaseConfig } from './utils.js';
18
16
  <%_ if (engine === 'MySQL') { _%>
19
17
 
20
- export const getPrisma = async (): Promise<PrismaClient> => {
18
+ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
19
+ log: LogOpts[] = ['warn', 'error'] as LogOpts[],
20
+ ): Promise<PrismaClient<LogOpts>> => {
21
21
  if (process.env.SERVE_LOCAL === 'true') {
22
22
  const adapter = new PrismaMariaDb({
23
23
  host: LOCAL_DB_HOST,
@@ -27,7 +27,10 @@ export const getPrisma = async (): Promise<PrismaClient> => {
27
27
  password: LOCAL_DB_PASSWORD,
28
28
  allowPublicKeyRetrieval: true,
29
29
  });
30
- return new PrismaClient({ adapter });
30
+ return new PrismaClient({
31
+ adapter,
32
+ log,
33
+ }) as unknown as PrismaClient<LogOpts>;
31
34
  }
32
35
 
33
36
  const { hostname, port, database, dbUser, region } =
@@ -50,55 +53,60 @@ export const getPrisma = async (): Promise<PrismaClient> => {
50
53
  },
51
54
  });
52
55
 
53
- return new PrismaClient({ adapter });
56
+ return new PrismaClient({
57
+ adapter,
58
+ log,
59
+ }) as unknown as PrismaClient<LogOpts>;
54
60
  };
55
61
  <%_ } else { _%>
56
62
 
57
- let prismaPromise: Promise<PrismaClient> | undefined;
58
-
59
- export const getPrisma = (): Promise<PrismaClient> => {
60
- prismaPromise ??= (async () => {
61
- if (process.env.SERVE_LOCAL === 'true') {
62
- const adapter = new PrismaPg(
63
- new Pool({
64
- host: LOCAL_DB_HOST,
65
- port: LOCAL_DB_PORT,
66
- database: LOCAL_DB_NAME,
67
- user: LOCAL_DB_USER,
68
- password: LOCAL_DB_PASSWORD,
69
- allowExitOnIdle: true,
70
- }),
71
- );
72
- return new PrismaClient({ adapter });
73
- }
74
-
75
- const { hostname, port, database, dbUser, region } =
76
- await getDatabaseConfig(DB_PACKAGE_NAME);
63
+ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
64
+ log: LogOpts[] = ['warn', 'error'] as LogOpts[],
65
+ ): Promise<PrismaClient<LogOpts>> => {
66
+ if (process.env.SERVE_LOCAL === 'true') {
77
67
  const adapter = new PrismaPg(
78
68
  new Pool({
79
- host: hostname,
80
- port,
81
- database,
82
- user: dbUser,
83
- ssl: {
84
- rejectUnauthorized: true,
85
- },
69
+ host: LOCAL_DB_HOST,
70
+ port: LOCAL_DB_PORT,
71
+ database: LOCAL_DB_NAME,
72
+ user: LOCAL_DB_USER,
73
+ password: LOCAL_DB_PASSWORD,
86
74
  allowExitOnIdle: true,
87
- password: async () => {
88
- const token = await new Signer({
89
- hostname,
90
- port,
91
- region,
92
- username: dbUser,
93
- }).getAuthToken();
94
- return token;
95
- },
96
75
  }),
97
76
  );
77
+ return new PrismaClient({
78
+ adapter,
79
+ log,
80
+ }) as unknown as PrismaClient<LogOpts>;
81
+ }
98
82
 
99
- return new PrismaClient({ adapter });
100
- })();
83
+ const { hostname, port, database, dbUser, region } =
84
+ await getDatabaseConfig(DB_PACKAGE_NAME);
85
+ const adapter = new PrismaPg(
86
+ new Pool({
87
+ host: hostname,
88
+ port,
89
+ database,
90
+ user: dbUser,
91
+ ssl: {
92
+ rejectUnauthorized: true,
93
+ },
94
+ allowExitOnIdle: true,
95
+ password: async () => {
96
+ const token = await new Signer({
97
+ hostname,
98
+ port,
99
+ region,
100
+ username: dbUser,
101
+ }).getAuthToken();
102
+ return token;
103
+ },
104
+ }),
105
+ );
101
106
 
102
- return prismaPromise;
107
+ return new PrismaClient({
108
+ adapter,
109
+ log,
110
+ }) as unknown as PrismaClient<LogOpts>;
103
111
  };
104
112
  <%_ } _%>
@@ -155,6 +155,9 @@ const tsRdbGenerator = async (tree, options) => {
155
155
  }
156
156
  (0, nx_1.addDependencyToTargetIfNotPresent)(projectConfig, 'compile', 'generate');
157
157
  (0, devkit_1.updateProjectConfiguration)(tree, fullyQualifiedName, projectConfig);
158
+ (0, nx_1.addGeneratorMetadata)(tree, fullyQualifiedName, exports.TS_RDB_GENERATOR_INFO, {
159
+ engine: options.engine,
160
+ });
158
161
  await (0, shared_constructs_1.sharedConstructsGenerator)(tree, { iacProvider });
159
162
  await (0, rdb_constructs_1.addRdbInfra)(tree, {
160
163
  iacProvider,