@aws/nx-plugin 0.113.0 → 0.114.1

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/generators.json +33 -1
  2. package/package.json +1 -1
  3. package/src/connection/generator.d.ts +2 -2
  4. package/src/connection/generator.js +19 -0
  5. package/src/connection/generator.js.map +1 -1
  6. package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +6 -6
  7. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  8. package/src/py/strands-agent/files/ag-ui/main.py.template +17 -0
  9. package/src/smithy/project/__snapshots__/generator.spec.ts.snap +2 -2
  10. package/src/smithy/project/files/build.Dockerfile.template +1 -1
  11. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +4 -4
  12. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +6 -6
  13. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  14. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +4 -3
  15. package/src/ts/mcp-server/files/http.ts.template +1 -1
  16. package/src/ts/mcp-server/files/server.ts.template +1 -1
  17. package/src/ts/mcp-server/files/stdio.ts.template +2 -1
  18. package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +3 -2
  19. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +54 -44
  20. package/src/ts/rdb/files/src/prisma.ts.template +54 -46
  21. package/src/ts/rdb/generator.js +3 -0
  22. package/src/ts/rdb/generator.js.map +1 -1
  23. package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +117 -0
  24. package/src/ts/rdb/mcp-server-connection/generator.d.ts +10 -0
  25. package/src/ts/rdb/mcp-server-connection/generator.js +59 -0
  26. package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -0
  27. package/src/ts/rdb/mcp-server-connection/schema.d.ts +14 -0
  28. package/src/ts/rdb/mcp-server-connection/schema.json +22 -0
  29. package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +286 -0
  30. package/src/ts/rdb/smithy-connection/generator.d.ts +10 -0
  31. package/src/ts/rdb/smithy-connection/generator.js +72 -0
  32. package/src/ts/rdb/smithy-connection/generator.js.map +1 -0
  33. package/src/ts/rdb/smithy-connection/schema.d.ts +12 -0
  34. package/src/ts/rdb/smithy-connection/schema.json +18 -0
  35. package/src/ts/rdb/strands-agent-connection/__snapshots__/generator.spec.ts.snap +183 -0
  36. package/src/ts/rdb/strands-agent-connection/generator.d.ts +10 -0
  37. package/src/ts/rdb/strands-agent-connection/generator.js +65 -0
  38. package/src/ts/rdb/strands-agent-connection/generator.js.map +1 -0
  39. package/src/ts/rdb/strands-agent-connection/schema.d.ts +14 -0
  40. package/src/ts/rdb/strands-agent-connection/schema.json +22 -0
  41. package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +75 -0
  42. package/src/ts/rdb/trpc-connection/files/src/middleware/__rdbNameKebab__.ts.template +32 -0
  43. package/src/ts/rdb/trpc-connection/generator.d.ts +10 -0
  44. package/src/ts/rdb/trpc-connection/generator.js +41 -0
  45. package/src/ts/rdb/trpc-connection/generator.js.map +1 -0
  46. package/src/ts/rdb/trpc-connection/schema.d.ts +12 -0
  47. package/src/ts/rdb/trpc-connection/schema.json +18 -0
  48. package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +4 -13
  49. package/src/ts/strands-agent/files/http/init.ts.template +1 -12
  50. package/src/ts/strands-agent/files/http/router.ts.template +3 -1
  51. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +1 -1
  52. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +1 -1
  53. package/src/utils/ast.js +9 -2
  54. package/src/utils/ast.js.map +1 -1
  55. package/src/utils/function-constructs/files/terraform/app/lambda-functions/__functionNameKebabCase__/__functionNameKebabCase__.tf.template +1 -1
  56. package/src/utils/pnpm-workspace.d.ts +11 -0
  57. package/src/utils/pnpm-workspace.js +28 -1
  58. package/src/utils/pnpm-workspace.js.map +1 -1
  59. package/src/utils/shared-shadcn.js +2 -19
  60. package/src/utils/shared-shadcn.js.map +1 -1
