@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.33
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/LICENSE-THIRD-PARTY +72 -70
- package/package.json +5 -5
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
- package/src/infra/app/files/app/src/main.ts.template +1 -1
- package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
- package/src/infra/app/generator.js +3 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/open-api/ts-client/files/client.gen.ts.template +1 -1
- package/src/open-api/ts-client/generator.js +5 -1
- package/src/open-api/ts-client/generator.js.map +1 -1
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
- package/src/open-api/ts-hooks/generator.js +5 -1
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +5 -2
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.js.map +1 -1
- package/src/preset/schema.d.ts +2 -0
- package/src/preset/schema.json +6 -0
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
- package/src/smithy/ts/api/files/handler.ts.template +2 -2
- package/src/smithy/ts/api/files/local-server.ts.template +2 -2
- package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
- package/src/smithy/ts/api/files/service.ts.template +3 -3
- package/src/smithy/ts/api/generator.js +3 -1
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
- package/src/trpc/backend/files/src/client/index.ts.template +1 -1
- package/src/trpc/backend/files/src/handler.ts.template +1 -1
- package/src/trpc/backend/files/src/index.ts.template +5 -5
- package/src/trpc/backend/files/src/init.ts.template +1 -1
- package/src/trpc/backend/files/src/local-server.ts.template +1 -1
- package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
- package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
- package/src/trpc/backend/files/src/router.ts.template +2 -2
- package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
- package/src/trpc/backend/generator.js +3 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
- package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/a2a-connection/generator.js +3 -1
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/a2a/index.ts.template +1 -1
- package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
- package/src/ts/agent/files/http/client.ts.template +2 -2
- package/src/ts/agent/files/http/index.ts.template +2 -2
- package/src/ts/agent/files/http/router.ts.template +3 -3
- package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/gateway-connection/generator.js +3 -1
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +5 -2
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/mcp-connection/generator.js +3 -1
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
- package/src/ts/astro-docs/generator.js +2 -0
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/dynamodb/files/src/client.ts.template +5 -2
- package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
- package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
- package/src/ts/dynamodb/files/src/index.ts.template +2 -2
- package/src/ts/dynamodb/generator.js +3 -1
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/lib/generator.js +7 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +19 -4
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/types.d.ts +6 -0
- package/src/ts/lib/types.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
- package/src/ts/mcp-server/generator.js +3 -2
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
- package/src/ts/nx-generator/generator.js +5 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
- package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
- package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
- package/src/ts/nx-plugin/generator.js +3 -1
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.js +7 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
- package/src/ts/rdb/files/src/index.ts.template +1 -1
- package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
- package/src/ts/rdb/files/src/prisma.ts.template +7 -4
- package/src/ts/rdb/generator.js +3 -1
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
- package/src/utils/agent-chat/agent-chat.js +3 -1
- package/src/utils/agent-chat/agent-chat.js.map +1 -1
- package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-connection/agent-connection.js +4 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
- package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
- package/src/utils/api-constructs/api-constructs.js +8 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
- package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
- package/src/utils/ast.js +16 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/commands.d.ts +1 -1
- package/src/utils/commands.js +4 -1
- package/src/utils/commands.js.map +1 -1
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
- package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
- package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
- package/src/utils/files/common/constructs/src/index.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
- package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
- package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
- package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
- package/src/utils/function-constructs/function-constructs.js +3 -1
- package/src/utils/function-constructs/function-constructs.js.map +1 -1
- package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
- package/src/utils/identity-constructs/identity-constructs.js +5 -1
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
- package/src/utils/module-format.d.ts +28 -0
- package/src/utils/module-format.js +28 -0
- package/src/utils/module-format.js.map +1 -0
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
- package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
- package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/shared-constructs.js +3 -1
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-infra-config.js +3 -1
- package/src/utils/shared-infra-config.js.map +1 -1
- package/src/utils/shared-infra-scripts.js +3 -1
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.js +3 -1
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.d.ts +2 -0
- package/src/utils/test.js +7 -1
- package/src/utils/test.js.map +1 -1
- package/src/utils/versions.d.ts +58 -58
- package/src/utils/versions.js +56 -56
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
- package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
- package/src/utils/website-constructs/website-constructs.js +9 -2
- package/src/utils/website-constructs/website-constructs.js.map +1 -1
|
@@ -403,7 +403,7 @@ terraform {
|
|
|
403
403
|
required_providers {
|
|
404
404
|
aws = {
|
|
405
405
|
source = "hashicorp/aws"
|
|
406
|
-
version = "6.
|
|
406
|
+
version = "6.54.0"
|
|
407
407
|
}
|
|
408
408
|
random = {
|
|
409
409
|
source = "hashicorp/random"
|
|
@@ -662,7 +662,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with Terraform pro
|
|
|
662
662
|
required_providers {
|
|
663
663
|
aws = {
|
|
664
664
|
source = "hashicorp/aws"
|
|
665
|
-
version = "6.
|
|
665
|
+
version = "6.54.0"
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
}
|
|
@@ -1827,7 +1827,7 @@ terraform {
|
|
|
1827
1827
|
required_providers {
|
|
1828
1828
|
aws = {
|
|
1829
1829
|
source = "hashicorp/aws"
|
|
1830
|
-
version = "6.
|
|
1830
|
+
version = "6.54.0"
|
|
1831
1831
|
}
|
|
1832
1832
|
random = {
|
|
1833
1833
|
source = "hashicorp/random"
|
|
@@ -2083,7 +2083,7 @@ output "waf_web_acl_arn" {
|
|
|
2083
2083
|
required_providers {
|
|
2084
2084
|
aws = {
|
|
2085
2085
|
source = "hashicorp/aws"
|
|
2086
|
-
version = "6.
|
|
2086
|
+
version = "6.54.0"
|
|
2087
2087
|
}
|
|
2088
2088
|
}
|
|
2089
2089
|
}
|
|
@@ -2774,7 +2774,7 @@ terraform {
|
|
|
2774
2774
|
required_providers {
|
|
2775
2775
|
aws = {
|
|
2776
2776
|
source = "hashicorp/aws"
|
|
2777
|
-
version = "6.
|
|
2777
|
+
version = "6.54.0"
|
|
2778
2778
|
}
|
|
2779
2779
|
random = {
|
|
2780
2780
|
source = "hashicorp/random"
|
|
@@ -3030,7 +3030,7 @@ output "waf_web_acl_arn" {
|
|
|
3030
3030
|
required_providers {
|
|
3031
3031
|
aws = {
|
|
3032
3032
|
source = "hashicorp/aws"
|
|
3033
|
-
version = "6.
|
|
3033
|
+
version = "6.54.0"
|
|
3034
3034
|
}
|
|
3035
3035
|
}
|
|
3036
3036
|
}
|
|
@@ -3706,7 +3706,7 @@ exports[`tsSmithyApiGenerator > terraform iac > should generate terraform with c
|
|
|
3706
3706
|
required_providers {
|
|
3707
3707
|
aws = {
|
|
3708
3708
|
source = "hashicorp/aws"
|
|
3709
|
-
version = "6.
|
|
3709
|
+
version = "6.54.0"
|
|
3710
3710
|
}
|
|
3711
3711
|
}
|
|
3712
3712
|
}
|
|
@@ -10,8 +10,8 @@ import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
|
|
|
10
10
|
import { Logger } from '@aws-lambda-powertools/logger';
|
|
11
11
|
import { Metrics } from '@aws-lambda-powertools/metrics';
|
|
12
12
|
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
|
|
13
|
-
import { Service } from './service
|
|
14
|
-
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index
|
|
13
|
+
import { Service } from './service<% if (esm) { %>.js<% } %>';
|
|
14
|
+
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index<% if (esm) { %>.js<% } %>';
|
|
15
15
|
|
|
16
16
|
process.env.POWERTOOLS_METRICS_NAMESPACE = '<%- apiNameClassName %>';
|
|
17
17
|
process.env.POWERTOOLS_SERVICE_NAME = '<%- apiNameClassName %>';
|
|
@@ -3,8 +3,8 @@ import { convertRequest, writeResponse } from '@aws-smithy/server-node';
|
|
|
3
3
|
import { Logger } from '@aws-lambda-powertools/logger';
|
|
4
4
|
import { Metrics } from '@aws-lambda-powertools/metrics';
|
|
5
5
|
import { Tracer } from '@aws-lambda-powertools/tracer';
|
|
6
|
-
import { Service } from './service
|
|
7
|
-
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index
|
|
6
|
+
import { Service } from './service<% if (esm) { %>.js<% } %>';
|
|
7
|
+
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index<% if (esm) { %>.js<% } %>';
|
|
8
8
|
|
|
9
9
|
const PORT = <%- port %>;
|
|
10
10
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ServiceContext } from "../context
|
|
2
|
-
import { Echo as EchoOperation } from "../generated/ssdk/index
|
|
1
|
+
import { ServiceContext } from "../context<% if (esm) { %>.js<% } %>";
|
|
2
|
+
import { Echo as EchoOperation } from "../generated/ssdk/index<% if (esm) { %>.js<% } %>";
|
|
3
3
|
|
|
4
4
|
export const Echo: EchoOperation<ServiceContext> = async (input, ctx) => {
|
|
5
5
|
ctx.logger.info('Starting Echo operation');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ServiceContext } from './context
|
|
2
|
-
import { <%- apiNameClassName %>Service } from './generated/ssdk/index
|
|
3
|
-
import { Echo } from './operations/echo
|
|
1
|
+
import { ServiceContext } from './context<% if (esm) { %>.js<% } %>';
|
|
2
|
+
import { <%- apiNameClassName %>Service } from './generated/ssdk/index<% if (esm) { %>.js<% } %>';
|
|
3
|
+
import { Echo } from './operations/echo<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
// Register operations to the service here
|
|
6
6
|
export const Service: <%- apiNameClassName %>Service<ServiceContext> = {
|
|
@@ -12,6 +12,7 @@ import { updateGitIgnore } from "../../../utils/git.js";
|
|
|
12
12
|
import { resolveIac } from "../../../utils/iac.js";
|
|
13
13
|
import { installDependencies } from "../../../utils/install.js";
|
|
14
14
|
import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
|
|
15
|
+
import { esmVars } from "../../../utils/module-format.js";
|
|
15
16
|
import { toClassName, toKebabCase } from "../../../utils/names.js";
|
|
16
17
|
import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo, normalizeTargetKeyOrder, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
|
|
17
18
|
import { assignPort } from "../../../utils/port.js";
|
|
@@ -73,7 +74,8 @@ export const tsSmithyApiGenerator = async (tree, options)=>{
|
|
|
73
74
|
tree.delete(joinPathFragments(backendProjectConfig.sourceRoot, 'index.ts'));
|
|
74
75
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), backendProjectConfig.sourceRoot, {
|
|
75
76
|
apiNameClassName,
|
|
76
|
-
port
|
|
77
|
+
port,
|
|
78
|
+
...esmVars(tree)
|
|
77
79
|
});
|
|
78
80
|
if (options.infra !== 'none') {
|
|
79
81
|
if (options.auth === 'custom') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/smithy/ts/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 addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator, { getTsLibDetails } from '../../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../../utils/api-constructs/api-constructs';\nimport { addSharedConstructsOpenApiMetadataGenerateTarget } from '../../../utils/api-constructs/open-api-metadata';\nimport { addTypeScriptBundleTarget } from '../../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { FsCommands } from '../../../utils/fs';\nimport { updateGitIgnore } from '../../../utils/git';\nimport { resolveIac } from '../../../utils/iac';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../../utils/names';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n normalizeTargetKeyOrder,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { assignPort } from '../../../utils/port';\nimport { sharedConstructsGenerator } from '../../../utils/shared-constructs';\nimport { withVersions } from '../../../utils/versions';\nimport smithyProjectGenerator from '../../project/generator';\nimport type { TsSmithyApiGeneratorSchema } from './schema';\n\nexport const TS_SMITHY_API_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsSmithyApiGenerator = async (\n tree: Tree,\n options: TsSmithyApiGeneratorSchema,\n): Promise<GeneratorCallback> => {\n if (\n (options.infra as string) !== 'rest-lambda' &&\n (options.infra as string) !== 'none'\n ) {\n throw new Error(\n `Unsupported infra '${options.infra}' for Smithy TypeScript API. ` +\n `Only 'rest-lambda' (API Gateway REST API) is supported.`,\n );\n }\n\n const integrationPattern = getIntegrationPattern(options);\n const apiNameClassName = toClassName(options.name);\n const apiNameKebabCase = toKebabCase(options.name);\n const { fullyQualifiedName: backendFullyQualifiedName, dir } =\n getTsLibDetails(tree, options);\n const modelProjectName = `${apiNameKebabCase}-model`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendFullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n // Generate the model project\n await smithyProjectGenerator(tree, {\n name: modelProjectName,\n serviceName: apiNameClassName,\n namespace: options.namespace,\n directory: dir,\n subDirectory: 'model',\n preferInstallDependencies: false,\n });\n\n // Generate the backend project\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: dir,\n subDirectory: 'backend',\n preferInstallDependencies: false,\n });\n }\n\n // Add metadata to associate backend project with model project\n const modelProjectConfig = readProjectConfigurationUnqualified(\n tree,\n modelProjectName,\n );\n updateProjectConfiguration(tree, modelProjectConfig.name, {\n ...modelProjectConfig,\n metadata: {\n ...modelProjectConfig.metadata,\n backendProject: backendFullyQualifiedName,\n } as any,\n });\n\n addGeneratorMetadata(\n tree,\n backendFullyQualifiedName,\n TS_SMITHY_API_GENERATOR_INFO,\n {\n apiName: options.name,\n auth: options.auth,\n modelProject: modelProjectConfig.name,\n },\n );\n\n const backendProjectConfig = readProjectConfigurationUnqualified(\n tree,\n backendFullyQualifiedName,\n );\n const port = assignPort(tree, backendProjectConfig, 3001);\n\n // Delete default index.ts with \"hello\" function\n tree.delete(joinPathFragments(backendProjectConfig.sourceRoot, 'index.ts'));\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendProjectConfig.sourceRoot,\n {\n apiNameClassName,\n port,\n },\n );\n\n if (options.infra !== 'none') {\n if (options.auth === 'custom') {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n 'rest',\n ),\n backendProjectConfig.sourceRoot,\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Add infrastructure\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, {\n iac,\n });\n await addApiGatewayInfra(tree, {\n iac,\n apiProjectName: backendFullyQualifiedName,\n apiNameClassName,\n apiNameKebabCase,\n auth: options.auth,\n constructType: 'rest',\n backend: {\n type: 'smithy',\n bundleOutputDir: joinPathFragments(\n 'dist',\n backendProjectConfig.root,\n 'bundle',\n ),\n integrationPattern,\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendProjectConfig.root,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n });\n addSharedConstructsOpenApiMetadataGenerateTarget(tree, {\n iac,\n apiNameKebabCase,\n specPath: joinPathFragments(\n 'dist',\n modelProjectConfig.root,\n 'build',\n 'openapi',\n 'openapi.json',\n ),\n specBuildTargetName: `${modelProjectConfig.name}:build`,\n });\n\n // Add bundle target using rolldown\n await addTypeScriptBundleTarget(tree, backendProjectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, backendProjectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n }\n\n const cmd = new FsCommands(tree);\n const generatedSrcDirFromRoot = '{projectRoot}/src/generated';\n\n // Target for copying the ssdk built by the model\n backendProjectConfig.targets['copy-ssdk'] = {\n cache: true,\n inputs: [\n {\n dependentTasksOutputFiles: '**/*',\n },\n ],\n executor: 'nx:run-commands',\n options: {\n commands: [\n cmd.rm(generatedSrcDirFromRoot),\n cmd.mkdir(generatedSrcDirFromRoot),\n cmd.cp(\n joinPathFragments('dist', modelProjectConfig.root, 'build', 'ssdk'),\n joinPathFragments(generatedSrcDirFromRoot, 'ssdk'),\n ),\n ],\n parallel: false,\n },\n outputs: ['{projectRoot}/src/generated'],\n dependsOn: [`${modelProjectConfig.name}:build`],\n };\n addDependencyToTargetIfNotPresent(\n backendProjectConfig,\n 'compile',\n 'copy-ssdk',\n );\n\n // Add a project which continuously copies based on changes to the model project\n // This allows the \"serve\" target to hot reload when the smithy model is changed\n backendProjectConfig.targets['watch-copy-ssdk'] = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n command: `nx watch --projects=${modelProjectConfig.name} --includeDependencies -- nx run ${backendFullyQualifiedName}:copy-ssdk`,\n },\n };\n\n // Add serve target for running the server locally\n backendProjectConfig.targets.serve = normalizeTargetKeyOrder({\n executor: 'nx:run-commands',\n continuous: true,\n dependsOn: ['copy-ssdk', 'watch-copy-ssdk'],\n options: {\n command: 'tsx --watch src/local-server.ts',\n cwd: '{projectRoot}',\n },\n });\n\n const existingDevDependsOn =\n backendProjectConfig.targets['dev']?.dependsOn ?? [];\n\n backendProjectConfig.targets['dev'] = normalizeTargetKeyOrder({\n ...backendProjectConfig.targets.serve,\n // Own copy of dependsOn so adding dev dependencies below doesn't\n // mutate the shared array referenced by the serve target.\n dependsOn: [...(backendProjectConfig.targets.serve.dependsOn ?? [])],\n options: {\n ...backendProjectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n });\n\n // Preserve any dependencies added to dev by connection generators\n for (const dependency of existingDevDependsOn) {\n addDependencyToTargetIfNotPresent(backendProjectConfig, 'dev', dependency);\n }\n\n // Ignore generated code\n updateGitIgnore(tree, backendProjectConfig.root, (patterns) => [\n ...patterns,\n 'src/generated',\n ]);\n\n updateProjectConfiguration(\n tree,\n backendFullyQualifiedName,\n backendProjectConfig,\n );\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-smithy/server-apigateway',\n '@aws-smithy/server-node',\n '@middy/core',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-lambda-powertools/metrics',\n '@aws-sdk/client-appconfigdata',\n ...(options.auth === 'custom'\n ? (['@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx']),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_SMITHY_API_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nconst getIntegrationPattern = (\n options: TsSmithyApiGeneratorSchema,\n): 'isolated' | 'shared' => options.integrationPattern ?? 'isolated';\n\nexport default tsSmithyApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","getTsLibDetails","addApiGatewayInfra","addSharedConstructsOpenApiMetadataGenerateTarget","addTypeScriptBundleTarget","formatFilesInSubtree","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","normalizeTargetKeyOrder","readProjectConfigurationUnqualified","assignPort","sharedConstructsGenerator","withVersions","smithyProjectGenerator","TS_SMITHY_API_GENERATOR_INFO","filename","tsSmithyApiGenerator","tree","options","infra","Error","integrationPattern","getIntegrationPattern","apiNameClassName","name","apiNameKebabCase","fullyQualifiedName","backendFullyQualifiedName","dir","modelProjectName","projectExists","serviceName","namespace","directory","subDirectory","preferInstallDependencies","modelProjectConfig","metadata","backendProject","apiName","auth","modelProject","backendProjectConfig","port","delete","sourceRoot","dirname","overwriteStrategy","KeepExisting","iac","apiProjectName","constructType","backend","type","bundleOutputDir","root","authorizerBundleOutputDir","specPath","specBuildTargetName","targetFilePath","external","cmd","generatedSrcDirFromRoot","targets","cache","inputs","dependentTasksOutputFiles","executor","commands","rm","mkdir","cp","parallel","outputs","dependsOn","continuous","command","serve","cwd","existingDevDependsOn","env","LOCAL_DEV","dependency","patterns","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,sBAAsBC,eAAe,QAAQ,+BAA4B;AAChF,SAASC,kBAAkB,QAAQ,kDAA+C;AAClF,SAASC,gDAAgD,QAAQ,qDAAkD;AACnH,SAASC,yBAAyB,QAAQ,kCAA+B;AACzE,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,UAAU,QAAQ,uBAAoB;AAC/C,SAASC,eAAe,QAAQ,wBAAqB;AACrD,SAASC,UAAU,QAAQ,wBAAqB;AAChD,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,WAAW,EAAEC,WAAW,QAAQ,0BAAuB;AAChE,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,uBAAuB,EACvBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,UAAU,QAAQ,yBAAsB;AACjD,SAASC,yBAAyB,QAAQ,sCAAmC;AAC7E,SAASC,YAAY,QAAQ,6BAA0B;AACvD,OAAOC,4BAA4B,6BAA0B;AAG7D,OAAO,MAAMC,+BAAgDP,iBAC3D,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,uBAAuB,OAClCC,MACAC;IAEA,IACE,AAACA,QAAQC,KAAK,KAAgB,iBAC9B,AAACD,QAAQC,KAAK,KAAgB,QAC9B;QACA,MAAM,IAAIC,MACR,CAAC,mBAAmB,E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S;YACP,GAAGwB,qBAAqBqB,OAAO,CAACc,KAAK,CAAC3D,OAAO;YAC7C8D,KAAK;gBACHC,WAAW;YACb;QACF;IACF;IAEA,kEAAkE;IAClE,KAAK,MAAMC,cAAcH,qBAAsB;QAC7C1E,kCAAkCqC,sBAAsB,OAAOwC;IACjE;IAEA,wBAAwB;IACxBnF,gBAAgBkB,MAAMyB,qBAAqBa,IAAI,EAAE,CAAC4B,WAAa;eAC1DA;YACH;SACD;IAED5F,2BACE0B,MACAU,2BACAe;IAGFvD,6BACE8B,MACAL,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;QACA;QACA;WACIM,QAAQsB,IAAI,KAAK,WAChB;YAAC;SAAgC,GAClC,EAAE;KACP,GACD5B,aAAa;QAAC;QAAqB;KAAM;IAG3C,MAAMV,gCAAgCe,MAAM;QAACH;KAA6B;IAE1E,MAAMjB,qBAAqBoB;IAC3B,OAAO,IACLhB,oBAAoBgB,MAAMC,QAAQiB,yBAAyB,EAAE;YAC3DiD,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,MAAM9D,wBAAwB,CAC5BJ,UAC0BA,QAAQG,kBAAkB,IAAI;AAE1D,eAAeL,qBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/smithy/ts/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 addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator, { getTsLibDetails } from '../../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../../utils/api-constructs/api-constructs';\nimport { addSharedConstructsOpenApiMetadataGenerateTarget } from '../../../utils/api-constructs/open-api-metadata';\nimport { addTypeScriptBundleTarget } from '../../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { FsCommands } from '../../../utils/fs';\nimport { updateGitIgnore } from '../../../utils/git';\nimport { resolveIac } from '../../../utils/iac';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { toClassName, toKebabCase } from '../../../utils/names';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n normalizeTargetKeyOrder,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { assignPort } from '../../../utils/port';\nimport { sharedConstructsGenerator } from '../../../utils/shared-constructs';\nimport { withVersions } from '../../../utils/versions';\nimport smithyProjectGenerator from '../../project/generator';\nimport type { TsSmithyApiGeneratorSchema } from './schema';\n\nexport const TS_SMITHY_API_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsSmithyApiGenerator = async (\n tree: Tree,\n options: TsSmithyApiGeneratorSchema,\n): Promise<GeneratorCallback> => {\n if (\n (options.infra as string) !== 'rest-lambda' &&\n (options.infra as string) !== 'none'\n ) {\n throw new Error(\n `Unsupported infra '${options.infra}' for Smithy TypeScript API. ` +\n `Only 'rest-lambda' (API Gateway REST API) is supported.`,\n );\n }\n\n const integrationPattern = getIntegrationPattern(options);\n const apiNameClassName = toClassName(options.name);\n const apiNameKebabCase = toKebabCase(options.name);\n const { fullyQualifiedName: backendFullyQualifiedName, dir } =\n getTsLibDetails(tree, options);\n const modelProjectName = `${apiNameKebabCase}-model`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendFullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n // Generate the model project\n await smithyProjectGenerator(tree, {\n name: modelProjectName,\n serviceName: apiNameClassName,\n namespace: options.namespace,\n directory: dir,\n subDirectory: 'model',\n preferInstallDependencies: false,\n });\n\n // Generate the backend project\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: dir,\n subDirectory: 'backend',\n preferInstallDependencies: false,\n });\n }\n\n // Add metadata to associate backend project with model project\n const modelProjectConfig = readProjectConfigurationUnqualified(\n tree,\n modelProjectName,\n );\n updateProjectConfiguration(tree, modelProjectConfig.name, {\n ...modelProjectConfig,\n metadata: {\n ...modelProjectConfig.metadata,\n backendProject: backendFullyQualifiedName,\n } as any,\n });\n\n addGeneratorMetadata(\n tree,\n backendFullyQualifiedName,\n TS_SMITHY_API_GENERATOR_INFO,\n {\n apiName: options.name,\n auth: options.auth,\n modelProject: modelProjectConfig.name,\n },\n );\n\n const backendProjectConfig = readProjectConfigurationUnqualified(\n tree,\n backendFullyQualifiedName,\n );\n const port = assignPort(tree, backendProjectConfig, 3001);\n\n // Delete default index.ts with \"hello\" function\n tree.delete(joinPathFragments(backendProjectConfig.sourceRoot, 'index.ts'));\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendProjectConfig.sourceRoot,\n {\n apiNameClassName,\n port,\n ...esmVars(tree),\n },\n );\n\n if (options.infra !== 'none') {\n if (options.auth === 'custom') {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n 'rest',\n ),\n backendProjectConfig.sourceRoot,\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Add infrastructure\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, {\n iac,\n });\n await addApiGatewayInfra(tree, {\n iac,\n apiProjectName: backendFullyQualifiedName,\n apiNameClassName,\n apiNameKebabCase,\n auth: options.auth,\n constructType: 'rest',\n backend: {\n type: 'smithy',\n bundleOutputDir: joinPathFragments(\n 'dist',\n backendProjectConfig.root,\n 'bundle',\n ),\n integrationPattern,\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendProjectConfig.root,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n });\n addSharedConstructsOpenApiMetadataGenerateTarget(tree, {\n iac,\n apiNameKebabCase,\n specPath: joinPathFragments(\n 'dist',\n modelProjectConfig.root,\n 'build',\n 'openapi',\n 'openapi.json',\n ),\n specBuildTargetName: `${modelProjectConfig.name}:build`,\n });\n\n // Add bundle target using rolldown\n await addTypeScriptBundleTarget(tree, backendProjectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, backendProjectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n }\n\n const cmd = new FsCommands(tree);\n const generatedSrcDirFromRoot = '{projectRoot}/src/generated';\n\n // Target for copying the ssdk built by the model\n backendProjectConfig.targets['copy-ssdk'] = {\n cache: true,\n inputs: [\n {\n dependentTasksOutputFiles: '**/*',\n },\n ],\n executor: 'nx:run-commands',\n options: {\n commands: [\n cmd.rm(generatedSrcDirFromRoot),\n cmd.mkdir(generatedSrcDirFromRoot),\n cmd.cp(\n joinPathFragments('dist', modelProjectConfig.root, 'build', 'ssdk'),\n joinPathFragments(generatedSrcDirFromRoot, 'ssdk'),\n ),\n ],\n parallel: false,\n },\n outputs: ['{projectRoot}/src/generated'],\n dependsOn: [`${modelProjectConfig.name}:build`],\n };\n addDependencyToTargetIfNotPresent(\n backendProjectConfig,\n 'compile',\n 'copy-ssdk',\n );\n\n // Add a project which continuously copies based on changes to the model project\n // This allows the \"serve\" target to hot reload when the smithy model is changed\n backendProjectConfig.targets['watch-copy-ssdk'] = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n command: `nx watch --projects=${modelProjectConfig.name} --includeDependencies -- nx run ${backendFullyQualifiedName}:copy-ssdk`,\n },\n };\n\n // Add serve target for running the server locally\n backendProjectConfig.targets.serve = normalizeTargetKeyOrder({\n executor: 'nx:run-commands',\n continuous: true,\n dependsOn: ['copy-ssdk', 'watch-copy-ssdk'],\n options: {\n command: 'tsx --watch src/local-server.ts',\n cwd: '{projectRoot}',\n },\n });\n\n const existingDevDependsOn =\n backendProjectConfig.targets['dev']?.dependsOn ?? [];\n\n backendProjectConfig.targets['dev'] = normalizeTargetKeyOrder({\n ...backendProjectConfig.targets.serve,\n // Own copy of dependsOn so adding dev dependencies below doesn't\n // mutate the shared array referenced by the serve target.\n dependsOn: [...(backendProjectConfig.targets.serve.dependsOn ?? [])],\n options: {\n ...backendProjectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n });\n\n // Preserve any dependencies added to dev by connection generators\n for (const dependency of existingDevDependsOn) {\n addDependencyToTargetIfNotPresent(backendProjectConfig, 'dev', dependency);\n }\n\n // Ignore generated code\n updateGitIgnore(tree, backendProjectConfig.root, (patterns) => [\n ...patterns,\n 'src/generated',\n ]);\n\n updateProjectConfiguration(\n tree,\n backendFullyQualifiedName,\n backendProjectConfig,\n );\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-smithy/server-apigateway',\n '@aws-smithy/server-node',\n '@middy/core',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-lambda-powertools/metrics',\n '@aws-sdk/client-appconfigdata',\n ...(options.auth === 'custom'\n ? (['@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx']),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_SMITHY_API_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nconst getIntegrationPattern = (\n options: TsSmithyApiGeneratorSchema,\n): 'isolated' | 'shared' => options.integrationPattern ?? 'isolated';\n\nexport default tsSmithyApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","getTsLibDetails","addApiGatewayInfra","addSharedConstructsOpenApiMetadataGenerateTarget","addTypeScriptBundleTarget","formatFilesInSubtree","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","toClassName","toKebabCase","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","normalizeTargetKeyOrder","readProjectConfigurationUnqualified","assignPort","sharedConstructsGenerator","withVersions","smithyProjectGenerator","TS_SMITHY_API_GENERATOR_INFO","filename","tsSmithyApiGenerator","tree","options","infra","Error","integrationPattern","getIntegrationPattern","apiNameClassName","name","apiNameKebabCase","fullyQualifiedName","backendFullyQualifiedName","dir","modelProjectName","projectExists","serviceName","namespace","directory","subDirectory","preferInstallDependencies","modelProjectConfig","metadata","backendProject","apiName","auth","modelProject","backendProjectConfig","port","delete","sourceRoot","dirname","overwriteStrategy","KeepExisting","iac","apiProjectName","constructType","backend","type","bundleOutputDir","root","authorizerBundleOutputDir","specPath","specBuildTargetName","targetFilePath","external","cmd","generatedSrcDirFromRoot","targets","cache","inputs","dependentTasksOutputFiles","executor","commands","rm","mkdir","cp","parallel","outputs","dependsOn","continuous","command","serve","cwd","existingDevDependsOn","env","LOCAL_DEV","dependency","patterns","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,sBAAsBC,eAAe,QAAQ,+BAA4B;AAChF,SAASC,kBAAkB,QAAQ,kDAA+C;AAClF,SAASC,gDAAgD,QAAQ,qDAAkD;AACnH,SAASC,yBAAyB,QAAQ,kCAA+B;AACzE,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,UAAU,QAAQ,uBAAoB;AAC/C,SAASC,eAAe,QAAQ,wBAAqB;AACrD,SAASC,UAAU,QAAQ,wBAAqB;AAChD,SAASC,mBAAmB,QAAQ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,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,MAAM9D,wBAAwB,CAC5BJ,UAC0BA,QAAQG,kBAAkB,IAAI;AAE1D,eAAeL,qBAAqB"}
|
|
@@ -3142,7 +3142,7 @@ terraform {
|
|
|
3142
3142
|
required_providers {
|
|
3143
3143
|
aws = {
|
|
3144
3144
|
source = "hashicorp/aws"
|
|
3145
|
-
version = "6.
|
|
3145
|
+
version = "6.54.0"
|
|
3146
3146
|
}
|
|
3147
3147
|
}
|
|
3148
3148
|
}
|
|
@@ -3389,7 +3389,7 @@ output "api_log_group_arn" {
|
|
|
3389
3389
|
required_providers {
|
|
3390
3390
|
aws = {
|
|
3391
3391
|
source = "hashicorp/aws"
|
|
3392
|
-
version = "6.
|
|
3392
|
+
version = "6.54.0"
|
|
3393
3393
|
}
|
|
3394
3394
|
}
|
|
3395
3395
|
}
|
|
@@ -3856,7 +3856,7 @@ terraform {
|
|
|
3856
3856
|
required_providers {
|
|
3857
3857
|
aws = {
|
|
3858
3858
|
source = "hashicorp/aws"
|
|
3859
|
-
version = "6.
|
|
3859
|
+
version = "6.54.0"
|
|
3860
3860
|
}
|
|
3861
3861
|
}
|
|
3862
3862
|
}
|
|
@@ -4103,7 +4103,7 @@ output "api_log_group_arn" {
|
|
|
4103
4103
|
required_providers {
|
|
4104
4104
|
aws = {
|
|
4105
4105
|
source = "hashicorp/aws"
|
|
4106
|
-
version = "6.
|
|
4106
|
+
version = "6.54.0"
|
|
4107
4107
|
}
|
|
4108
4108
|
}
|
|
4109
4109
|
}
|
|
@@ -4642,7 +4642,7 @@ terraform {
|
|
|
4642
4642
|
required_providers {
|
|
4643
4643
|
aws = {
|
|
4644
4644
|
source = "hashicorp/aws"
|
|
4645
|
-
version = "6.
|
|
4645
|
+
version = "6.54.0"
|
|
4646
4646
|
}
|
|
4647
4647
|
}
|
|
4648
4648
|
}
|
|
@@ -4889,7 +4889,7 @@ output "api_log_group_arn" {
|
|
|
4889
4889
|
required_providers {
|
|
4890
4890
|
aws = {
|
|
4891
4891
|
source = "hashicorp/aws"
|
|
4892
|
-
version = "6.
|
|
4892
|
+
version = "6.54.0"
|
|
4893
4893
|
}
|
|
4894
4894
|
}
|
|
4895
4895
|
}
|
|
@@ -5333,7 +5333,7 @@ terraform {
|
|
|
5333
5333
|
required_providers {
|
|
5334
5334
|
aws = {
|
|
5335
5335
|
source = "hashicorp/aws"
|
|
5336
|
-
version = "6.
|
|
5336
|
+
version = "6.54.0"
|
|
5337
5337
|
}
|
|
5338
5338
|
random = {
|
|
5339
5339
|
source = "hashicorp/random"
|
|
@@ -5589,7 +5589,7 @@ output "waf_web_acl_arn" {
|
|
|
5589
5589
|
required_providers {
|
|
5590
5590
|
aws = {
|
|
5591
5591
|
source = "hashicorp/aws"
|
|
5592
|
-
version = "6.
|
|
5592
|
+
version = "6.54.0"
|
|
5593
5593
|
}
|
|
5594
5594
|
}
|
|
5595
5595
|
}
|
|
@@ -6281,7 +6281,7 @@ terraform {
|
|
|
6281
6281
|
required_providers {
|
|
6282
6282
|
aws = {
|
|
6283
6283
|
source = "hashicorp/aws"
|
|
6284
|
-
version = "6.
|
|
6284
|
+
version = "6.54.0"
|
|
6285
6285
|
}
|
|
6286
6286
|
random = {
|
|
6287
6287
|
source = "hashicorp/random"
|
|
@@ -6537,7 +6537,7 @@ output "waf_web_acl_arn" {
|
|
|
6537
6537
|
required_providers {
|
|
6538
6538
|
aws = {
|
|
6539
6539
|
source = "hashicorp/aws"
|
|
6540
|
-
version = "6.
|
|
6540
|
+
version = "6.54.0"
|
|
6541
6541
|
}
|
|
6542
6542
|
}
|
|
6543
6543
|
}
|
|
@@ -7218,7 +7218,7 @@ terraform {
|
|
|
7218
7218
|
required_providers {
|
|
7219
7219
|
aws = {
|
|
7220
7220
|
source = "hashicorp/aws"
|
|
7221
|
-
version = "6.
|
|
7221
|
+
version = "6.54.0"
|
|
7222
7222
|
}
|
|
7223
7223
|
random = {
|
|
7224
7224
|
source = "hashicorp/random"
|
|
@@ -7474,7 +7474,7 @@ output "waf_web_acl_arn" {
|
|
|
7474
7474
|
required_providers {
|
|
7475
7475
|
aws = {
|
|
7476
7476
|
source = "hashicorp/aws"
|
|
7477
|
-
version = "6.
|
|
7477
|
+
version = "6.54.0"
|
|
7478
7478
|
}
|
|
7479
7479
|
}
|
|
7480
7480
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { AwsClient } from 'aws4fetch';
|
|
8
8
|
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
9
9
|
<%_ } _%>
|
|
10
|
-
import { AppRouter } from "../router
|
|
10
|
+
import { AppRouter } from "../router<% if (esm) { %>.js<% } %>";
|
|
11
11
|
|
|
12
12
|
<%_ if (auth === 'iam') { %>
|
|
13
13
|
const credentialProvider = fromNodeProviderChain();
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
<%_ } _%>
|
|
8
8
|
} from '@trpc/server/adapters/aws-lambda';
|
|
9
9
|
import type { <%- apiGatewayEventType %> } from 'aws-lambda';
|
|
10
|
-
import { appRouter } from './router
|
|
10
|
+
import { appRouter } from './router<% if (esm) { %>.js<% } %>';
|
|
11
11
|
|
|
12
12
|
<%_ if (infra === 'rest-lambda') { _%>
|
|
13
13
|
export const handler = awslambda.streamifyResponse(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { AppRouter } from './router
|
|
2
|
-
export { appRouter } from './router
|
|
3
|
-
export type { Context } from './init
|
|
4
|
-
export * from './client/index
|
|
5
|
-
export * from './schema/index
|
|
1
|
+
export type { AppRouter } from './router<% if (esm) { %>.js<% } %>';
|
|
2
|
+
export { appRouter } from './router<% if (esm) { %>.js<% } %>';
|
|
3
|
+
export type { Context } from './init<% if (esm) { %>.js<% } %>';
|
|
4
|
+
export * from './client/index<% if (esm) { %>.js<% } %>';
|
|
5
|
+
export * from './schema/index<% if (esm) { %>.js<% } %>';
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createMetricsPlugin,
|
|
6
6
|
createTracerPlugin,
|
|
7
7
|
IMiddlewareContext,
|
|
8
|
-
} from './middleware/index
|
|
8
|
+
} from './middleware/index<% if (esm) { %>.js<% } %>';
|
|
9
9
|
|
|
10
10
|
process.env.POWERTOOLS_SERVICE_NAME = '<%= apiNameClassName %>';
|
|
11
11
|
process.env.POWERTOOLS_METRICS_NAMESPACE = '<%= apiNameClassName %>';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { CreateAWSLambdaContextOptions } from '@trpc/server/adapters/aws-lambda';
|
|
2
2
|
import type { <%- apiGatewayEventType %> } from 'aws-lambda';
|
|
3
|
-
import { ILoggerContext } from './logger
|
|
4
|
-
import { IMetricsContext } from './metrics
|
|
5
|
-
import { ITracerContext } from './tracer
|
|
3
|
+
import { ILoggerContext } from './logger<% if (esm) { %>.js<% } %>';
|
|
4
|
+
import { IMetricsContext } from './metrics<% if (esm) { %>.js<% } %>';
|
|
5
|
+
import { ITracerContext } from './tracer<% if (esm) { %>.js<% } %>';
|
|
6
6
|
|
|
7
|
-
export * from './logger
|
|
8
|
-
export * from './metrics
|
|
9
|
-
export * from './tracer
|
|
10
|
-
export * from './error
|
|
7
|
+
export * from './logger<% if (esm) { %>.js<% } %>';
|
|
8
|
+
export * from './metrics<% if (esm) { %>.js<% } %>';
|
|
9
|
+
export * from './tracer<% if (esm) { %>.js<% } %>';
|
|
10
|
+
export * from './error<% if (esm) { %>.js<% } %>';
|
|
11
11
|
|
|
12
12
|
export type IMiddlewareContext = CreateAWSLambdaContextOptions<<%- apiGatewayEventType %>>
|
|
13
13
|
& ILoggerContext
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { publicProcedure } from '../init
|
|
2
|
-
import { EchoInputSchema, EchoOutputSchema } from '../schema/index
|
|
1
|
+
import { publicProcedure } from '../init<% if (esm) { %>.js<% } %>';
|
|
2
|
+
import { EchoInputSchema, EchoOutputSchema } from '../schema/index<% if (esm) { %>.js<% } %>';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const echo = publicProcedure
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './echo
|
|
1
|
+
export * from './echo<% if (esm) { %>.js<% } %>';
|
|
@@ -9,6 +9,7 @@ import { formatFilesInSubtree } from "../../utils/format.js";
|
|
|
9
9
|
import { resolveIac } from "../../utils/iac.js";
|
|
10
10
|
import { installDependencies } from "../../utils/install.js";
|
|
11
11
|
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
12
|
+
import { esmVars } from "../../utils/module-format.js";
|
|
12
13
|
import { kebabCase, toClassName } from "../../utils/names.js";
|
|
13
14
|
import { getNpmScopePrefix, toScopeAlias } from "../../utils/npm-scope.js";
|
|
14
15
|
import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
@@ -62,7 +63,8 @@ export async function tsTrpcApiGenerator(tree, options) {
|
|
|
62
63
|
pkgMgrCmd: getPackageManagerDisplayCommands().exec,
|
|
63
64
|
apiGatewayEventType: getApiGatewayEventType(options),
|
|
64
65
|
port,
|
|
65
|
-
...options
|
|
66
|
+
...options,
|
|
67
|
+
...esmVars(tree)
|
|
66
68
|
};
|
|
67
69
|
if (options.infra !== 'none') {
|
|
68
70
|
const iac = await resolveIac(tree, options.iac);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../utils/api-constructs/api-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScopePrefix, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: toScopeAlias(backendProjectName),\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n };\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addApiGatewayInfra(tree, {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n });\n }\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\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 if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.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 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'aws-xray-sdk-core',\n 'zod',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/metrics',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-sdk/client-appconfigdata',\n '@trpc/server',\n '@trpc/client',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ...(options.auth === 'custom'\n ? (['@middy/core', '@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx', 'cors', '@types/cors']),\n );\n tree.delete(joinPathFragments(backendRoot, 'package.json'));\n\n addGeneratorMetadata(tree, backendName, TRPC_BACKEND_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addApiGatewayInfra","addTypeScriptBundleTarget","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","sharedConstructsGenerator","withVersions","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","infra","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","name","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","root","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","iac","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","auth","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,4BAAyB;AACxD,SAASC,kBAAkB,QAAQ,+CAA4C;AAC/E,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,2BAAwB;AACxE,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,gCAAgC,QAAQ,6BAA0B;AAC3E,SAASC,UAAU,QAAQ,sBAAmB;AAC9C,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SAASC,YAAY,QAAQ,0BAAuB;AAGpD,OAAO,MAAMC,8BAA+CP,iBAC1D,YAAYQ,QAAQ,EACpB;AAEF,MAAMC,sCAAsC,IAAIC,IAAI;IAClD;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,eAAeC,mBACpBC,IAAU,EACVC,OAAiC;IAEjC,IAAIA,QAAQC,KAAK,KAAK,QAAQ;QAC5BC,kDAAkDF;IACpD;IAEA,MAAMG,eAAepB,kBAAkBgB;IACvC,MAAMK,mBAAmBvB,UAAUmB,QAAQK,IAAI;IAC/C,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OAAO;IACT;IACA,IAAID,QAAQgC,IAAI,KAAK,OAAO;QAC1B,OAAO;IACT,OAAO,IAAIhC,QAAQgC,IAAI,KAAK,WAAW;QACrC,OAAO;IACT;IACA,OAAO;AACT;AAEA,eAAelC,mBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../utils/api-constructs/api-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScopePrefix, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: toScopeAlias(backendProjectName),\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n ...esmVars(tree),\n };\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addApiGatewayInfra(tree, {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n });\n }\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\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 if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.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 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'aws-xray-sdk-core',\n 'zod',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/metrics',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-sdk/client-appconfigdata',\n '@trpc/server',\n '@trpc/client',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ...(options.auth === 'custom'\n ? (['@middy/core', '@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx', 'cors', '@types/cors']),\n );\n tree.delete(joinPathFragments(backendRoot, 'package.json'));\n\n addGeneratorMetadata(tree, backendName, TRPC_BACKEND_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addApiGatewayInfra","addTypeScriptBundleTarget","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScopePrefix","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","sharedConstructsGenerator","withVersions","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","infra","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","name","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","root","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","iac","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","auth","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,4BAAyB;AACxD,SAASC,kBAAkB,QAAQ,+CAA4C;AAC/E,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SA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