@fy-stack/apigateway-construct 0.0.122

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # apigateway-construct
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build apigateway-construct` to build the library.
@@ -0,0 +1,3 @@
1
+ export { ApiGatewayConstruct } from './lib/apigateway-construct';
2
+ export type { ApiGatewayConstructProps } from "./lib/types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiGatewayConstruct = void 0;
4
+ var apigateway_construct_1 = require("./lib/apigateway-construct");
5
+ Object.defineProperty(exports, "ApiGatewayConstruct", { enumerable: true, get: function () { return apigateway_construct_1.ApiGatewayConstruct; } });
@@ -0,0 +1,8 @@
1
+ import { HttpApi } from "aws-cdk-lib/aws-apigatewayv2";
2
+ import { Construct } from "constructs";
3
+ import { ApiGatewayConstructProps } from "./types";
4
+ export declare class ApiGatewayConstruct extends Construct {
5
+ readonly api: HttpApi;
6
+ constructor(scope: Construct, id: string, props: ApiGatewayConstructProps);
7
+ }
8
+ //# sourceMappingURL=apigateway-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apigateway-construct.d.ts","sourceRoot":"","sources":["../../src/lib/apigateway-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,GAAG,EAAE,OAAO,CAAC;gBAEjB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB;CAuC1E"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiGatewayConstruct = void 0;
4
+ const aws_apigatewayv2_1 = require("aws-cdk-lib/aws-apigatewayv2");
5
+ const constructs_1 = require("constructs");
6
+ class ApiGatewayConstruct extends constructs_1.Construct {
7
+ api;
8
+ constructor(scope, id, props) {
9
+ super(scope, id);
10
+ const routes = {};
11
+ Object.assign(routes, Object.fromEntries(Object.entries(props.routes).map(([key, val]) => {
12
+ const app = props.resources?.[val.$resource];
13
+ if (!app)
14
+ throw new Error(`"${val.$resource}" resource not found`);
15
+ return [key, app];
16
+ })));
17
+ const { "/*": base, ...otherRoutes } = routes;
18
+ if (!base)
19
+ throw new Error("no base route");
20
+ const { "/*": defaultIntegration, ...additionalIntegrations } = base
21
+ .api("");
22
+ if (!defaultIntegration)
23
+ throw new Error("no default integration");
24
+ for (const i in otherRoutes) {
25
+ Object.assign(additionalIntegrations, otherRoutes[i]?.api(i));
26
+ }
27
+ this.api = new aws_apigatewayv2_1.HttpApi(this, "Api", { defaultIntegration });
28
+ for (const i in additionalIntegrations) {
29
+ this.api.addRoutes({
30
+ integration: additionalIntegrations[i],
31
+ methods: [aws_apigatewayv2_1.HttpMethod.ANY],
32
+ path: `${i}/{proxy+}`,
33
+ });
34
+ }
35
+ }
36
+ }
37
+ exports.ApiGatewayConstruct = ApiGatewayConstruct;
@@ -0,0 +1,6 @@
1
+ import type { ApiResource, ResourceRef } from '@fy-stack/types';
2
+ export type ApiGatewayConstructProps = {
3
+ routes: Record<string, ResourceRef>;
4
+ resources?: Record<string, ApiResource | undefined>;
5
+ };
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAC,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@fy-stack/apigateway-construct",
3
+ "version": "0.0.122",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0",
6
+ "@fy-stack/types": "0.0.122"
7
+ },
8
+ "peerDependencies": {
9
+ "aws-cdk-lib": "2.164.1",
10
+ "constructs": "10.4.2"
11
+ },
12
+ "type": "commonjs",
13
+ "main": "./dist/index.js",
14
+ "typings": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "!**/*.tsbuildinfo"
18
+ ],
19
+ "nx": {
20
+ "name": "apigateway-construct"
21
+ }
22
+ }