@aws/nx-plugin 0.80.1 → 0.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-THIRD-PARTY +28 -299
- package/package.json +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +368 -86
- package/src/py/fast-api/generator.js +3 -0
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/schema.d.ts +1 -0
- package/src/py/fast-api/schema.json +22 -0
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +12 -8
- package/src/smithy/ts/api/generator.js +3 -0
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/smithy/ts/api/schema.d.ts +4 -0
- package/src/smithy/ts/api/schema.json +22 -0
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +392 -102
- package/src/trpc/backend/generator.js +20 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +1 -0
- package/src/trpc/backend/schema.json +22 -0
- package/src/utils/api-constructs/api-constructs.d.ts +1 -0
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +18 -10
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +28 -16
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +25 -5
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +32 -8
- package/src/utils/api-constructs/files/cdk/core/api/utils/utils.ts.template +151 -32
|
@@ -22,8 +22,15 @@ const port_1 = require("../../utils/port");
|
|
|
22
22
|
const iac_1 = require("../../utils/iac");
|
|
23
23
|
const bundle_1 = require("../../utils/bundle/bundle");
|
|
24
24
|
exports.TRPC_BACKEND_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
25
|
+
const VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([
|
|
26
|
+
'ServerlessApiGatewayRestApi::isolated',
|
|
27
|
+
'ServerlessApiGatewayRestApi::shared',
|
|
28
|
+
'ServerlessApiGatewayHttpApi::isolated',
|
|
29
|
+
'ServerlessApiGatewayHttpApi::shared',
|
|
30
|
+
]);
|
|
25
31
|
function tsTrpcApiGenerator(tree, options) {
|
|
26
32
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
validateTrpcComputeTypeAndIntegrationPatternCombination(options);
|
|
27
34
|
const iacProvider = yield (0, iac_1.resolveIacProvider)(tree, options.iacProvider);
|
|
28
35
|
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree, {
|
|
29
36
|
iacProvider,
|
|
@@ -52,11 +59,12 @@ function tsTrpcApiGenerator(tree, options) {
|
|
|
52
59
|
type: 'trpc',
|
|
53
60
|
projectAlias: enhancedOptions.backendProjectAlias,
|
|
54
61
|
bundleOutputDir: (0, devkit_1.joinPathFragments)('dist', backendRoot, 'bundle'),
|
|
62
|
+
integrationPattern: getIntegrationPattern(options),
|
|
55
63
|
},
|
|
56
64
|
auth: options.auth,
|
|
57
65
|
iacProvider,
|
|
58
66
|
});
|
|
59
|
-
projectConfig.metadata = Object.assign(Object.assign({}, projectConfig.metadata), { apiName: options.name, apiType: 'trpc', auth: options.auth, computeType: options.computeType });
|
|
67
|
+
projectConfig.metadata = Object.assign(Object.assign({}, projectConfig.metadata), { apiName: options.name, apiType: 'trpc', auth: options.auth, computeType: options.computeType, integrationPattern: getIntegrationPattern(options) });
|
|
60
68
|
projectConfig.targets.serve = {
|
|
61
69
|
executor: 'nx:run-commands',
|
|
62
70
|
options: {
|
|
@@ -100,6 +108,17 @@ function tsTrpcApiGenerator(tree, options) {
|
|
|
100
108
|
};
|
|
101
109
|
});
|
|
102
110
|
}
|
|
111
|
+
const validateTrpcComputeTypeAndIntegrationPatternCombination = (options) => {
|
|
112
|
+
const integrationPattern = getIntegrationPattern(options);
|
|
113
|
+
const permutation = `${options.computeType}::${integrationPattern}`;
|
|
114
|
+
if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {
|
|
115
|
+
throw new Error(`Invalid tRPC computeType/integrationPattern combination: ${options.computeType} + ${integrationPattern}.`);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const getIntegrationPattern = (options) => {
|
|
119
|
+
var _a;
|
|
120
|
+
return (_a = options.integrationPattern) !== null && _a !== void 0 ? _a : 'isolated';
|
|
121
|
+
};
|
|
103
122
|
const getApiGatewayEventType = (options) => {
|
|
104
123
|
if (options.computeType === 'ServerlessApiGatewayRestApi') {
|
|
105
124
|
return 'APIGatewayProxyEvent';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;AA6CA,gDAqIC;;AAlLD;;;GAGG;AACH,uCASoB;AAEpB,qEAA0E;AAC1E,+EAAwD;AACxD,qDAAwE;AACxE,mDAAoD;AACpD,6CAA2D;AAC3D,+CAA0D;AAC1D,+CAAoD;AACpD,uCAMwB;AACxB,iDAAsE;AACtE,8EAA+E;AAC/E,2CAA8C;AAC9C,yCAAqD;AACrD,sDAAsE;AAEzD,QAAA,2BAA2B,GACtC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B,MAAM,mCAAmC,GAAG,IAAI,GAAG,CAAC;IAClD,uCAAuC;IACvC,qCAAqC;IACrC,uCAAuC;IACvC,qCAAqC;CACtC,CAAC,CAAC;AAEH,SAAsB,kBAAkB,CACtC,IAAU,EACV,OAAiC;;QAEjC,uDAAuD,CAAC,OAAO,CAAC,CAAC;QAEjE,MAAM,WAAW,GAAG,MAAM,IAAA,wBAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QAExE,MAAM,IAAA,6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A4D,OAAO,CAAC,WAAW,MAAM,kBAAkB,GAAG,CAC3G,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAC5B,OAAiC,EACV,EAAE;;IACzB,OAAO,MAAA,OAAO,CAAC,kBAAkB,mCAAI,UAAU,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,OAAiC,EAAU,EAAE;IAC3E,IAAI,OAAO,CAAC,WAAW,KAAK,6BAA6B,EAAE,CAAC;QAC1D,OAAO,sBAAsB,CAAC;IAChC,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAO,yCAAyC,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,yCAAyC,CAAC;IACnD,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAEF,kBAAe,kBAAkB,CAAC"}
|
|
@@ -9,6 +9,7 @@ import { TsProjectGeneratorSchema } from '../../ts/lib/schema';
|
|
|
9
9
|
export interface TsTrpcApiGeneratorSchema {
|
|
10
10
|
name: string;
|
|
11
11
|
computeType: 'ServerlessApiGatewayRestApi' | 'ServerlessApiGatewayHttpApi';
|
|
12
|
+
integrationPattern?: 'isolated' | 'shared';
|
|
12
13
|
auth: 'IAM' | 'Cognito' | 'None';
|
|
13
14
|
directory?: TsProjectGeneratorSchema['directory'];
|
|
14
15
|
iacProvider: IacProviderOption;
|
|
@@ -21,6 +21,28 @@
|
|
|
21
21
|
"x-prompt": "What compute type would you like to deploy your API with?",
|
|
22
22
|
"x-priority": "important"
|
|
23
23
|
},
|
|
24
|
+
"integrationPattern": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "How API Gateway integrations are generated for the API. Choose between isolated (default) and shared.",
|
|
27
|
+
"default": "isolated",
|
|
28
|
+
"enum": ["isolated", "shared"],
|
|
29
|
+
"x-priority": "important",
|
|
30
|
+
"x-prompt": {
|
|
31
|
+
"message": "How would you like to map integrations to your tRPC procedures?",
|
|
32
|
+
"type": "list",
|
|
33
|
+
"items": [
|
|
34
|
+
{
|
|
35
|
+
"value": "isolated",
|
|
36
|
+
"label": "isolated (one integration per procedure)"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"value": "shared",
|
|
40
|
+
"label": "shared (single default integration with optional overrides)"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"default": "isolated"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
24
46
|
"auth": {
|
|
25
47
|
"type": "string",
|
|
26
48
|
"description": "The method used to authenticate with your API. Choose between IAM (default), Cognito or None.",
|
|
@@ -6,6 +6,7 @@ import { Tree } from '@nx/devkit';
|
|
|
6
6
|
import { IacProvider } from '../iac';
|
|
7
7
|
interface BackendOptions {
|
|
8
8
|
type: 'trpc' | 'fastapi' | 'smithy';
|
|
9
|
+
integrationPattern: 'isolated' | 'shared';
|
|
9
10
|
}
|
|
10
11
|
export interface TrpcBackendOptions extends BackendOptions {
|
|
11
12
|
type: 'trpc';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/api-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,gFAIwC;AACxC,gCAAuC;
|
|
1
|
+
{"version":3,"file":"api-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/api-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,gFAIwC;AACxC,gCAAuC;AAkChC,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,OAAqE,EACrE,EAAE;IACF,IAAI,OAAO,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QAClC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;SA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,0BAAiB,EAAC,0CAAY,EAAE,kDAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAC3E,EAAE,EACF;QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;IAEF,yCAAyC;IACzC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EACf,SAAS,EACT,OAAO,EACP,WAAW,EACX,KAAK,EACL,MAAM,EACN,OAAO,CAAC,aAAa,CACtB,EACD,IAAA,0BAAiB,EAAC,0CAAY,EAAE,kDAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAC3E,OAAO,EACP;QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -37,6 +37,7 @@ import { IUserPool, IUserPoolClient } from 'aws-cdk-lib/aws-cognito';
|
|
|
37
37
|
import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam';
|
|
38
38
|
<%_ } _%>
|
|
39
39
|
import {
|
|
40
|
+
ApiIntegrations,
|
|
40
41
|
HttpApiIntegration,
|
|
41
42
|
IntegrationBuilder,
|
|
42
43
|
} from '../../core/api/utils.js';
|
|
@@ -60,7 +61,7 @@ import {
|
|
|
60
61
|
* @template TIntegrations - Map of operation names to their integrations
|
|
61
62
|
*/
|
|
62
63
|
export interface <%= apiNameClassName %>Props<
|
|
63
|
-
TIntegrations extends
|
|
64
|
+
TIntegrations extends ApiIntegrations<Operations, HttpApiIntegration>,
|
|
64
65
|
> {
|
|
65
66
|
/**
|
|
66
67
|
* Map of operation names to their API Gateway integrations
|
|
@@ -83,23 +84,29 @@ export interface <%= apiNameClassName %>Props<
|
|
|
83
84
|
* @template TIntegrations - Map of operation names to their integrations
|
|
84
85
|
*/
|
|
85
86
|
export class <%= apiNameClassName %><
|
|
86
|
-
TIntegrations extends
|
|
87
|
+
TIntegrations extends ApiIntegrations<Operations, HttpApiIntegration>,
|
|
87
88
|
> extends HttpApi<Operations, TIntegrations> {
|
|
88
89
|
/**
|
|
90
|
+
<%_ if (backend.integrationPattern === 'shared') { _%>
|
|
91
|
+
* Creates default integrations for all operations using a single shared
|
|
92
|
+
* router lambda function.
|
|
93
|
+
<%_ } else { _%>
|
|
89
94
|
* Creates default integrations for all operations, which implement each operation as
|
|
90
95
|
* its own individual lambda function.
|
|
96
|
+
<%_ } _%>
|
|
91
97
|
*
|
|
92
98
|
* @param scope - The CDK construct scope
|
|
93
99
|
* @returns An IntegrationBuilder with default lambda integrations
|
|
94
|
-
|
|
100
|
+
*/
|
|
95
101
|
public static defaultIntegrations = (scope: Construct) => {
|
|
96
102
|
return IntegrationBuilder.http({
|
|
103
|
+
pattern: '<%= backend.integrationPattern %>',
|
|
97
104
|
<%_ if (backend.type === 'trpc') { _%>
|
|
98
105
|
operations: routerToOperations(appRouter),
|
|
99
106
|
<%_ } else { _%>
|
|
100
107
|
operations: OPERATION_DETAILS,
|
|
101
108
|
<%_ } _%>
|
|
102
|
-
defaultIntegrationOptions: {
|
|
109
|
+
defaultIntegrationOptions: <FunctionProps>{
|
|
103
110
|
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
104
111
|
runtime: Runtime.NODEJS_LATEST,
|
|
105
112
|
handler: 'index.handler',
|
|
@@ -136,8 +143,10 @@ export class <%= apiNameClassName %><
|
|
|
136
143
|
AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
|
|
137
144
|
<%_ } _%>
|
|
138
145
|
},
|
|
139
|
-
}
|
|
146
|
+
},
|
|
140
147
|
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
148
|
+
<%_ const lambdaTarget = backend.type === 'fastapi' ? 'handler.currentVersion' : 'handler'; _%>
|
|
149
|
+
<%_ const integrationOptions = backend.integrationPattern === 'shared' ? ', { scopePermissionToRoute: false }' : ''; _%>
|
|
141
150
|
const handler = new Function(scope, `<%= apiNameClassName %>${op}Handler`, props);
|
|
142
151
|
<%_ if (backend.type === 'fastapi') { _%>
|
|
143
152
|
const stack = Stack.of(scope);
|
|
@@ -151,11 +160,10 @@ export class <%= apiNameClassName %><
|
|
|
151
160
|
<%_ } _%>
|
|
152
161
|
return {
|
|
153
162
|
handler,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<%_ } _%>
|
|
163
|
+
integration: new HttpLambdaIntegration(
|
|
164
|
+
`<%= apiNameClassName %><%_ if (backend.integrationPattern === 'shared') { _%>Router<%_ } _%>${op}Integration`,
|
|
165
|
+
<%- lambdaTarget %><%- integrationOptions %>,
|
|
166
|
+
),
|
|
159
167
|
};
|
|
160
168
|
},
|
|
161
169
|
});
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
import { IUserPool } from 'aws-cdk-lib/aws-cognito';
|
|
39
39
|
<%_ } _%>
|
|
40
40
|
import {
|
|
41
|
+
ApiIntegrations,
|
|
41
42
|
IntegrationBuilder,
|
|
42
43
|
RestApiIntegration,
|
|
43
44
|
} from '../../core/api/utils.js';
|
|
@@ -61,7 +62,7 @@ import {
|
|
|
61
62
|
* @template TIntegrations - Map of operation names to their integrations
|
|
62
63
|
*/
|
|
63
64
|
export interface <%= apiNameClassName %>Props<
|
|
64
|
-
TIntegrations extends
|
|
65
|
+
TIntegrations extends ApiIntegrations<Operations, RestApiIntegration>,
|
|
65
66
|
> {
|
|
66
67
|
/**
|
|
67
68
|
* Map of operation names to their API Gateway integrations
|
|
@@ -83,23 +84,29 @@ export interface <%= apiNameClassName %>Props<
|
|
|
83
84
|
* @template TIntegrations - Map of operation names to their integrations
|
|
84
85
|
*/
|
|
85
86
|
export class <%= apiNameClassName %><
|
|
86
|
-
TIntegrations extends
|
|
87
|
+
TIntegrations extends ApiIntegrations<Operations, RestApiIntegration>,
|
|
87
88
|
> extends RestApi<Operations, TIntegrations> {
|
|
88
89
|
/**
|
|
90
|
+
<%_ if (backend.integrationPattern === 'shared') { _%>
|
|
91
|
+
* Creates default integrations for all operations using a single shared
|
|
92
|
+
* router lambda function.
|
|
93
|
+
<%_ } else { _%>
|
|
89
94
|
* Creates default integrations for all operations, which implement each operation as
|
|
90
95
|
* its own individual lambda function.
|
|
96
|
+
<%_ } _%>
|
|
91
97
|
*
|
|
92
98
|
* @param scope - The CDK construct scope
|
|
93
99
|
* @returns An IntegrationBuilder with default lambda integrations
|
|
94
|
-
|
|
100
|
+
*/
|
|
95
101
|
public static defaultIntegrations = (scope: Construct) => {
|
|
96
102
|
return IntegrationBuilder.rest({
|
|
103
|
+
pattern: '<%= backend.integrationPattern %>',
|
|
97
104
|
<%_ if (backend.type === 'trpc') { _%>
|
|
98
105
|
operations: routerToOperations(appRouter),
|
|
99
106
|
<%_ } else { _%>
|
|
100
107
|
operations: OPERATION_DETAILS,
|
|
101
108
|
<%_ } _%>
|
|
102
|
-
defaultIntegrationOptions: {
|
|
109
|
+
defaultIntegrationOptions: <FunctionProps>{
|
|
103
110
|
<%_ if (['trpc', 'smithy'].includes(backend.type)) { _%>
|
|
104
111
|
runtime: Runtime.NODEJS_LATEST,
|
|
105
112
|
handler: 'index.handler',
|
|
@@ -136,8 +143,23 @@ export class <%= apiNameClassName %><
|
|
|
136
143
|
AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
|
|
137
144
|
<%_ } _%>
|
|
138
145
|
},
|
|
139
|
-
}
|
|
146
|
+
},
|
|
140
147
|
buildDefaultIntegration: (op, props: FunctionProps) => {
|
|
148
|
+
<%_ const lambdaTarget = backend.type === 'fastapi' ? 'handler.currentVersion' : 'handler'; _%>
|
|
149
|
+
<%_
|
|
150
|
+
const integrationOptionEntries = [];
|
|
151
|
+
if (backend.integrationPattern === 'shared') {
|
|
152
|
+
integrationOptionEntries.push('scopePermissionToMethod: false');
|
|
153
|
+
}
|
|
154
|
+
if (['fastapi', 'trpc'].includes(backend.type)) {
|
|
155
|
+
integrationOptionEntries.push(
|
|
156
|
+
'responseTransferMode: ResponseTransferMode.STREAM',
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const integrationOptions = integrationOptionEntries.length
|
|
160
|
+
? `, { ${integrationOptionEntries.join(', ')} }`
|
|
161
|
+
: '';
|
|
162
|
+
_%>
|
|
141
163
|
const handler = new Function(scope, `<%= apiNameClassName %>${op}Handler`, props);
|
|
142
164
|
<%_ if (backend.type === 'fastapi') { _%>
|
|
143
165
|
const stack = Stack.of(scope);
|
|
@@ -151,17 +173,7 @@ export class <%= apiNameClassName %><
|
|
|
151
173
|
<%_ } _%>
|
|
152
174
|
return {
|
|
153
175
|
handler,
|
|
154
|
-
|
|
155
|
-
integration: new LambdaIntegration(handler.currentVersion, {
|
|
156
|
-
responseTransferMode: ResponseTransferMode.STREAM,
|
|
157
|
-
}),
|
|
158
|
-
<%_ } else if (backend.type === 'trpc') { _%>
|
|
159
|
-
integration: new LambdaIntegration(handler, {
|
|
160
|
-
responseTransferMode: ResponseTransferMode.STREAM,
|
|
161
|
-
}),
|
|
162
|
-
<%_ } else { _%>
|
|
163
|
-
integration: new LambdaIntegration(handler),
|
|
164
|
-
<%_ } _%>
|
|
176
|
+
integration: new LambdaIntegration(<%- lambdaTarget %><%- integrationOptions %>),
|
|
165
177
|
};
|
|
166
178
|
},
|
|
167
179
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { RuntimeConfig } from '../runtime-config.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ApiIntegrations,
|
|
5
|
+
HttpApiIntegration,
|
|
6
|
+
OperationDetails,
|
|
7
|
+
} from './utils.js';
|
|
4
8
|
import { CfnOutput } from 'aws-cdk-lib';
|
|
5
9
|
import {
|
|
6
10
|
HttpApi as _HttpApi,
|
|
@@ -19,7 +23,7 @@ import { suppressRules } from '../checkov.js';
|
|
|
19
23
|
* @template TOperation - String literal type representing operation names
|
|
20
24
|
*/
|
|
21
25
|
export interface HttpApiProps<
|
|
22
|
-
TIntegrations extends
|
|
26
|
+
TIntegrations extends ApiIntegrations<TOperation, HttpApiIntegration>,
|
|
23
27
|
TOperation extends string,
|
|
24
28
|
> extends _HttpApiProps {
|
|
25
29
|
/**
|
|
@@ -49,7 +53,7 @@ export interface HttpApiProps<
|
|
|
49
53
|
*/
|
|
50
54
|
export class HttpApi<
|
|
51
55
|
TOperation extends string,
|
|
52
|
-
TIntegrations extends
|
|
56
|
+
TIntegrations extends ApiIntegrations<TOperation, HttpApiIntegration>,
|
|
53
57
|
> extends Construct {
|
|
54
58
|
/** The underlying CDK HttpApi instance */
|
|
55
59
|
public readonly api: _HttpApi;
|
|
@@ -99,16 +103,32 @@ export class HttpApi<
|
|
|
99
103
|
},
|
|
100
104
|
});
|
|
101
105
|
|
|
106
|
+
// Resolve the integration for a given operation.
|
|
107
|
+
// If the operation has a dedicated integration, use it; otherwise fall back to $router.
|
|
108
|
+
const resolveIntegration = (op: TOperation): HttpApiIntegration => {
|
|
109
|
+
const record = integrations as Record<string, HttpApiIntegration>;
|
|
110
|
+
if (op in record) {
|
|
111
|
+
return record[op];
|
|
112
|
+
}
|
|
113
|
+
if ('$router' in record) {
|
|
114
|
+
return record['$router'];
|
|
115
|
+
}
|
|
116
|
+
throw new Error(
|
|
117
|
+
`No integration found for operation '${op}' and no $router integration available`,
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
102
121
|
// Create API resources and methods for each operation
|
|
103
122
|
(Object.entries(operations) as [TOperation, OperationDetails][]).map(
|
|
104
123
|
([op, details]) => {
|
|
124
|
+
const integration = resolveIntegration(op);
|
|
105
125
|
this.api.addRoutes({
|
|
106
126
|
path: details.path.startsWith('/')
|
|
107
127
|
? details.path
|
|
108
128
|
: `/${details.path}`,
|
|
109
129
|
methods: [details.method as HttpMethod],
|
|
110
|
-
integration:
|
|
111
|
-
...
|
|
130
|
+
integration: integration.integration,
|
|
131
|
+
...integration.options,
|
|
112
132
|
});
|
|
113
133
|
},
|
|
114
134
|
);
|
|
@@ -6,17 +6,21 @@ import {
|
|
|
6
6
|
Stage,
|
|
7
7
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
8
8
|
import { RuntimeConfig } from '../runtime-config.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
ApiIntegrations,
|
|
11
|
+
OperationDetails,
|
|
12
|
+
RestApiIntegration,
|
|
13
|
+
} from './utils.js';
|
|
10
14
|
import { suppressRules } from '../checkov.js';
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Properties for creating a RestApi construct.
|
|
14
18
|
*
|
|
15
|
-
* @template TIntegrations - Record mapping
|
|
19
|
+
* @template TIntegrations - Record mapping integration keys to their integrations
|
|
16
20
|
* @template TOperation - String literal type representing operation names
|
|
17
21
|
*/
|
|
18
22
|
export interface RestApiProps<
|
|
19
|
-
TIntegrations extends
|
|
23
|
+
TIntegrations extends ApiIntegrations<TOperation, RestApiIntegration>,
|
|
20
24
|
TOperation extends string,
|
|
21
25
|
> extends _RestApiProps {
|
|
22
26
|
/**
|
|
@@ -28,7 +32,7 @@ export interface RestApiProps<
|
|
|
28
32
|
*/
|
|
29
33
|
readonly operations: Record<TOperation, OperationDetails>;
|
|
30
34
|
/**
|
|
31
|
-
* Map of
|
|
35
|
+
* Map of integration keys to their API Gateway integrations
|
|
32
36
|
*/
|
|
33
37
|
readonly integrations: TIntegrations;
|
|
34
38
|
}
|
|
@@ -42,16 +46,16 @@ export interface RestApiProps<
|
|
|
42
46
|
* - Integration with runtime configuration for client discovery
|
|
43
47
|
*
|
|
44
48
|
* @template TOperation - String literal type representing operation names
|
|
45
|
-
* @template TIntegrations - Record mapping
|
|
49
|
+
* @template TIntegrations - Record mapping integration keys to their integrations
|
|
46
50
|
*/
|
|
47
51
|
export class RestApi<
|
|
48
52
|
TOperation extends string,
|
|
49
|
-
TIntegrations extends
|
|
53
|
+
TIntegrations extends ApiIntegrations<TOperation, RestApiIntegration>,
|
|
50
54
|
> extends Construct {
|
|
51
55
|
/** The underlying CDK RestApi instance */
|
|
52
56
|
public readonly api: _RestApi;
|
|
53
57
|
|
|
54
|
-
/** Map of
|
|
58
|
+
/** Map of integration keys to their API Gateway integrations */
|
|
55
59
|
public readonly integrations: TIntegrations;
|
|
56
60
|
|
|
57
61
|
constructor(
|
|
@@ -83,9 +87,25 @@ export class RestApi<
|
|
|
83
87
|
(c) => c instanceof Stage,
|
|
84
88
|
);
|
|
85
89
|
|
|
90
|
+
// Resolve the integration for a given operation.
|
|
91
|
+
// If the operation has a dedicated integration, use it; otherwise fall back to $router.
|
|
92
|
+
const resolveIntegration = (op: TOperation): RestApiIntegration => {
|
|
93
|
+
const record = integrations as Record<string, RestApiIntegration>;
|
|
94
|
+
if (op in record) {
|
|
95
|
+
return record[op];
|
|
96
|
+
}
|
|
97
|
+
if ('$router' in record) {
|
|
98
|
+
return record['$router'];
|
|
99
|
+
}
|
|
100
|
+
throw new Error(
|
|
101
|
+
`No integration found for operation '${op}' and no $router integration available`,
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
86
105
|
// Create API resources and methods for each operation
|
|
87
106
|
(Object.entries(operations) as [TOperation, OperationDetails][]).map(
|
|
88
107
|
([op, details]) => {
|
|
108
|
+
const integration = resolveIntegration(op);
|
|
89
109
|
const resource = this.getOrCreateResource(
|
|
90
110
|
this.api.root,
|
|
91
111
|
(details.path.startsWith('/')
|
|
@@ -93,7 +113,11 @@ export class RestApi<
|
|
|
93
113
|
: details.path
|
|
94
114
|
).split('/'),
|
|
95
115
|
);
|
|
96
|
-
resource.addMethod(
|
|
116
|
+
resource.addMethod(
|
|
117
|
+
details.method,
|
|
118
|
+
integration.integration,
|
|
119
|
+
integration.options,
|
|
120
|
+
);
|
|
97
121
|
},
|
|
98
122
|
);
|
|
99
123
|
|