@@ -0,0 +1,286 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`ts#rdb smithy-connection generator > should add rdb serve-local dependency to smithy backend serve-local 1`] = `
4
+ {
5
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
6
+ "name": "api",
7
+ "root": "packages/api",
8
+ "targets": {
9
+ "serve-local": {
10
+ "continuous": true,
11
+ "dependsOn": [
12
+ {
13
+ "projects": [
14
+ "db",
15
+ ],
16
+ "target": "serve-local",
17
+ },
18
+ ],
19
+ "executor": "nx:run-commands",
20
+ },
21
+ },
22
+ }
23
+ `;
24
+
25
+ exports[`ts#rdb smithy-connection generator > should be idempotent across context.ts, handler.ts, and local-server.ts 1`] = `
26
+ "import { getPrisma as getDb } from 'db';
27
+ import { Logger } from '@aws-lambda-powertools/logger';
28
+ import { Metrics } from '@aws-lambda-powertools/metrics';
29
+ import { Tracer } from '@aws-lambda-powertools/tracer';
30
+
31
+ export interface ServiceContext {
32
+ tracer: Tracer;
33
+ logger: Logger;
34
+ metrics: Metrics;
35
+ db: Awaited<ReturnType<typeof getDb>>;
36
+ }
37
+ "
38
+ `;
39
+
40
+ exports[`ts#rdb smithy-connection generator > should be idempotent across context.ts, handler.ts, and local-server.ts 2`] = `
41
+ "import { getPrisma as getDb } from 'db';
42
+ import {
43
+ convertEvent,
44
+ convertVersion1Response,
45
+ } from '@aws-smithy/server-apigateway';
46
+ import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
47
+ import { Tracer } from '@aws-lambda-powertools/tracer';
48
+ import { Logger } from '@aws-lambda-powertools/logger';
49
+ import { Metrics } from '@aws-lambda-powertools/metrics';
50
+ import { Service } from './service.js';
51
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
52
+
53
+ const tracer = new Tracer();
54
+ const logger = new Logger();
55
+ const metrics = new Metrics();
56
+
57
+ const serviceHandler = getMyApiServiceHandler(Service);
58
+
59
+ export const lambdaHandler = async (
60
+ event: APIGatewayProxyEvent,
61
+ ): Promise<APIGatewayProxyResult> => {
62
+ const httpRequest = convertEvent(event);
63
+ const db = await getDb();
64
+ const httpResponse = await serviceHandler.handle(httpRequest, {
65
+ tracer,
66
+ logger,
67
+ metrics,
68
+ db,
69
+ });
70
+ return convertVersion1Response(httpResponse);
71
+ };
72
+ "
73
+ `;
74
+
75
+ exports[`ts#rdb smithy-connection generator > should be idempotent across context.ts, handler.ts, and local-server.ts 3`] = `
76
+ "import { getPrisma as getDb } from 'db';
77
+ import { IncomingMessage, ServerResponse, createServer } from 'http';
78
+ import { convertRequest, writeResponse } from '@aws-smithy/server-node';
79
+ import { Tracer } from '@aws-lambda-powertools/tracer';
80
+ import { Logger } from '@aws-lambda-powertools/logger';
81
+ import { Metrics } from '@aws-lambda-powertools/metrics';
82
+ import { Service } from './service.js';
83
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
84
+
85
+ const tracer = new Tracer();
86
+ const logger = new Logger();
87
+ const metrics = new Metrics();
88
+
89
+ const serviceHandler = getMyApiServiceHandler(Service);
90
+
91
+ const server = createServer(async function (
92
+ req: IncomingMessage,
93
+ res: ServerResponse<IncomingMessage> & { req: IncomingMessage },
94
+ ) {
95
+ const httpRequest = convertRequest(req);
96
+ const db = await getDb();
97
+ const httpResponse = await serviceHandler.handle(httpRequest, {
98
+ tracer,
99
+ logger,
100
+ metrics,
101
+ db,
102
+ });
103
+ return writeResponse(httpResponse, res);
104
+ });
105
+
106
+ server.listen(3000);
107
+ "
108
+ `;
109
+
110
+ exports[`ts#rdb smithy-connection generator > should inject into context.ts, handler.ts, and local-server.ts 1`] = `
111
+ "import { getPrisma as getDb } from 'db';
112
+ import { Logger } from '@aws-lambda-powertools/logger';
113
+ import { Metrics } from '@aws-lambda-powertools/metrics';
114
+ import { Tracer } from '@aws-lambda-powertools/tracer';
115
+
116
+ export interface ServiceContext {
117
+ tracer: Tracer;
118
+ logger: Logger;
119
+ metrics: Metrics;
120
+ db: Awaited<ReturnType<typeof getDb>>;
121
+ }
122
+ "
123
+ `;
124
+
125
+ exports[`ts#rdb smithy-connection generator > should inject into context.ts, handler.ts, and local-server.ts 2`] = `
126
+ "import { getPrisma as getDb } from 'db';
127
+ import {
128
+ convertEvent,
129
+ convertVersion1Response,
130
+ } from '@aws-smithy/server-apigateway';
131
+ import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
132
+ import { Tracer } from '@aws-lambda-powertools/tracer';
133
+ import { Logger } from '@aws-lambda-powertools/logger';
134
+ import { Metrics } from '@aws-lambda-powertools/metrics';
135
+ import { Service } from './service.js';
136
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
137
+
138
+ const tracer = new Tracer();
139
+ const logger = new Logger();
140
+ const metrics = new Metrics();
141
+
142
+ const serviceHandler = getMyApiServiceHandler(Service);
143
+
144
+ export const lambdaHandler = async (
145
+ event: APIGatewayProxyEvent,
146
+ ): Promise<APIGatewayProxyResult> => {
147
+ const httpRequest = convertEvent(event);
148
+ const db = await getDb();
149
+ const httpResponse = await serviceHandler.handle(httpRequest, {
150
+ tracer,
151
+ logger,
152
+ metrics,
153
+ db,
154
+ });
155
+ return convertVersion1Response(httpResponse);
156
+ };
157
+ "
158
+ `;
159
+
160
+ exports[`ts#rdb smithy-connection generator > should inject into context.ts, handler.ts, and local-server.ts 3`] = `
161
+ "import { getPrisma as getDb } from 'db';
162
+ import { IncomingMessage, ServerResponse, createServer } from 'http';
163
+ import { convertRequest, writeResponse } from '@aws-smithy/server-node';
164
+ import { Tracer } from '@aws-lambda-powertools/tracer';
165
+ import { Logger } from '@aws-lambda-powertools/logger';
166
+ import { Metrics } from '@aws-lambda-powertools/metrics';
167
+ import { Service } from './service.js';
168
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
169
+
170
+ const tracer = new Tracer();
171
+ const logger = new Logger();
172
+ const metrics = new Metrics();
173
+
174
+ const serviceHandler = getMyApiServiceHandler(Service);
175
+
176
+ const server = createServer(async function (
177
+ req: IncomingMessage,
178
+ res: ServerResponse<IncomingMessage> & { req: IncomingMessage },
179
+ ) {
180
+ const httpRequest = convertRequest(req);
181
+ const db = await getDb();
182
+ const httpResponse = await serviceHandler.handle(httpRequest, {
183
+ tracer,
184
+ logger,
185
+ metrics,
186
+ db,
187
+ });
188
+ return writeResponse(httpResponse, res);
189
+ });
190
+
191
+ server.listen(3000);
192
+ "
193
+ `;
194
+
195
+ exports[`ts#rdb smithy-connection generator > should support multiple rdb connections 1`] = `
196
+ "import { getPrisma as getMysqlDb } from 'mysql-db';
197
+ import { getPrisma as getPostgresDb } from 'postgres-db';
198
+ import { Logger } from '@aws-lambda-powertools/logger';
199
+ import { Metrics } from '@aws-lambda-powertools/metrics';
200
+ import { Tracer } from '@aws-lambda-powertools/tracer';
201
+
202
+ export interface ServiceContext {
203
+ tracer: Tracer;
204
+ logger: Logger;
205
+ metrics: Metrics;
206
+ postgresDb: Awaited<ReturnType<typeof getPostgresDb>>;
207
+ mysqlDb: Awaited<ReturnType<typeof getMysqlDb>>;
208
+ }
209
+ "
210
+ `;
211
+
212
+ exports[`ts#rdb smithy-connection generator > should support multiple rdb connections 2`] = `
213
+ "import { getPrisma as getMysqlDb } from 'mysql-db';
214
+ import { getPrisma as getPostgresDb } from 'postgres-db';
215
+ import {
216
+ convertEvent,
217
+ convertVersion1Response,
218
+ } from '@aws-smithy/server-apigateway';
219
+ import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
220
+ import { Tracer } from '@aws-lambda-powertools/tracer';
221
+ import { Logger } from '@aws-lambda-powertools/logger';
222
+ import { Metrics } from '@aws-lambda-powertools/metrics';
223
+ import { Service } from './service.js';
224
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
225
+
226
+ const tracer = new Tracer();
227
+ const logger = new Logger();
228
+ const metrics = new Metrics();
229
+
230
+ const serviceHandler = getMyApiServiceHandler(Service);
231
+
232
+ export const lambdaHandler = async (
233
+ event: APIGatewayProxyEvent,
234
+ ): Promise<APIGatewayProxyResult> => {
235
+ const httpRequest = convertEvent(event);
236
+ const postgresDb = await getPostgresDb();
237
+ const mysqlDb = await getMysqlDb();
238
+ const httpResponse = await serviceHandler.handle(httpRequest, {
239
+ tracer,
240
+ logger,
241
+ metrics,
242
+ postgresDb,
243
+ mysqlDb,
244
+ });
245
+ return convertVersion1Response(httpResponse);
246
+ };
247
+ "
248
+ `;
249
+
250
+ exports[`ts#rdb smithy-connection generator > should support multiple rdb connections 3`] = `
251
+ "import { getPrisma as getMysqlDb } from 'mysql-db';
252
+ import { getPrisma as getPostgresDb } from 'postgres-db';
253
+ import { IncomingMessage, ServerResponse, createServer } from 'http';
254
+ import { convertRequest, writeResponse } from '@aws-smithy/server-node';
255
+ import { Tracer } from '@aws-lambda-powertools/tracer';
256
+ import { Logger } from '@aws-lambda-powertools/logger';
257
+ import { Metrics } from '@aws-lambda-powertools/metrics';
258
+ import { Service } from './service.js';
259
+ import { getMyApiServiceHandler } from './generated/ssdk/index.js';
260
+
261
+ const tracer = new Tracer();
262
+ const logger = new Logger();
263
+ const metrics = new Metrics();
264
+
265
+ const serviceHandler = getMyApiServiceHandler(Service);
266
+
267
+ const server = createServer(async function (
268
+ req: IncomingMessage,
269
+ res: ServerResponse<IncomingMessage> & { req: IncomingMessage },
270
+ ) {
271
+ const httpRequest = convertRequest(req);
272
+ const postgresDb = await getPostgresDb();
273
+ const mysqlDb = await getMysqlDb();
274
+ const httpResponse = await serviceHandler.handle(httpRequest, {
275
+ tracer,
276
+ logger,
277
+ metrics,
278
+ postgresDb,
279
+ mysqlDb,
280
+ });
281
+ return writeResponse(httpResponse, res);
282
+ });
283
+
284
+ server.listen(3000);
285
+ "
286
+ `;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { Tree } from '@nx/devkit';
6
+ import { TsRdbSmithyConnectionGeneratorSchema } from './schema';
7
+ import { NxGeneratorInfo } from '../../../utils/nx';
8
+ export declare const TS_RDB_SMITHY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
9
+ export declare const tsRdbSmithyConnectionGenerator: (tree: Tree, options: TsRdbSmithyConnectionGeneratorSchema) => Promise<void>;
10
+ export default tsRdbSmithyConnectionGenerator;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsRdbSmithyConnectionGenerator = exports.TS_RDB_SMITHY_CONNECTION_GENERATOR_INFO = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ */
9
+ const devkit_1 = require("@nx/devkit");
10
+ const nx_1 = require("../../../utils/nx");
11
+ const metrics_1 = require("../../../utils/metrics");
12
+ const format_1 = require("../../../utils/format");
13
+ const names_1 = require("../../../utils/names");
14
+ const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
15
+ const npm_scope_1 = require("../../../utils/npm-scope");
16
+ const ast_1 = require("../../../utils/ast");
17
+ exports.TS_RDB_SMITHY_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
18
+ const tsRdbSmithyConnectionGenerator = async (tree, options) => {
19
+ const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
20
+ const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
21
+ if (sourceProject.targets?.['serve-local']) {
22
+ (0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, 'serve-local', {
23
+ projects: [targetProject.name],
24
+ target: 'serve-local',
25
+ });
26
+ (0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
27
+ }
28
+ const rdbBaseName = targetProject.name.split('/').pop();
29
+ const rdbNameCamel = (0, lodash_camelcase_1.default)(rdbBaseName);
30
+ const rdbNamePascal = (0, names_1.pascalCase)(rdbBaseName);
31
+ const rdbPackageAlias = (0, npm_scope_1.toScopeAlias)(targetProject.name);
32
+ const getterAlias = `getPrisma as get${rdbNamePascal}`;
33
+ const contextPath = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src/context.ts');
34
+ const handlerPath = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src/handler.ts');
35
+ const localServerPath = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src/local-server.ts');
36
+ if (tree.exists(contextPath)) {
37
+ await (0, ast_1.addDestructuredImport)(tree, contextPath, [getterAlias], rdbPackageAlias);
38
+ await (0, ast_1.applyGritQL)(tree, contextPath, `\`interface ServiceContext { $members }\` where {
39
+ $members <: not some \`${rdbNameCamel}: $_\`,
40
+ $members += \`\n ${rdbNameCamel}: Awaited<ReturnType<typeof get${rdbNamePascal}>>\`
41
+ }`);
42
+ }
43
+ if (tree.exists(handlerPath)) {
44
+ await (0, ast_1.addDestructuredImport)(tree, handlerPath, [getterAlias], rdbPackageAlias);
45
+ const alreadyHasDecl = await (0, ast_1.matchGritQL)(tree, handlerPath, `\`const ${rdbNameCamel} = await get${rdbNamePascal}()\``);
46
+ if (!alreadyHasDecl) {
47
+ await (0, ast_1.applyGritQL)(tree, handlerPath, `\`const httpResponse = await serviceHandler.handle($req, $ctx)\` => \`const ${rdbNameCamel} = await get${rdbNamePascal}();\n const httpResponse = await serviceHandler.handle($req, $ctx)\``);
48
+ }
49
+ await (0, ast_1.applyGritQL)(tree, handlerPath, `\`serviceHandler.handle($req, { $props })\` where {
50
+ $props <: not some \`${rdbNameCamel}\`,
51
+ $props += \`\n ${rdbNameCamel}\`
52
+ }`);
53
+ }
54
+ if (tree.exists(localServerPath)) {
55
+ await (0, ast_1.addDestructuredImport)(tree, localServerPath, [getterAlias], rdbPackageAlias);
56
+ const alreadyHasDeclLocal = await (0, ast_1.matchGritQL)(tree, localServerPath, `\`const ${rdbNameCamel} = await get${rdbNamePascal}()\``);
57
+ if (!alreadyHasDeclLocal) {
58
+ await (0, ast_1.applyGritQL)(tree, localServerPath, `\`const httpResponse = await serviceHandler.handle($req, $ctx)\` => \`const ${rdbNameCamel} = await get${rdbNamePascal}();\n const httpResponse = await serviceHandler.handle($req, $ctx)\``);
59
+ }
60
+ await (0, ast_1.applyGritQL)(tree, localServerPath, `\`serviceHandler.handle($req, { $props })\` where {
61
+ $props <: not some \`${rdbNameCamel}\`,
62
+ $props += \`\n ${rdbNameCamel}\`
63
+ }`);
64
+ }
65
+ await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
66
+ exports.TS_RDB_SMITHY_CONNECTION_GENERATOR_INFO,
67
+ ]);
68
+ await (0, format_1.formatFilesInSubtree)(tree);
69
+ };
70
+ exports.tsRdbSmithyConnectionGenerator = tsRdbSmithyConnectionGenerator;
71
+ exports.default = exports.tsRdbSmithyConnectionGenerator;
72
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/rdb/smithy-connection/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAIoB;AAEpB,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAAkD;AAClD,gFAAyC;AACzC,wDAAwD;AACxD,4CAI4B;AAEf,QAAA,uCAAuC,GAClD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,8BAA8B,GAAG,KAAK,EACjD,IAAU,EACV,OAA6C,EAC9B,EAAE;IACjB,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB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AC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * TypeScript types for options defined in schema.json
8
+ */
9
+ export interface TsRdbSmithyConnectionGeneratorSchema {
10
+ sourceProject: string;
11
+ targetProject: string;
12
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "ts#rdb#smithy-connection",
4
+ "title": "ts#rdb#smithy-connection",
5
+ "description": "Connect a Smithy backend to a ts#rdb project",
6
+ "type": "object",
7
+ "properties": {
8
+ "sourceProject": {
9
+ "type": "string",
10
+ "description": "The TypeScript project to connect from"
11
+ },
12
+ "targetProject": {
13
+ "type": "string",
14
+ "description": "The ts#rdb project to connect to"
15
+ }
16
+ },
17
+ "required": ["sourceProject", "targetProject"]
18
+ }
@@ -0,0 +1,183 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`ts#rdb strands-agent-connection generator > should add rdb serve-local dependency to the agent prefixed serve-local 1`] = `
4
+ {
5
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
6
+ "metadata": {
7
+ "components": [
8
+ {
9
+ "generator": "ts#strands-agent",
10
+ "name": "my-agent",
11
+ "path": "src/my-agent",
12
+ "protocol": "HTTP",
13
+ },
14
+ ],
15
+ },
16
+ "name": "my-service",
17
+ "root": "packages/my-service",
18
+ "targets": {
19
+ "my-agent-serve-local": {
20
+ "continuous": true,
21
+ "dependsOn": [
22
+ {
23
+ "projects": [
24
+ "db",
25
+ ],
26
+ "target": "serve-local",
27
+ },
28
+ ],
29
+ "executor": "nx:run-commands",
30
+ },
31
+ },
32
+ }
33
+ `;
34
+
35
+ exports[`ts#rdb strands-agent-connection generator > should be idempotent for A2A agent.ts injection 1`] = `
36
+ "import { getPrisma as getDb } from 'db';
37
+ import { Agent, tool } from '@strands-agents/sdk';
38
+ import { z } from 'zod';
39
+
40
+ const multiply = tool({
41
+ name: 'Multiply',
42
+ description: 'Multiply two numbers',
43
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
44
+ callback: ({ a, b }) => a * b,
45
+ });
46
+
47
+ export const getAgent = async () => {
48
+ const db = await getDb();
49
+ db.$on('error', console.error);
50
+ return new Agent({
51
+ systemPrompt: 'You are a helpful assistant.',
52
+ tools: [multiply],
53
+ });
54
+ };
55
+ "
56
+ `;
57
+
58
+ exports[`ts#rdb strands-agent-connection generator > should be idempotent for agent.ts injection 1`] = `
59
+ "import { getPrisma as getDb } from 'db';
60
+ import { Agent, tool } from '@strands-agents/sdk';
61
+ import { z } from 'zod';
62
+
63
+ const multiply = tool({
64
+ name: 'Multiply',
65
+ description: 'Multiply two numbers',
66
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
67
+ callback: ({ a, b }) => a * b,
68
+ });
69
+
70
+ export const getAgent = async () => {
71
+ const db = await getDb();
72
+ db.$on('error', console.error);
73
+ return new Agent({
74
+ systemPrompt: 'You are a helpful assistant.',
75
+ tools: [multiply],
76
+ });
77
+ };
78
+ "
79
+ `;
80
+
81
+ exports[`ts#rdb strands-agent-connection generator > should fall back to agent-serve-local when no component name 1`] = `
82
+ {
83
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
84
+ "metadata": {
85
+ "components": [
86
+ {
87
+ "generator": "ts#strands-agent",
88
+ "name": "agent",
89
+ "path": "src/agent",
90
+ "protocol": "HTTP",
91
+ },
92
+ ],
93
+ },
94
+ "name": "my-service",
95
+ "root": "packages/my-service",
96
+ "targets": {
97
+ "agent-serve-local": {
98
+ "continuous": true,
99
+ "dependsOn": [
100
+ {
101
+ "projects": [
102
+ "db",
103
+ ],
104
+ "target": "serve-local",
105
+ },
106
+ ],
107
+ "executor": "nx:run-commands",
108
+ },
109
+ },
110
+ }
111
+ `;
112
+
113
+ exports[`ts#rdb strands-agent-connection generator > should inject db into agent.ts 1`] = `
114
+ "import { getPrisma as getDb } from 'db';
115
+ import { Agent, tool } from '@strands-agents/sdk';
116
+ import { z } from 'zod';
117
+
118
+ const multiply = tool({
119
+ name: 'Multiply',
120
+ description: 'Multiply two numbers',
121
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
122
+ callback: ({ a, b }) => a * b,
123
+ });
124
+
125
+ export const getAgent = async () => {
126
+ const db = await getDb();
127
+ db.$on('error', console.error);
128
+ return new Agent({
129
+ systemPrompt: 'You are a helpful assistant.',
130
+ tools: [multiply],
131
+ });
132
+ };
133
+ "
134
+ `;
135
+
136
+ exports[`ts#rdb strands-agent-connection generator > should inject db into agent.ts for A2A 1`] = `
137
+ "import { getPrisma as getDb } from 'db';
138
+ import { Agent, tool } from '@strands-agents/sdk';
139
+ import { z } from 'zod';
140
+
141
+ const multiply = tool({
142
+ name: 'Multiply',
143
+ description: 'Multiply two numbers',
144
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
145
+ callback: ({ a, b }) => a * b,
146
+ });
147
+
148
+ export const getAgent = async () => {
149
+ const db = await getDb();
150
+ db.$on('error', console.error);
151
+ return new Agent({
152
+ systemPrompt: 'You are a helpful assistant.',
153
+ tools: [multiply],
154
+ });
155
+ };
156
+ "
157
+ `;
158
+
159
+ exports[`ts#rdb strands-agent-connection generator > should support multiple rdb connections in agent.ts 1`] = `
160
+ "import { getPrisma as getMysqlDb } from 'mysql-db';
161
+ import { getPrisma as getPostgresDb } from 'postgres-db';
162
+ import { Agent, tool } from '@strands-agents/sdk';
163
+ import { z } from 'zod';
164
+
165
+ const multiply = tool({
166
+ name: 'Multiply',
167
+ description: 'Multiply two numbers',
168
+ inputSchema: z.object({ a: z.number(), b: z.number() }),
169
+ callback: ({ a, b }) => a * b,
170
+ });
171
+
172
+ export const getAgent = async () => {
173
+ const mysqlDb = await getMysqlDb();
174
+ mysqlDb.$on('error', console.error);
175
+ const postgresDb = await getPostgresDb();
176
+ postgresDb.$on('error', console.error);
177
+ return new Agent({
178
+ systemPrompt: 'You are a helpful assistant.',
179
+ tools: [multiply],
180
+ });
181
+ };
182
+ "
183
+ `;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { Tree } from '@nx/devkit';
6
+ import { TsRdbStrandsAgentConnectionGeneratorSchema } from './schema';
7
+ import { NxGeneratorInfo } from '../../../utils/nx';
8
+ export declare const TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
9
+ export declare const tsRdbStrandsAgentConnectionGenerator: (tree: Tree, options: TsRdbStrandsAgentConnectionGeneratorSchema) => Promise<void>;
10
+ export default tsRdbStrandsAgentConnectionGenerator;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsRdbStrandsAgentConnectionGenerator = exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ */
9
+ const devkit_1 = require("@nx/devkit");
10
+ const nx_1 = require("../../../utils/nx");
11
+ const metrics_1 = require("../../../utils/metrics");
12
+ const format_1 = require("../../../utils/format");
13
+ const names_1 = require("../../../utils/names");
14
+ const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
15
+ const npm_scope_1 = require("../../../utils/npm-scope");
16
+ const ast_1 = require("../../../utils/ast");
17
+ exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
18
+ const tsRdbStrandsAgentConnectionGenerator = async (tree, options) => {
19
+ const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
20
+ const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
21
+ const agentName = options.sourceComponent?.name ?? 'agent';
22
+ const serveLocalTarget = `${agentName}-serve-local`;
23
+ if (sourceProject.targets?.[serveLocalTarget]) {
24
+ (0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, serveLocalTarget, {
25
+ projects: [targetProject.name],
26
+ target: 'serve-local',
27
+ });
28
+ (0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
29
+ }
30
+ const rdbBaseName = targetProject.name.split('/').pop();
31
+ const rdbNameCamel = (0, lodash_camelcase_1.default)(rdbBaseName);
32
+ const rdbNamePascal = (0, names_1.pascalCase)(rdbBaseName);
33
+ const rdbPackageAlias = (0, npm_scope_1.toScopeAlias)(targetProject.name);
34
+ const getterAlias = `getPrisma as get${rdbNamePascal}`;
35
+ const agentSourceDir = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src', agentName);
36
+ const agentPath = (0, devkit_1.joinPathFragments)(agentSourceDir, 'agent.ts');
37
+ if (tree.exists(agentPath)) {
38
+ await (0, ast_1.addDestructuredImport)(tree, agentPath, [getterAlias], rdbPackageAlias);
39
+ // Block body form: export const getAgent = async () => { ... }
40
+ await (0, ast_1.applyGritQL)(tree, agentPath, `\`export const getAgent = async () => { $body }\` => raw\`export const getAgent = async () => {
41
+ const ${rdbNameCamel} = await get${rdbNamePascal}();
42
+ $body
43
+ }\` where { $body <: not some \`const ${rdbNameCamel} = await get${rdbNamePascal}()\` }`);
44
+ // Expression body form: export const getAgent = async () => expr
45
+ await (0, ast_1.applyGritQL)(tree, agentPath, `\`export const getAgent = async () => $expr\` => raw\`export const getAgent = async () => {
46
+ const ${rdbNameCamel} = await get${rdbNamePascal}();
47
+ return $expr;
48
+ }\` where { $expr <: not \`{ $_ }\` }`);
49
+ // Add $on error handler after the db declaration.
50
+ // Done via string replacement because GritQL treats $on as a metavariable.
51
+ const dbDecl = `const ${rdbNameCamel} = await get${rdbNamePascal}();`;
52
+ const onCall = `${rdbNameCamel}.$on('error', console.error);`;
53
+ const content = tree.read(agentPath, 'utf-8');
54
+ if (content.includes(dbDecl) && !content.includes(`${rdbNameCamel}.$on`)) {
55
+ tree.write(agentPath, content.replace(dbDecl, `${dbDecl}\n ${onCall}`));
56
+ }
57
+ }
58
+ await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
59
+ exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO,
60
+ ]);
61
+ await (0, format_1.formatFilesInSubtree)(tree);
62
+ };
63
+ exports.tsRdbStrandsAgentConnectionGenerator = tsRdbStrandsAgentConnectionGenerator;
64
+ exports.default = exports.tsRdbStrandsAgentConnectionGenerator;
65
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/rdb/strands-agent-connection/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAIoB;AAEpB,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAAkD;AAClD,gFAAyC;AACzC,wDAAwD;AACxD,4CAAwE;AAE3D,QAAA,8CAA8C,GACzD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,oCAAoC,GAAG,KAAK,EACvD,IAAU,EACV,OAAmD,EACpC,EAAE;IACjB,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CAAC,eAAe,EAAE,IAAI,IAAI,OAAO,CAAC;IAC3D,MAAM,gBAAgB,GAAG,GAAG,SAAS,cAAc,CAAC;IAEpD,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9C,IAAA,sCAAiC,EAAC,aAAa,EAAE,gBAAgB,EAAE;YACjE,QAAQ,EAAE,CAAC,aAAa,CAAC,I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