@aws/nx-plugin 1.0.0-rc.54 → 1.0.0-rc.55
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.
- package/migrations.json +45 -0
- package/package.json +1 -1
- package/src/agentcore-gateway/gateway-connection/generator.js +3 -1
- package/src/agentcore-gateway/gateway-connection/generator.js.map +1 -1
- package/src/agentcore-gateway/generator.d.ts +49 -1
- package/src/agentcore-gateway/generator.js +55 -22
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/agentcore-gateway/mcp-connection/generator.js +3 -1
- package/src/agentcore-gateway/mcp-connection/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/infra/app/generator.d.ts +43 -0
- package/src/infra/app/generator.js +47 -18
- package/src/infra/app/generator.js.map +1 -1
- package/src/init/generator.d.ts +13 -0
- package/src/init/generator.js +14 -3
- package/src/init/generator.js.map +1 -1
- package/src/migrations/latest/backfill-generator-metadata/migration.d.ts +96 -0
- package/src/migrations/latest/backfill-generator-metadata/migration.js +670 -0
- package/src/migrations/latest/backfill-generator-metadata/migration.js.map +1 -0
- package/src/preset/generator.d.ts +13 -0
- package/src/preset/generator.js +12 -3
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/a2a-connection/generator.d.ts +24 -0
- package/src/py/agent/a2a-connection/generator.js +49 -20
- package/src/py/agent/a2a-connection/generator.js.map +1 -1
- package/src/py/agent/gateway-connection/generator.d.ts +23 -0
- package/src/py/agent/gateway-connection/generator.js +45 -11
- package/src/py/agent/gateway-connection/generator.js.map +1 -1
- package/src/py/agent/generator.d.ts +146 -1
- package/src/py/agent/generator.js +173 -76
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/mcp-connection/generator.d.ts +23 -0
- package/src/py/agent/mcp-connection/generator.js +45 -11
- package/src/py/agent/mcp-connection/generator.js.map +1 -1
- package/src/py/agent/react-connection/generator.d.ts +146 -0
- package/src/py/agent/react-connection/generator.js +27 -4
- package/src/py/agent/react-connection/generator.js.map +1 -1
- package/src/py/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/dynamodb/agent-connection/generator.js +7 -1
- package/src/py/dynamodb/agent-connection/generator.js.map +1 -1
- package/src/py/dynamodb/fast-api-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/py/dynamodb/fast-api-connection/generator.js +3 -1
- package/src/py/dynamodb/fast-api-connection/generator.js.map +1 -1
- package/src/py/dynamodb/generator.d.ts +29 -0
- package/src/py/dynamodb/generator.js +32 -12
- package/src/py/dynamodb/generator.js.map +1 -1
- package/src/py/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/dynamodb/mcp-server-connection/generator.js +7 -1
- package/src/py/dynamodb/mcp-server-connection/generator.js.map +1 -1
- package/src/py/fast-api/generator.d.ts +63 -0
- package/src/py/fast-api/generator.js +58 -23
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/generator.d.ts +16 -1
- package/src/py/fast-api/react/generator.js +15 -3
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/lambda-function/generator.d.ts +21 -0
- package/src/py/lambda-function/generator.js +29 -10
- package/src/py/lambda-function/generator.js.map +1 -1
- package/src/py/mcp-server/generator.d.ts +60 -0
- package/src/py/mcp-server/generator.js +62 -25
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/project/generator.d.ts +13 -0
- package/src/py/project/generator.js +29 -10
- package/src/py/project/generator.js.map +1 -1
- package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +19 -0
- package/src/py/rdb/agent-connection/generator.js +7 -1
- package/src/py/rdb/agent-connection/generator.js.map +1 -1
- package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +7 -0
- package/src/py/rdb/fast-api-connection/generator.js +3 -1
- package/src/py/rdb/fast-api-connection/generator.js.map +1 -1
- package/src/py/rdb/generator.d.ts +89 -0
- package/src/py/rdb/generator.js +88 -40
- package/src/py/rdb/generator.js.map +1 -1
- package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/py/rdb/mcp-server-connection/generator.js +7 -1
- package/src/py/rdb/mcp-server-connection/generator.js.map +1 -1
- package/src/smithy/project/generator.d.ts +7 -0
- package/src/smithy/project/generator.js +8 -2
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/react-connection/generator.d.ts +15 -0
- package/src/smithy/react-connection/generator.js +17 -3
- package/src/smithy/react-connection/generator.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/smithy/ts/api/generator.d.ts +79 -0
- package/src/smithy/ts/api/generator.js +77 -33
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/terraform/project/generator.d.ts +50 -0
- package/src/terraform/project/generator.js +63 -17
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/generator.d.ts +84 -0
- package/src/trpc/backend/generator.js +98 -38
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/react/generator.d.ts +37 -0
- package/src/trpc/react/generator.js +63 -26
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/agent/a2a-connection/generator.d.ts +46 -0
- package/src/ts/agent/a2a-connection/generator.js +53 -16
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/gateway-connection/generator.d.ts +37 -0
- package/src/ts/agent/gateway-connection/generator.js +41 -14
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.d.ts +162 -0
- package/src/ts/agent/generator.js +166 -75
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/generator.d.ts +37 -0
- package/src/ts/agent/mcp-connection/generator.js +41 -14
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/agent/react-connection/generator.d.ts +186 -0
- package/src/ts/agent/react-connection/generator.js +70 -21
- package/src/ts/agent/react-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/generator.d.ts +38 -0
- package/src/ts/astro-docs/generator.js +58 -19
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dcr-proxy/generator.d.ts +24 -0
- package/src/ts/dcr-proxy/generator.js +31 -14
- package/src/ts/dcr-proxy/generator.js.map +1 -1
- package/src/ts/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/ts/dynamodb/agent-connection/generator.js +7 -1
- package/src/ts/dynamodb/agent-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/generator.d.ts +41 -0
- package/src/ts/dynamodb/generator.js +47 -20
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
- package/src/ts/dynamodb/mcp-server-connection/generator.js +7 -1
- package/src/ts/dynamodb/mcp-server-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/dynamodb/smithy-connection/generator.js +3 -1
- package/src/ts/dynamodb/smithy-connection/generator.js.map +1 -1
- package/src/ts/dynamodb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/dynamodb/trpc-connection/generator.js +3 -1
- package/src/ts/dynamodb/trpc-connection/generator.js.map +1 -1
- package/src/ts/lambda-function/generator.d.ts +38 -0
- package/src/ts/lambda-function/generator.js +49 -20
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lib/generator.d.ts +7 -0
- package/src/ts/lib/generator.js +8 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.d.ts +3 -1
- package/src/ts/lib/ts-project-utils.js +3 -2
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.d.ts +10 -1
- package/src/ts/lib/vitest.js +14 -2
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/generator.d.ts +71 -0
- package/src/ts/mcp-server/generator.js +73 -36
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/generator.d.ts +3 -0
- package/src/ts/nx-generator/generator.js +8 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-migration/generator.d.ts +3 -0
- package/src/ts/nx-migration/generator.js +8 -2
- package/src/ts/nx-migration/generator.js.map +1 -1
- package/src/ts/nx-plugin/generator.d.ts +3 -0
- package/src/ts/nx-plugin/generator.js +8 -2
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.d.ts +7 -2
- package/src/ts/nx-plugin/utils.js +10 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/ts/rdb/agent-connection/generator.js +8 -1
- package/src/ts/rdb/agent-connection/generator.js.map +1 -1
- package/src/ts/rdb/generator.d.ts +101 -0
- package/src/ts/rdb/generator.js +93 -41
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/ts/rdb/mcp-server-connection/generator.js +8 -1
- package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -1
- package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/rdb/smithy-connection/generator.js +4 -1
- package/src/ts/rdb/smithy-connection/generator.js.map +1 -1
- package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/rdb/trpc-connection/generator.js +3 -1
- package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
- package/src/ts/react-website/agui/generator.d.ts +86 -0
- package/src/ts/react-website/agui/generator.js +63 -28
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +8 -2
- package/src/ts/react-website/app/generator.d.ts +136 -1
- package/src/ts/react-website/app/generator.js +109 -40
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/generator.d.ts +19 -0
- package/src/ts/react-website/cognito-auth/generator.js +21 -9
- package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
- package/src/utils/add-dependencies.d.ts +38 -0
- package/src/utils/add-dependencies.js +83 -0
- package/src/utils/add-dependencies.js.map +1 -0
- package/src/utils/agent-connection/agent-connection.d.ts +27 -6
- package/src/utils/agent-connection/agent-connection.js +47 -18
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +19 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +26 -6
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +21 -2
- package/src/utils/api-constructs/api-constructs.js +26 -5
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/bundle/bundle.d.ts +6 -1
- package/src/utils/bundle/bundle.js +8 -2
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/commands.d.ts +5 -4
- package/src/utils/commands.js +2 -6
- package/src/utils/commands.js.map +1 -1
- package/src/utils/connection/open-api/react.d.ts +18 -1
- package/src/utils/connection/open-api/react.js +27 -3
- package/src/utils/connection/open-api/react.js.map +1 -1
- package/src/utils/declared-dependencies.d.ts +140 -0
- package/src/utils/declared-dependencies.js +64 -0
- package/src/utils/declared-dependencies.js.map +1 -0
- package/src/utils/docker.d.ts +10 -1
- package/src/utils/docker.js +7 -3
- package/src/utils/docker.js.map +1 -1
- package/src/utils/fs.d.ts +15 -4
- package/src/utils/fs.js +26 -13
- package/src/utils/fs.js.map +1 -1
- package/src/utils/init.d.ts +14 -1
- package/src/utils/init.js +25 -7
- package/src/utils/init.js.map +1 -1
- package/src/utils/migration-versions.d.ts +15 -1
- package/src/utils/migration-versions.js +53 -7
- package/src/utils/migration-versions.js.map +1 -1
- package/src/utils/nx.d.ts +18 -0
- package/src/utils/nx.js +4 -0
- package/src/utils/nx.js.map +1 -1
- package/src/utils/py.d.ts +3 -2
- package/src/utils/py.js +10 -10
- package/src/utils/py.js.map +1 -1
- package/src/utils/shared-constructs-constants.d.ts +39 -4
- package/src/utils/shared-constructs-constants.js +29 -0
- package/src/utils/shared-constructs-constants.js.map +1 -1
- package/src/utils/shared-constructs.d.ts +4 -1
- package/src/utils/shared-constructs.js +5 -4
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-dynamodb-scripts.d.ts +8 -1
- package/src/utils/shared-dynamodb-scripts.js +11 -3
- package/src/utils/shared-dynamodb-scripts.js.map +1 -1
- package/src/utils/shared-infra-scripts.d.ts +16 -1
- package/src/utils/shared-infra-scripts.js +18 -3
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-rdb-scripts.d.ts +12 -1
- package/src/utils/shared-rdb-scripts.js +17 -3
- package/src/utils/shared-rdb-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.d.ts +26 -1
- package/src/utils/shared-shadcn.js +31 -14
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/version-upgrade-migration/migration.d.ts +14 -0
- package/src/utils/version-upgrade-migration/migration.js +16 -0
- package/src/utils/version-upgrade-migration/migration.js.map +1 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.d.ts +35 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.js +42 -0
- package/src/utils/version-upgrade-migration/nx-package-updates.js.map +1 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.d.ts +50 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.js +98 -0
- package/src/utils/version-upgrade-migration/owned-dependencies.js.map +1 -0
- package/src/utils/version-upgrade-migration/register.d.ts +18 -0
- package/src/utils/version-upgrade-migration/register.js +33 -0
- package/src/utils/version-upgrade-migration/register.js.map +1 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.d.ts +13 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.js +33 -0
- package/src/utils/version-upgrade-migration/sync-metrics-version.js.map +1 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.d.ts +10 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.js +504 -0
- package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.d.ts +14 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.js +40 -0
- package/src/utils/version-upgrade-migration/vended-upgrade.js.map +1 -0
- package/src/utils/versions.d.ts +25 -5
- package/src/utils/versions.js +46 -4
- package/src/utils/versions.js.map +1 -1
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { generateFiles, joinPathFragments, OverwriteStrategy, readProjectConfiguration, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
-
import {
|
|
5
|
+
import { addPyDependencies } from "../../utils/add-dependencies.js";
|
|
6
|
+
import { API_CONSTRUCTS_DEPENDENCIES, addApiGatewayInfra } from "../../utils/api-constructs/api-constructs.js";
|
|
6
7
|
import { addSharedConstructsOpenApiMetadataGenerateTarget } from "../../utils/api-constructs/open-api-metadata.js";
|
|
7
8
|
import { addPythonBundleTarget } from "../../utils/bundle/bundle.js";
|
|
9
|
+
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
8
10
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
9
|
-
import { FsCommands } from "../../utils/fs.js";
|
|
11
|
+
import { FS_DEPENDENCIES, FsCommands } from "../../utils/fs.js";
|
|
10
12
|
import { resolveIac } from "../../utils/iac.js";
|
|
11
13
|
import { installDependencies } from "../../utils/install.js";
|
|
12
14
|
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
@@ -14,10 +16,40 @@ import { toClassName, toKebabCase } from "../../utils/names.js";
|
|
|
14
16
|
import { addGeneratorMetadata, getGeneratorInfo } from "../../utils/nx.js";
|
|
15
17
|
import { sortObjectKeys } from "../../utils/object.js";
|
|
16
18
|
import { assignPort } from "../../utils/port.js";
|
|
17
|
-
import {
|
|
18
|
-
import { sharedConstructsGenerator } from "../../utils/shared-constructs.js";
|
|
19
|
+
import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../../utils/shared-constructs.js";
|
|
19
20
|
import pyProjectGenerator, { getPyProjectDetails } from "../project/generator.js";
|
|
20
21
|
import { addOpenApiGeneration } from "./react/open-api.js";
|
|
22
|
+
export const DEPENDENCIES = declareDependencies()({
|
|
23
|
+
ts: [
|
|
24
|
+
...ownedElsewhere(FS_DEPENDENCIES),
|
|
25
|
+
...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),
|
|
26
|
+
...ownedElsewhere(API_CONSTRUCTS_DEPENDENCIES)
|
|
27
|
+
],
|
|
28
|
+
py: [
|
|
29
|
+
{
|
|
30
|
+
name: 'fastapi'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'uvicorn'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'aws-lambda-powertools'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'aws-lambda-powertools[tracer]'
|
|
40
|
+
},
|
|
41
|
+
// The custom authorizer handler parses its event with the parser extra.
|
|
42
|
+
{
|
|
43
|
+
name: 'aws-lambda-powertools[parser]',
|
|
44
|
+
when: (m)=>m.auth === 'custom'
|
|
45
|
+
},
|
|
46
|
+
// `fastapi dev` runs the local server.
|
|
47
|
+
{
|
|
48
|
+
name: 'fastapi[standard]',
|
|
49
|
+
group: 'dev'
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
});
|
|
21
53
|
export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
22
54
|
/**
|
|
23
55
|
* Generates a Python FastAPI project
|
|
@@ -52,7 +84,7 @@ export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
52
84
|
const port = assignPort(tree, projectConfig, 8000);
|
|
53
85
|
const { bundleOutputDir, bundleTargetName } = addPythonBundleTarget(projectConfig);
|
|
54
86
|
// Add a command to copy run.sh to the bundle output for Lambda Web Adapter
|
|
55
|
-
const fs = new FsCommands(tree);
|
|
87
|
+
const fs = new FsCommands(tree, DEPENDENCIES);
|
|
56
88
|
const bundleTarget = projectConfig.targets[bundleTargetName];
|
|
57
89
|
const copyRunShCommand = fs.cp(`{projectRoot}/run.sh`, `dist/{projectRoot}/${bundleTargetName}/run.sh`);
|
|
58
90
|
if (!bundleTarget.options.commands.includes(copyRunShCommand)) {
|
|
@@ -79,11 +111,23 @@ export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
79
111
|
}
|
|
80
112
|
}
|
|
81
113
|
};
|
|
82
|
-
|
|
83
|
-
|
|
114
|
+
// Recorded in the metadata below so the version sync can tell a CDK
|
|
115
|
+
// project from a Terraform one; undefined when no infrastructure was
|
|
116
|
+
// generated, in which case neither provider's packages were added.
|
|
117
|
+
const iac = schema.infra !== 'none' ? await resolveIac(tree, schema.iac) : undefined;
|
|
118
|
+
// Recorded below and read by the declaration's predicates, so the packages
|
|
119
|
+
// added here are exactly the ones the version sync will own.
|
|
120
|
+
const metadata = {
|
|
84
121
|
apiName: schema.name,
|
|
85
122
|
apiType: 'fast-api',
|
|
86
|
-
auth: schema.auth
|
|
123
|
+
auth: schema.auth,
|
|
124
|
+
...iac ? {
|
|
125
|
+
iac
|
|
126
|
+
} : {}
|
|
127
|
+
};
|
|
128
|
+
projectConfig.metadata = {
|
|
129
|
+
...projectConfig.metadata,
|
|
130
|
+
...metadata
|
|
87
131
|
};
|
|
88
132
|
projectConfig.targets = sortObjectKeys(projectConfig.targets);
|
|
89
133
|
updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);
|
|
@@ -105,10 +149,9 @@ export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
105
149
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
106
150
|
});
|
|
107
151
|
if (schema.infra !== 'none') {
|
|
108
|
-
const iac = await resolveIac(tree, schema.iac);
|
|
109
152
|
await sharedConstructsGenerator(tree, {
|
|
110
153
|
iac
|
|
111
|
-
});
|
|
154
|
+
}, DEPENDENCIES);
|
|
112
155
|
if (schema.auth === 'custom') {
|
|
113
156
|
const authorizerType = schema.infra === 'http-lambda' ? 'http' : 'rest';
|
|
114
157
|
generateFiles(tree, joinPathFragments(import.meta.dirname, '..', '..', 'utils', 'api-constructs', 'files', 'py-authorizer', authorizerType), joinPathFragments(dir, normalizedModuleName), {}, {
|
|
@@ -129,7 +172,7 @@ export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
129
172
|
},
|
|
130
173
|
auth: schema.auth,
|
|
131
174
|
iac
|
|
132
|
-
});
|
|
175
|
+
}, DEPENDENCIES);
|
|
133
176
|
addSharedConstructsOpenApiMetadataGenerateTarget(tree, {
|
|
134
177
|
iac,
|
|
135
178
|
apiNameKebabCase,
|
|
@@ -137,18 +180,10 @@ export const FAST_API_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
137
180
|
specBuildTargetName: `${projectConfig.name}:openapi`
|
|
138
181
|
});
|
|
139
182
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
'aws-lambda-powertools[tracer]',
|
|
145
|
-
...schema.auth === 'custom' ? [
|
|
146
|
-
'aws-lambda-powertools[parser]'
|
|
147
|
-
] : []
|
|
148
|
-
]);
|
|
149
|
-
addDependenciesToDependencyGroupInPyProjectToml(tree, dir, 'dev', [
|
|
150
|
-
'fastapi[standard]'
|
|
151
|
-
]);
|
|
183
|
+
addPyDependencies(tree, DEPENDENCIES, {
|
|
184
|
+
metadata,
|
|
185
|
+
projectRoot: dir
|
|
186
|
+
});
|
|
152
187
|
addGeneratorMetadata(tree, fullyQualifiedName, FAST_API_GENERATOR_INFO);
|
|
153
188
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
154
189
|
FAST_API_GENERATOR_INFO
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/fast-api/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addApiGatewayInfra } from '../../utils/api-constructs/api-constructs';\nimport { addSharedConstructsOpenApiMetadataGenerateTarget } from '../../utils/api-constructs/open-api-metadata';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport {\n addDependenciesToDependencyGroupInPyProjectToml,\n addDependenciesToPyProjectToml,\n} from '../../utils/py';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport pyProjectGenerator, { getPyProjectDetails } from '../project/generator';\nimport { addOpenApiGeneration } from './react/open-api';\nimport type { PyFastApiProjectGeneratorSchema } from './schema';\n\nexport const FAST_API_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Generates a Python FastAPI project\n */\nexport const pyFastApiProjectGenerator = async (\n tree: Tree,\n schema: PyFastApiProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const integrationPattern = getIntegrationPattern(schema);\n\n const { dir, normalizedModuleName, fullyQualifiedName } = getPyProjectDetails(\n tree,\n {\n name: schema.name,\n directory: schema.directory,\n subDirectory: schema.subDirectory,\n moduleName: schema.moduleName,\n },\n );\n const apiNameKebabCase = toKebabCase(schema.name);\n const apiNameClassName = toClassName(schema.name);\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await pyProjectGenerator(tree, {\n name: schema.name,\n directory: schema.directory,\n subDirectory: schema.subDirectory,\n moduleName: normalizedModuleName,\n type: 'application',\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n const port = assignPort(tree, projectConfig, 8000);\n\n const { bundleOutputDir, bundleTargetName } =\n addPythonBundleTarget(projectConfig);\n\n // Add a command to copy run.sh to the bundle output for Lambda Web Adapter\n const fs = new FsCommands(tree);\n const bundleTarget = projectConfig.targets[bundleTargetName];\n const copyRunShCommand = fs.cp(\n `{projectRoot}/run.sh`,\n `dist/{projectRoot}/${bundleTargetName}/run.sh`,\n );\n if (!bundleTarget.options.commands.includes(copyRunShCommand)) {\n bundleTarget.options.commands = [\n ...bundleTarget.options.commands,\n copyRunShCommand,\n ];\n }\n\n projectConfig.targets.serve = {\n executor: '@nxlv/python:run-commands',\n continuous: true,\n options: {\n command: `uv run fastapi dev ${normalizedModuleName}/main.py --port ${port}`,\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n apiName: schema.name,\n apiType: 'fast-api',\n auth: schema.auth,\n } as any;\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n\n // Add OpenAPI spec generation to the project, run as part of build\n const { specPath } = addOpenApiGeneration(tree, { project: projectConfig });\n\n [\n joinPathFragments(dir, normalizedModuleName, 'hello.py'),\n joinPathFragments(dir, 'tests', 'test_hello.py'),\n ].forEach((f) => tree.delete(f));\n\n // User-owned source files: preserve any existing copies so re-running does\n // not clobber user edits (and does not reformat them nondeterministically).\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'app'), // path to the file templates\n dir, // destination path of the files\n {\n name: normalizedModuleName,\n apiNameClassName,\n infra: schema.infra,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n if (schema.infra !== 'none') {\n const iac = await resolveIac(tree, schema.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n if (schema.auth === 'custom') {\n const authorizerType = schema.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'py-authorizer',\n authorizerType,\n ),\n joinPathFragments(dir, normalizedModuleName),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Add the CDK construct to deploy the FastAPI to shared constructs\n await addApiGatewayInfra(tree, {\n apiProjectName: projectConfig.name,\n apiNameClassName,\n apiNameKebabCase,\n constructType: schema.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'fastapi',\n moduleName: normalizedModuleName,\n bundleOutputDir,\n integrationPattern,\n },\n auth: schema.auth,\n iac,\n });\n\n addSharedConstructsOpenApiMetadataGenerateTarget(tree, {\n iac,\n apiNameKebabCase,\n specPath,\n specBuildTargetName: `${projectConfig.name}:openapi`,\n });\n }\n\n addDependenciesToPyProjectToml(tree, dir, [\n 'fastapi',\n 'uvicorn',\n 'aws-lambda-powertools',\n 'aws-lambda-powertools[tracer]',\n ...(schema.auth === 'custom'\n ? (['aws-lambda-powertools[parser]'] as const)\n : []),\n ]);\n addDependenciesToDependencyGroupInPyProjectToml(tree, dir, 'dev', [\n 'fastapi[standard]',\n ]);\n\n addGeneratorMetadata(tree, fullyQualifiedName, FAST_API_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [FAST_API_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\n\nconst getIntegrationPattern = (\n schema: PyFastApiProjectGeneratorSchema,\n): 'isolated' | 'shared' => schema.integrationPattern ?? 'isolated';\n\nexport default pyFastApiProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateProjectConfiguration","addApiGatewayInfra","addSharedConstructsOpenApiMetadataGenerateTarget","addPythonBundleTarget","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","addGeneratorMetadata","getGeneratorInfo","sortObjectKeys","assignPort","addDependenciesToDependencyGroupInPyProjectToml","addDependenciesToPyProjectToml","sharedConstructsGenerator","pyProjectGenerator","getPyProjectDetails","addOpenApiGeneration","FAST_API_GENERATOR_INFO","filename","pyFastApiProjectGenerator","tree","schema","integrationPattern","getIntegrationPattern","dir","normalizedModuleName","fullyQualifiedName","name","directory","subDirectory","moduleName","apiNameKebabCase","apiNameClassName","projectExists","type","preferInstallDependencies","projectConfig","port","bundleOutputDir","bundleTargetName","fs","bundleTarget","targets","copyRunShCommand","cp","options","commands","includes","serve","executor","continuous","command","cwd","env","LOCAL_DEV","metadata","apiName","apiType","auth","specPath","project","forEach","f","delete","dirname","infra","overwriteStrategy","KeepExisting","iac","authorizerType","apiProjectName","constructType","backend","specBuildTargetName","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,kBAAkB,QAAQ,+CAA4C;AAC/E,SAASC,gDAAgD,QAAQ,kDAA+C;AAChH,SAASC,qBAAqB,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OAAOqC,IAAI,KAAK,WACf;YAAC;SAAgC,GAClC,EAAE;KACP;IACD/C,gDAAgDS,MAAMI,KAAK,OAAO;QAChE;KACD;IAEDjB,qBAAqBa,MAAMM,oBAAoBT;IAE/C,MAAMb,gCAAgCgB,MAAM;QAACH;KAAwB;IAErE,MAAMjB,qBAAqBoB;IAE3B,OAAO,IACLjB,oBAAoBiB,MAAMC,OAAOc,yBAAyB,EAAE;YAC1DuC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AAEF,MAAMnD,wBAAwB,CAC5BF,SAC0BA,OAAOC,kBAAkB,IAAI;AAEzD,eAAeH,0BAA0B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/fast-api/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addPyDependencies } from '../../utils/add-dependencies';\nimport {\n API_CONSTRUCTS_DEPENDENCIES,\n addApiGatewayInfra,\n} from '../../utils/api-constructs/api-constructs';\nimport { addSharedConstructsOpenApiMetadataGenerateTarget } from '../../utils/api-constructs/open-api-metadata';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants';\nimport pyProjectGenerator, { getPyProjectDetails } from '../project/generator';\nimport { addOpenApiGeneration } from './react/open-api';\nimport type { PyFastApiProjectGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface PyFastApiMetadata extends IacMetadata {\n readonly apiName: string;\n readonly apiType: string;\n readonly auth: PyFastApiProjectGeneratorSchema['auth'];\n}\n\nexport const DEPENDENCIES = declareDependencies<PyFastApiMetadata>()({\n ts: [\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(API_CONSTRUCTS_DEPENDENCIES),\n ],\n py: [\n { name: 'fastapi' },\n { name: 'uvicorn' },\n { name: 'aws-lambda-powertools' },\n { name: 'aws-lambda-powertools[tracer]' },\n // The custom authorizer handler parses its event with the parser extra.\n {\n name: 'aws-lambda-powertools[parser]',\n when: (m) => m.auth === 'custom',\n },\n // `fastapi dev` runs the local server.\n { name: 'fastapi[standard]', group: 'dev' },\n ],\n});\n\nexport const FAST_API_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Generates a Python FastAPI project\n */\nexport const pyFastApiProjectGenerator = async (\n tree: Tree,\n schema: PyFastApiProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const integrationPattern = getIntegrationPattern(schema);\n\n const { dir, normalizedModuleName, fullyQualifiedName } = getPyProjectDetails(\n tree,\n {\n name: schema.name,\n directory: schema.directory,\n subDirectory: schema.subDirectory,\n moduleName: schema.moduleName,\n },\n );\n const apiNameKebabCase = toKebabCase(schema.name);\n const apiNameClassName = toClassName(schema.name);\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await pyProjectGenerator(tree, {\n name: schema.name,\n directory: schema.directory,\n subDirectory: schema.subDirectory,\n moduleName: normalizedModuleName,\n type: 'application',\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n const port = assignPort(tree, projectConfig, 8000);\n\n const { bundleOutputDir, bundleTargetName } =\n addPythonBundleTarget(projectConfig);\n\n // Add a command to copy run.sh to the bundle output for Lambda Web Adapter\n const fs = new FsCommands(tree, DEPENDENCIES);\n const bundleTarget = projectConfig.targets[bundleTargetName];\n const copyRunShCommand = fs.cp(\n `{projectRoot}/run.sh`,\n `dist/{projectRoot}/${bundleTargetName}/run.sh`,\n );\n if (!bundleTarget.options.commands.includes(copyRunShCommand)) {\n bundleTarget.options.commands = [\n ...bundleTarget.options.commands,\n copyRunShCommand,\n ];\n }\n\n projectConfig.targets.serve = {\n executor: '@nxlv/python:run-commands',\n continuous: true,\n options: {\n command: `uv run fastapi dev ${normalizedModuleName}/main.py --port ${port}`,\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n schema.infra !== 'none' ? await resolveIac(tree, schema.iac) : undefined;\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: PyFastApiMetadata = {\n apiName: schema.name,\n apiType: 'fast-api',\n auth: schema.auth,\n ...(iac ? { iac } : {}),\n };\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n ...metadata,\n } as any;\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n\n // Add OpenAPI spec generation to the project, run as part of build\n const { specPath } = addOpenApiGeneration(tree, { project: projectConfig });\n\n [\n joinPathFragments(dir, normalizedModuleName, 'hello.py'),\n joinPathFragments(dir, 'tests', 'test_hello.py'),\n ].forEach((f) => tree.delete(f));\n\n // User-owned source files: preserve any existing copies so re-running does\n // not clobber user edits (and does not reformat them nondeterministically).\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'app'), // path to the file templates\n dir, // destination path of the files\n {\n name: normalizedModuleName,\n apiNameClassName,\n infra: schema.infra,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n if (schema.infra !== 'none') {\n await sharedConstructsGenerator(\n tree,\n {\n iac,\n },\n DEPENDENCIES,\n );\n\n if (schema.auth === 'custom') {\n const authorizerType = schema.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'py-authorizer',\n authorizerType,\n ),\n joinPathFragments(dir, normalizedModuleName),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Add the CDK construct to deploy the FastAPI to shared constructs\n await addApiGatewayInfra(\n tree,\n {\n apiProjectName: projectConfig.name,\n apiNameClassName,\n apiNameKebabCase,\n constructType: schema.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'fastapi',\n moduleName: normalizedModuleName,\n bundleOutputDir,\n integrationPattern,\n },\n auth: schema.auth,\n iac,\n },\n DEPENDENCIES,\n );\n\n addSharedConstructsOpenApiMetadataGenerateTarget(tree, {\n iac,\n apiNameKebabCase,\n specPath,\n specBuildTargetName: `${projectConfig.name}:openapi`,\n });\n }\n\n addPyDependencies(tree, DEPENDENCIES, { metadata, projectRoot: dir });\n\n addGeneratorMetadata(tree, fullyQualifiedName, FAST_API_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [FAST_API_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\n\nconst getIntegrationPattern = (\n schema: PyFastApiProjectGeneratorSchema,\n): 'isolated' | 'shared' => schema.integrationPattern ?? 'isolated';\n\nexport default pyFastApiProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateProjectConfiguration","addPyDependencies","API_CONSTRUCTS_DEPENDENCIES","addApiGatewayInfra","addSharedConstructsOpenApiMetadataGenerateTarget","addPythonBundleTarget","declareDependencies","ownedElsewhere","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","addGeneratorMetadata","getGeneratorInfo","sortObjectKeys","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","pyProjectGenerator","getPyProjectDetails","addOpenApiGeneration","DEPENDENCIES","ts","py","name","when","m","auth","group","FAST_API_GENERATOR_INFO","filename","pyFastApiProjectGenerator","tree","schema","integrationPattern","getIntegrationPattern","dir","normalizedModuleName","fullyQualifiedName","directory","subDirectory","moduleName","apiNameKebabCase","apiNameClassName","projectExists","type","preferInstallDependencies","projectConfig","port","bundleOutputDir","bundleTargetName","fs","bundleTarget","targets","copyRunShCommand","cp","options","commands","includes","serve","executor","continuous","command","cwd","env","LOCAL_DEV","iac","infra","undefined","metadata","apiName","apiType","specPath","project","forEach","f","delete","dirname","overwriteStrategy","KeepExisting","authorizerType","apiProjectName","constructType","backend","specBuildTargetName","projectRoot","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SACEC,2BAA2B,EAC3BC,kBAAkB,QACb,+CAA4C;AACnD,SAASC,gDAAgD,QAAQ,kDAA+C;AAChH,SAASC,qB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KAAK,KAAK,gBAAgB,SAAS;YACjE3E,cACEwC,MACAvC,kBACE,YAAYoF,OAAO,EACnB,MACA,MACA,SACA,kBACA,SACA,iBACAG,iBAEFvF,kBAAkB2C,KAAKC,uBACvB,CAAC,GACD;gBACEyC,mBAAmBpF,kBAAkBqF,YAAY;YACnD;QAEJ;QAEA,mEAAmE;QACnE,MAAMhF,mBACJiC,MACA;YACEiD,gBAAgBlC,cAAcvB,IAAI;YAClCmB;YACAD;YACAwC,eAAejD,OAAOkC,KAAK,KAAK,gBAAgB,SAAS;YACzDgB,SAAS;gBACPtC,MAAM;gBACNJ,YAAYJ;gBACZY;gBACAf;YACF;YACAP,MAAMM,OAAON,IAAI;YACjBuC;QACF,GACA7C;QAGFrB,iDAAiDgC,MAAM;YACrDkC;YACAxB;YACA8B;YACAY,qBAAqB,GAAGrC,cAAcvB,IAAI,CAAC,QAAQ,CAAC;QACtD;IACF;IAEA3B,kBAAkBmC,MAAMX,cAAc;QAAEgD;QAAUgB,aAAajD;IAAI;IAEnExB,qBAAqBoB,MAAMM,oBAAoBT;IAE/C,MAAMpB,gCAAgCuB,MAAM;QAACH;KAAwB;IAErE,MAAMzB,qBAAqB4B;IAE3B,OAAO,IACLxB,oBAAoBwB,MAAMC,OAAOa,yBAAyB,EAAE;YAC1DwC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AAEF,MAAMnD,wBAAwB,CAC5BF,SAC0BA,OAAOC,kBAAkB,IAAI;AAEzD,eAAeH,0BAA0B"}
|
|
@@ -2,9 +2,24 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type Tree } from '@nx/devkit';
|
|
6
6
|
import { type NxGeneratorInfo } from '../../../utils/nx';
|
|
7
7
|
import type { FastApiReactGeneratorSchema } from './schema';
|
|
8
|
+
export declare const DEPENDENCIES: import("../../../utils/declared-dependencies").DependencyDeclaration<readonly [{
|
|
9
|
+
readonly name: "oidc-client-ts";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "react-oidc-context";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "@aws-sdk/credential-provider-cognito-identity";
|
|
14
|
+
}, {
|
|
15
|
+
readonly name: "aws4fetch";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "@tanstack/react-query";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "@tanstack/react-query-devtools";
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "@smithy/types";
|
|
22
|
+
}], readonly import("../../../utils/declared-dependencies").DeclaredPyDependency<"a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "mcp" | "pip-check-updates" | "pip-licenses" | "ruff" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
|
|
8
23
|
export declare const FAST_API_REACT_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
24
|
export declare const fastApiReactGenerator: (tree: Tree, options: FastApiReactGeneratorSchema) => Promise<() => Promise<void>>;
|
|
10
25
|
export default fastApiReactGenerator;
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ import {
|
|
4
|
+
*/ import { joinPathFragments } from "@nx/devkit";
|
|
5
|
+
import { addOpenApiReactClient, OPEN_API_REACT_DEPENDENCIES } from "../../../utils/connection/open-api/react.js";
|
|
6
|
+
import { declareDependencies } from "../../../utils/declared-dependencies.js";
|
|
5
7
|
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
6
8
|
import { installDependencies } from "../../../utils/install.js";
|
|
7
9
|
import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
|
|
8
|
-
import {
|
|
10
|
+
import { toClassName } from "../../../utils/names.js";
|
|
11
|
+
import { addComponentGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
|
|
12
|
+
import { toProjectRelativePath } from "../../../utils/paths.js";
|
|
9
13
|
import { addOpenApiGeneration } from "./open-api.js";
|
|
14
|
+
export const DEPENDENCIES = declareDependencies()({
|
|
15
|
+
ts: [
|
|
16
|
+
...OPEN_API_REACT_DEPENDENCIES
|
|
17
|
+
]
|
|
18
|
+
});
|
|
10
19
|
export const FAST_API_REACT_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
11
20
|
export const fastApiReactGenerator = async (tree, options)=>{
|
|
12
21
|
const frontendProjectConfig = readProjectConfigurationUnqualified(tree, options.frontendProjectName);
|
|
@@ -28,7 +37,10 @@ export const fastApiReactGenerator = async (tree, options)=>{
|
|
|
28
37
|
specBuildTargetName: `${fastApiProjectConfig.name}:openapi`,
|
|
29
38
|
auth,
|
|
30
39
|
port
|
|
31
|
-
});
|
|
40
|
+
}, DEPENDENCIES);
|
|
41
|
+
const apiNameClassName = toClassName(apiName);
|
|
42
|
+
// Recorded so the version sync knows this connection's dependencies are ours.
|
|
43
|
+
addComponentGeneratorMetadata(tree, frontendProjectConfig.name, FAST_API_REACT_GENERATOR_INFO, toProjectRelativePath(frontendProjectConfig, joinPathFragments(frontendProjectConfig.sourceRoot, 'components', `${apiNameClassName}Provider`)), apiNameClassName);
|
|
32
44
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
33
45
|
FAST_API_REACT_GENERATOR_INFO
|
|
34
46
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/py/fast-api/react/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/py/fast-api/react/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, type Tree } from '@nx/devkit';\nimport {\n addOpenApiReactClient,\n OPEN_API_REACT_DEPENDENCIES,\n} from '../../../utils/connection/open-api/react';\nimport { declareDependencies } from '../../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { toClassName } from '../../../utils/names';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { toProjectRelativePath } from '../../../utils/paths';\nimport { addOpenApiGeneration } from './open-api';\nimport type { FastApiReactGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...OPEN_API_REACT_DEPENDENCIES],\n});\n\nexport const FAST_API_REACT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const fastApiReactGenerator = async (\n tree: Tree,\n options: FastApiReactGeneratorSchema,\n) => {\n const frontendProjectConfig = readProjectConfigurationUnqualified(\n tree,\n options.frontendProjectName,\n );\n const fastApiProjectConfig = readProjectConfigurationUnqualified(\n tree,\n options.fastApiProjectName,\n );\n\n // Add OpenAPI spec generation to the project, run as part of build\n const { specPath } = addOpenApiGeneration(tree, {\n project: fastApiProjectConfig,\n });\n\n const metadata = fastApiProjectConfig.metadata as any;\n const apiName = metadata?.apiName;\n const auth = (metadata?.auth ?? 'iam').toLowerCase();\n const port = metadata?.port ?? metadata?.ports?.[0] ?? 8000;\n\n await addOpenApiReactClient(\n tree,\n {\n apiName,\n frontendProjectConfig,\n backendProjectConfig: fastApiProjectConfig,\n specBuildProject: fastApiProjectConfig,\n specPath,\n specBuildTargetName: `${fastApiProjectConfig.name}:openapi`,\n auth,\n port,\n },\n DEPENDENCIES,\n );\n\n const apiNameClassName = toClassName(apiName);\n\n // Recorded so the version sync knows this connection's dependencies are ours.\n addComponentGeneratorMetadata(\n tree,\n frontendProjectConfig.name,\n FAST_API_REACT_GENERATOR_INFO,\n toProjectRelativePath(\n frontendProjectConfig,\n joinPathFragments(\n frontendProjectConfig.sourceRoot,\n 'components',\n `${apiNameClassName}Provider`,\n ),\n ),\n apiNameClassName,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [FAST_API_REACT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default fastApiReactGenerator;\n"],"names":["joinPathFragments","addOpenApiReactClient","OPEN_API_REACT_DEPENDENCIES","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","toClassName","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","toProjectRelativePath","addOpenApiGeneration","DEPENDENCIES","ts","FAST_API_REACT_GENERATOR_INFO","filename","fastApiReactGenerator","tree","options","frontendProjectConfig","frontendProjectName","fastApiProjectConfig","fastApiProjectName","specPath","project","metadata","apiName","auth","toLowerCase","port","ports","backendProjectConfig","specBuildProject","specBuildTargetName","name","apiNameClassName","sourceRoot","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAASA,iBAAiB,QAAmB,aAAa;AAC1D,SACEC,qBAAqB,EACrBC,2BAA2B,QACtB,8CAA2C;AAClD,SAASC,mBAAmB,QAAQ,0CAAuC;AAC3E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAm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AqBc;IAC3B,OAAO,IACLb,oBAAoBa,MAAMC,QAAQmB,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAetB,sBAAsB"}
|
|
@@ -5,6 +5,27 @@
|
|
|
5
5
|
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
6
|
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
7
|
import type { PyLambdaFunctionGeneratorSchema } from './schema';
|
|
8
|
+
export declare const DEPENDENCIES: import("../../utils/declared-dependencies").DependencyDeclaration<readonly [{
|
|
9
|
+
readonly name: "constructs";
|
|
10
|
+
readonly when: (m: import("../../utils/shared-constructs-constants").IacMetadata) => boolean;
|
|
11
|
+
} & {
|
|
12
|
+
versionOnly: true;
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "aws-cdk-lib";
|
|
15
|
+
readonly when: (m: import("../../utils/shared-constructs-constants").IacMetadata) => boolean;
|
|
16
|
+
} & {
|
|
17
|
+
versionOnly: true;
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "@types/node";
|
|
20
|
+
} & {
|
|
21
|
+
versionOnly: true;
|
|
22
|
+
}], readonly [{
|
|
23
|
+
readonly name: "aws-lambda-powertools";
|
|
24
|
+
}, {
|
|
25
|
+
readonly name: "aws-lambda-powertools[tracer]";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "aws-lambda-powertools[parser]";
|
|
28
|
+
}]>;
|
|
8
29
|
export declare const LAMBDA_FUNCTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
30
|
export interface LambdaFunctionDetails {
|
|
10
31
|
/**
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { generateFiles, joinPathFragments, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
+
import { addPyDependencies } from "../../utils/add-dependencies.js";
|
|
5
6
|
import { addPythonBundleTarget } from "../../utils/bundle/bundle.js";
|
|
7
|
+
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
6
8
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
7
9
|
import { addLambdaFunctionInfra } from "../../utils/function-constructs/function-constructs.js";
|
|
8
10
|
import { resolveIac } from "../../utils/iac.js";
|
|
@@ -13,8 +15,23 @@ import { getNpmScope } from "../../utils/npm-scope.js";
|
|
|
13
15
|
import { addComponentGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
14
16
|
import { sortObjectKeys } from "../../utils/object.js";
|
|
15
17
|
import { toProjectRelativePath } from "../../utils/paths.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
+
import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../../utils/shared-constructs.js";
|
|
19
|
+
export const DEPENDENCIES = declareDependencies()({
|
|
20
|
+
ts: [
|
|
21
|
+
...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES)
|
|
22
|
+
],
|
|
23
|
+
py: [
|
|
24
|
+
{
|
|
25
|
+
name: 'aws-lambda-powertools'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'aws-lambda-powertools[tracer]'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'aws-lambda-powertools[parser]'
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
});
|
|
18
35
|
export const LAMBDA_FUNCTION_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
19
36
|
const getLambdaFunctionDetails = (tree, schema)=>{
|
|
20
37
|
const scope = toSnakeCase(getNpmScope(tree));
|
|
@@ -63,11 +80,13 @@ const getLambdaFunctionDetails = (tree, schema)=>{
|
|
|
63
80
|
}
|
|
64
81
|
// Check if the project has a bundle target and if not add it
|
|
65
82
|
const { bundleOutputDir } = addPythonBundleTarget(projectConfig);
|
|
83
|
+
// Recorded below so the version sync can tell a CDK project from a
|
|
84
|
+
// Terraform one; undefined when no infrastructure was generated.
|
|
85
|
+
const iac = infra !== 'none' ? await resolveIac(tree, schema.iac) : undefined;
|
|
66
86
|
if (infra !== 'none') {
|
|
67
|
-
const iac = await resolveIac(tree, schema.iac);
|
|
68
87
|
await sharedConstructsGenerator(tree, {
|
|
69
88
|
iac
|
|
70
|
-
});
|
|
89
|
+
}, DEPENDENCIES);
|
|
71
90
|
await addLambdaFunctionInfra(tree, {
|
|
72
91
|
functionProjectName: projectConfig.name,
|
|
73
92
|
nameClassName: constructFunctionClassName,
|
|
@@ -94,12 +113,12 @@ const getLambdaFunctionDetails = (tree, schema)=>{
|
|
|
94
113
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'tests'), joinPathFragments(dir, 'tests'), enhancedOptions, {
|
|
95
114
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
96
115
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
addPyDependencies(tree, DEPENDENCIES, {
|
|
117
|
+
projectRoot: dir
|
|
118
|
+
});
|
|
119
|
+
addComponentGeneratorMetadata(tree, projectConfig.name, LAMBDA_FUNCTION_GENERATOR_INFO, toProjectRelativePath(projectConfig, functionPath), lambdaFunctionKebabCase, iac ? {
|
|
120
|
+
iac
|
|
121
|
+
} : {});
|
|
103
122
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
104
123
|
LAMBDA_FUNCTION_GENERATOR_INFO
|
|
105
124
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/lambda-function/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { addLambdaFunctionInfra } from '../../utils/function-constructs/function-constructs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n toClassName,\n toDotNotation,\n toKebabCase,\n toSnakeCase,\n} from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport { addDependenciesToPyProjectToml } from '../../utils/py';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport type { PyLambdaFunctionGeneratorSchema } from './schema';\n\nexport const LAMBDA_FUNCTION_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface LambdaFunctionDetails {\n /**\n * The normalized name of the lambda handler project\n */\n readonly normalizedFunctionName: string;\n /**\n * The full package name of the lambda handler construct\n */\n readonly fullyQualifiedFunctionName: string;\n /**\n * The normalized python path to the lambda handler file in dot notation (e.g. `app.lambda_functions.lambda_handler`)\n */\n readonly normalizedFunctionPath: string;\n}\n\nconst getLambdaFunctionDetails = (\n tree: Tree,\n schema: { moduleName: string; name: string; functionPath?: string },\n): LambdaFunctionDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedFunctionName = toSnakeCase(schema.name);\n const fullyQualifiedFunctionName = `${scope}.${normalizedFunctionName}`;\n const normalizedFunctionPath = `${schema.moduleName}.${schema.functionPath ? `${toDotNotation(schema.functionPath)}.` : ''}${normalizedFunctionName}.lambda_handler`;\n\n return {\n fullyQualifiedFunctionName,\n normalizedFunctionName,\n normalizedFunctionPath,\n };\n};\n\n/**\n * Generates a Python Lambda Function to add to a python project\n */\nexport const pyLambdaFunctionGenerator = async (\n tree: Tree,\n schema: PyLambdaFunctionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n schema.project,\n );\n\n const pyProjectPath = joinPathFragments(projectConfig.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `This generator does not support selected project ${schema.project}`,\n );\n }\n\n if (!projectConfig.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n const dir = projectConfig.root;\n const projectNameWithOutScope = projectConfig.name.split('.').pop();\n const normalizedProjectName = toSnakeCase(projectNameWithOutScope);\n\n // Module name is the last part of the source root,\n const sourceParts = projectConfig.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const { normalizedFunctionName, normalizedFunctionPath } =\n getLambdaFunctionDetails(tree, {\n moduleName,\n name: schema.name,\n functionPath: schema.functionPath,\n });\n\n const constructFunctionName = `${normalizedProjectName}_${normalizedFunctionName}`;\n const constructFunctionClassName = toClassName(constructFunctionName);\n const constructFunctionKebabCase = toKebabCase(constructFunctionName);\n const lambdaFunctionClassName = toClassName(schema.name);\n const lambdaFunctionKebabCase = toKebabCase(schema.name);\n\n const functionPath = joinPathFragments(\n projectConfig.sourceRoot,\n schema.functionPath ?? '',\n `${normalizedFunctionName}.py`,\n );\n\n const infra = schema.infra ?? 'lambda';\n const handlerAlreadyExists = tree.exists(functionPath);\n\n if (handlerAlreadyExists && infra === 'none') {\n throw new Error(\n `This project already has a lambda function with the name ${normalizedFunctionName}. Please remove the lambda function before running this generator or use a different name.`,\n );\n }\n\n // Check if the project has a bundle target and if not add it\n const { bundleOutputDir } = addPythonBundleTarget(projectConfig);\n\n if (infra !== 'none') {\n const iac = await resolveIac(tree, schema.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addLambdaFunctionInfra(tree, {\n functionProjectName: projectConfig.name,\n nameClassName: constructFunctionClassName,\n nameKebabCase: constructFunctionKebabCase,\n handler: normalizedFunctionPath,\n bundlePathFromRoot: bundleOutputDir,\n runtime: 'python',\n iac,\n });\n }\n\n const enhancedOptions = {\n ...schema,\n dir,\n lambdaFunctionClassName,\n lambdaFunctionSnakeCase: normalizedFunctionName,\n };\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n // Generate the lambda handler file\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'handler'), // path to the file templates\n joinPathFragments(projectConfig.sourceRoot, schema.functionPath ?? ''),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate the lambda handler test file\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'tests'),\n joinPathFragments(dir, 'tests'),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addDependenciesToPyProjectToml(tree, dir, [\n 'aws-lambda-powertools',\n 'aws-lambda-powertools[tracer]',\n 'aws-lambda-powertools[parser]',\n ]);\n\n addComponentGeneratorMetadata(\n tree,\n projectConfig.name,\n LAMBDA_FUNCTION_GENERATOR_INFO,\n toProjectRelativePath(projectConfig, functionPath),\n lambdaFunctionKebabCase,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [LAMBDA_FUNCTION_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyLambdaFunctionGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addPythonBundleTarget","formatFilesInSubtree","addLambdaFunctionInfra","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toDotNotation","toKebabCase","toSnakeCase","getNpmScope","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","toProjectRelativePath","addDependenciesToPyProjectToml","sharedConstructsGenerator","LAMBDA_FUNCTION_GENERATOR_INFO","filename","getLambdaFunctionDetails","tree","schema","scope","normalizedFunctionName","name","fullyQualifiedFunctionName","normalizedFunctionPath","moduleName","functionPath","pyLambdaFunctionGenerator","projectConfig","project","pyProjectPath","root","Error","sourceRoot","dir","projectNameWithOutScope","split","pop","normalizedProjectName","sourceParts","length","constructFunctionName","constructFunctionClassName","constructFunctionKebabCase","lambdaFunctionClassName","lambdaFunctionKebabCase","infra","handlerAlreadyExists","exists","bundleOutputDir","iac","functionProjectName","nameClassName","nameKebabCase","handler","bundlePathFromRoot","runtime","enhancedOptions","lambdaFunctionSnakeCase","targets","dirname","overwriteStrategy","KeepExisting","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,sBAAsB,QAAQ,yDAAsD;AAC7F,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,uBAAoB;AAC3B,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,6BAA6B,EAC7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,qBAAqB,QAAQ,uBAAoB;AAC1D,SAASC,8BAA8B,QAAQ,oBAAiB;AAChE,SAASC,yBAAyB,QAAQ,mCAAgC;AAG1E,OAAO,MAAMC,iCAAkDN,iBAC7D,YAAYO,QAAQ,EACpB;AAiBF,MAAMC,2BAA2B,CAC/BC,MACAC;IAEA,MA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,kBAAkBmE,YAAY;IAAC;IAGtDjD,+BAA+BK,MAAMgB,KAAK;QACxC;QACA;QACA;KACD;IAED1B,8BACEU,MACAU,cAAcN,IAAI,EAClBP,gCACAH,sBAAsBgB,eAAeF,eACrCmB;IAGF,MAAM3C,gCAAgCgB,MAAM;QAACH;KAA+B;IAE5E,MAAMjB,qBAAqBoB;IAE3B,OAAO,IACLjB,oBAAoBiB,MAAMC,OAAO4C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAerC,0BAA0B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/lambda-function/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addPyDependencies } from '../../utils/add-dependencies';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { addLambdaFunctionInfra } from '../../utils/function-constructs/function-constructs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n toClassName,\n toDotNotation,\n toKebabCase,\n toSnakeCase,\n} from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { PyLambdaFunctionGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES)],\n py: [\n { name: 'aws-lambda-powertools' },\n { name: 'aws-lambda-powertools[tracer]' },\n { name: 'aws-lambda-powertools[parser]' },\n ],\n});\n\nexport const LAMBDA_FUNCTION_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface LambdaFunctionDetails {\n /**\n * The normalized name of the lambda handler project\n */\n readonly normalizedFunctionName: string;\n /**\n * The full package name of the lambda handler construct\n */\n readonly fullyQualifiedFunctionName: string;\n /**\n * The normalized python path to the lambda handler file in dot notation (e.g. `app.lambda_functions.lambda_handler`)\n */\n readonly normalizedFunctionPath: string;\n}\n\nconst getLambdaFunctionDetails = (\n tree: Tree,\n schema: { moduleName: string; name: string; functionPath?: string },\n): LambdaFunctionDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedFunctionName = toSnakeCase(schema.name);\n const fullyQualifiedFunctionName = `${scope}.${normalizedFunctionName}`;\n const normalizedFunctionPath = `${schema.moduleName}.${schema.functionPath ? `${toDotNotation(schema.functionPath)}.` : ''}${normalizedFunctionName}.lambda_handler`;\n\n return {\n fullyQualifiedFunctionName,\n normalizedFunctionName,\n normalizedFunctionPath,\n };\n};\n\n/**\n * Generates a Python Lambda Function to add to a python project\n */\nexport const pyLambdaFunctionGenerator = async (\n tree: Tree,\n schema: PyLambdaFunctionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n schema.project,\n );\n\n const pyProjectPath = joinPathFragments(projectConfig.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `This generator does not support selected project ${schema.project}`,\n );\n }\n\n if (!projectConfig.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n const dir = projectConfig.root;\n const projectNameWithOutScope = projectConfig.name.split('.').pop();\n const normalizedProjectName = toSnakeCase(projectNameWithOutScope);\n\n // Module name is the last part of the source root,\n const sourceParts = projectConfig.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const { normalizedFunctionName, normalizedFunctionPath } =\n getLambdaFunctionDetails(tree, {\n moduleName,\n name: schema.name,\n functionPath: schema.functionPath,\n });\n\n const constructFunctionName = `${normalizedProjectName}_${normalizedFunctionName}`;\n const constructFunctionClassName = toClassName(constructFunctionName);\n const constructFunctionKebabCase = toKebabCase(constructFunctionName);\n const lambdaFunctionClassName = toClassName(schema.name);\n const lambdaFunctionKebabCase = toKebabCase(schema.name);\n\n const functionPath = joinPathFragments(\n projectConfig.sourceRoot,\n schema.functionPath ?? '',\n `${normalizedFunctionName}.py`,\n );\n\n const infra = schema.infra ?? 'lambda';\n const handlerAlreadyExists = tree.exists(functionPath);\n\n if (handlerAlreadyExists && infra === 'none') {\n throw new Error(\n `This project already has a lambda function with the name ${normalizedFunctionName}. Please remove the lambda function before running this generator or use a different name.`,\n );\n }\n\n // Check if the project has a bundle target and if not add it\n const { bundleOutputDir } = addPythonBundleTarget(projectConfig);\n\n // Recorded below so the version sync can tell a CDK project from a\n // Terraform one; undefined when no infrastructure was generated.\n const iac = infra !== 'none' ? await resolveIac(tree, schema.iac) : undefined;\n\n if (infra !== 'none') {\n await sharedConstructsGenerator(\n tree,\n {\n iac,\n },\n DEPENDENCIES,\n );\n\n await addLambdaFunctionInfra(tree, {\n functionProjectName: projectConfig.name,\n nameClassName: constructFunctionClassName,\n nameKebabCase: constructFunctionKebabCase,\n handler: normalizedFunctionPath,\n bundlePathFromRoot: bundleOutputDir,\n runtime: 'python',\n iac,\n });\n }\n\n const enhancedOptions = {\n ...schema,\n dir,\n lambdaFunctionClassName,\n lambdaFunctionSnakeCase: normalizedFunctionName,\n };\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n // Generate the lambda handler file\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'handler'), // path to the file templates\n joinPathFragments(projectConfig.sourceRoot, schema.functionPath ?? ''),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate the lambda handler test file\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'tests'),\n joinPathFragments(dir, 'tests'),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addPyDependencies(tree, DEPENDENCIES, { projectRoot: dir });\n\n addComponentGeneratorMetadata(\n tree,\n projectConfig.name,\n LAMBDA_FUNCTION_GENERATOR_INFO,\n toProjectRelativePath(projectConfig, functionPath),\n lambdaFunctionKebabCase,\n iac ? { iac } : {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [LAMBDA_FUNCTION_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyLambdaFunctionGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addPyDependencies","addPythonBundleTarget","declareDependencies","ownedElsewhere","formatFilesInSubtree","addLambdaFunctionInfra","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toDotNotation","toKebabCase","toSnakeCase","getNpmScope","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","toProjectRelativePath","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","py","name","LAMBDA_FUNCTION_GENERATOR_INFO","filename","getLambdaFunctionDetails","tree","schema","scope","normalizedFunctionName","fullyQualifiedFunctionName","normalizedFunctionPath","moduleName","functionPath","pyLambdaFunctionGenerator","projectConfig","project","pyProjectPath","root","Error","sourceRoot","dir","projectNameWithOutScope","split","pop","normalizedProjectName","sourceParts","length","constructFunctionName","constructFunctionClassName","constructFunctionKebabCase","lambdaFunctionClassName","lambdaFunctionKebabCase","infra","handlerAlreadyExists","exists","bundleOutputDir","iac","undefined","functionProjectName","nameClassName","nameKebabCase","handler","bundlePathFromRoot","runtime","enhancedOptions","lambdaFunctionSnakeCase","targets","dirname","overwriteStrategy","KeepExisting","projectRoot","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,sBAAsB,QAAQ,yDAAsD;AAC7F,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,uBAAoB;AAC3B,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,6BAA6B,EAC7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,qBAAqB,QAAQ,uBAAoB;AAC1D,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAgC;AAGvC,OAAO,MAAMC,eAAenB,sBAAsB;IAChDoB,IAAI;WAAInB,eAAegB;KAAgC;IACvDI,IAAI;QACF;YAAEC,MAAM;QAAwB;QAChC;YAAEA,MAAM;QAAgC;QACxC;YAAEA,MAAM;QAAgC;KACzC;AACH,GAAG;AAEH,OAAO,MAAMC,iCAAkDV,iBAC7D,YAAYW,QAAQ,EACpB;AAiBF,MAAMC,2BAA2B,CAC/BC,MACAC;IAEA,MAAMC,QAAQlB,YAAYC,YAAYe;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8C,KAAK,UACvBwB,iBACA;QAAEI,mBAAmBzE,kBAAkB0E,YAAY;IAAC;IAGtDxE,kBAAkB4B,MAAMP,cAAc;QAAEoD,aAAa9B;IAAI;IAEzD7B,8BACEc,MACAS,cAAcb,IAAI,EAClBC,gCACAP,sBAAsBmB,eAAeF,eACrCmB,yBACAK,MAAM;QAAEA;IAAI,IAAI,CAAC;IAGnB,MAAMnD,gCAAgCoB,MAAM;QAACH;KAA+B;IAE5E,MAAMrB,qBAAqBwB;IAE3B,OAAO,IACLrB,oBAAoBqB,MAAMC,OAAO6C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAevC,0BAA0B"}
|
|
@@ -4,7 +4,67 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
6
|
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
|
+
import type { IacMetadata } from '../../utils/shared-constructs-constants';
|
|
7
8
|
import type { PyMcpServerGeneratorSchema } from './schema';
|
|
9
|
+
/** The metadata this generator records, which its predicates read. */
|
|
10
|
+
export interface PyMcpServerMetadata extends IacMetadata {
|
|
11
|
+
readonly port: number;
|
|
12
|
+
readonly rc: string;
|
|
13
|
+
readonly auth: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const DEPENDENCIES: import("../../utils/declared-dependencies").DependencyDeclaration<readonly [{
|
|
16
|
+
readonly name: "@modelcontextprotocol/inspector";
|
|
17
|
+
readonly dev: true;
|
|
18
|
+
readonly root: true;
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "ncp";
|
|
21
|
+
} & {
|
|
22
|
+
versionOnly: true;
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "rimraf";
|
|
25
|
+
} & {
|
|
26
|
+
versionOnly: true;
|
|
27
|
+
}, {
|
|
28
|
+
readonly name: "make-dir-cli";
|
|
29
|
+
} & {
|
|
30
|
+
versionOnly: true;
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "ncp";
|
|
33
|
+
} & {
|
|
34
|
+
versionOnly: true;
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "rimraf";
|
|
37
|
+
} & {
|
|
38
|
+
versionOnly: true;
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "make-dir-cli";
|
|
41
|
+
} & {
|
|
42
|
+
versionOnly: true;
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "constructs";
|
|
45
|
+
readonly when: (m: IacMetadata) => boolean;
|
|
46
|
+
} & {
|
|
47
|
+
versionOnly: true;
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "aws-cdk-lib";
|
|
50
|
+
readonly when: (m: IacMetadata) => boolean;
|
|
51
|
+
} & {
|
|
52
|
+
versionOnly: true;
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "@types/node";
|
|
55
|
+
} & {
|
|
56
|
+
versionOnly: true;
|
|
57
|
+
}], readonly [{
|
|
58
|
+
readonly name: "aws-lambda-powertools";
|
|
59
|
+
}, {
|
|
60
|
+
readonly name: "mcp";
|
|
61
|
+
}, {
|
|
62
|
+
readonly name: "uvicorn";
|
|
63
|
+
}, {
|
|
64
|
+
readonly name: "boto3";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "aws-opentelemetry-distro";
|
|
67
|
+
}]>;
|
|
8
68
|
export declare const PY_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
69
|
export declare const pyMcpServerGenerator: (tree: Tree, options: PyMcpServerGeneratorSchema) => Promise<GeneratorCallback>;
|
|
10
70
|
export default pyMcpServerGenerator;
|