Skip to content

Commit

Permalink
chore: cleanup and sestructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
spirius committed Nov 27, 2023
1 parent c49fc79 commit 55ac254
Show file tree
Hide file tree
Showing 31 changed files with 58 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/bundler/Bundler.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TerraformStack } from "cdktf"

import { App } from "../App"
import { HttpApi } from "../http-api/HttpApi"
import { App } from "../core/App"
import { HttpApi } from "../http-api/core/HttpApi"
import * as setup from "../tests/setup"
import { Bundler } from "./Bundler"

Expand Down
4 changes: 2 additions & 2 deletions src/bundler/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import _ from "lodash"
import { OpenAPIV3 } from "openapi-types"
import { join, relative } from "path"

import { App, AppLifeCycle } from "../App"
import { App, AppLifeCycle } from "../core/App"
import { AsyncResolvable } from "../core/resolvable/AsyncResolvable"
import { HttpApi, HttpApiOperation } from "../http-api"
import { HttpApiLambdaAuthorizer } from "../http-api/authorizer"
import { Lambda, LambdaConfig, LambdaConfigCore, LambdaEntryPoint } from "../lambda/Lambda"
import { AsyncResolvable } from "../resolvable/AsyncResolvable"
import { sanitizeSchema } from "../utils/sanitizeSchema"
import { walkSchema } from "../utils/walkSchema"
import { BundlerLanguage } from "./language/BundlerLanguage"
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/language/BundlerLanguage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { OpenAPIV3 } from "openapi-types"

import { Resource } from "../../core/Resource"
import { HttpApi, HttpApiOperation } from "../../http-api"
import { HttpApiLambdaAuthorizer } from "../../http-api/authorizer"
import { LambdaConfigCore, LambdaEntryPoint } from "../../lambda"
import { Resource } from "../../resource"

export interface BundlerLanguageGenerateOptions {
schemas: Record<string, OpenAPIV3.SchemaObject>
Expand Down
6 changes: 3 additions & 3 deletions src/bundler/language/BundlerLanguageTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { compile } from "json-schema-to-typescript"
import { OpenAPIV3 } from "openapi-types"
import { dirname, join, relative } from "path"

import { App } from "../../App"
import { App } from "../../core/App"
import { Resource } from "../../core/Resource"
import { AsyncResolvable } from "../../core/resolvable/AsyncResolvable"
import { HttpApi, HttpApiOperation } from "../../http-api"
import { HttpApiLambdaAuthorizer } from "../../http-api/authorizer"
import { HttpStatusCodes } from "../../http-api/enum"
import { LambdaConfig, LambdaEntryPoint } from "../../lambda"
import { AsyncResolvable } from "../../resolvable/AsyncResolvable"
import { Resource } from "../../resource"
import { walkSchema } from "../../utils/walkSchema"
import { writeFile } from "../../utils/writeFile"
import { writeMustacheTemplate } from "../../utils/writeMustacheTemplate"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as esbuild from "esbuild"
import { readFile, rm, writeFile } from "fs/promises"
import { join, relative, resolve } from "path"

import type { App, AppManifest, AppOptions } from "../App"
import { BundlerLanguageTypeScriptManifest } from "../bundler/language/BundlerLanguageTypeScript"
import type { App, AppManifest, AppOptions } from "../core/App"
import { esbuildPlugins } from "../esbuild-plugins"
import { SdfConfig } from "../interfaces"

Expand Down
4 changes: 2 additions & 2 deletions src/App.ts → src/core/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Construct } from "constructs"
import { mkdir, writeFile } from "fs/promises"
import { join, resolve } from "path"

import { BundleManifest, Bundler } from "../bundler"
import { Resource } from "./Resource"
import { StackController } from "./StackController"
import { BundleManifest, Bundler } from "./bundler"
import { AsyncResolvable } from "./resolvable/AsyncResolvable"
import { TreeResolver } from "./resolvable/TreeResolver"
import { Resource } from "./resource"

export interface AppOptions extends CdkTfAppConfig {
argv?: Array<string>
Expand Down
2 changes: 1 addition & 1 deletion src/resource/Resource.ts → src/core/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DataAwsIamPolicyDocument } from "@cdktf/provider-aws/lib/data-aws-iam-p
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { App } from "../App"
import { App } from "./App"

export interface ResourcePermissions {
[key: string]: DataAwsIamPolicyDocument
Expand Down
2 changes: 1 addition & 1 deletion src/StackController.ts → src/core/StackController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TerraformStack } from "cdktf"
import { Construct } from "constructs"

import { Resource } from "./resource"
import { Resource } from "./Resource"

export class StackController {
private stacks = new WeakMap<TerraformStack, Record<string, Resource>>()
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./App"
export * from "./Resource"
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/http-api/authorizer/HttpApiAuthorizer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { HttpApi } from "../HttpApi"
import { HttpApi } from "../core/HttpApi"

export abstract class HttpApiAuthorizer extends Construct {
/** The spec method should return the OpenAPI spec for the authorizer */
Expand Down
4 changes: 2 additions & 2 deletions src/http-api/authorizer/HttpApiLambdaAuthorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { pascalCase } from "change-case"
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { App } from "../../App"
import { Bundler } from "../../bundler"
import { App } from "../../core/App"
import { Lambda, LambdaConfig } from "../../lambda/Lambda"
import { HttpApi } from "../HttpApi"
import { HttpApi } from "../core/HttpApi"
import { HttpApiAuthorizer } from "./HttpApiAuthorizer"

export interface HttpApiLambdaAuthorizerConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/http-api/client/HttpApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { jest } from "@jest/globals"
import { APIGatewayEventRequestContextV2 } from "aws-lambda"
import { TerraformStack } from "cdktf"

import { App } from "../../App"
import { Bundler } from "../../bundler/Bundler"
import { App } from "../../core/App"
import { HttpServer, createHttpServer } from "../../tests/createHttpServer"
import { requireFile } from "../../tests/requireFile"
import * as setup from "../../tests/setup"
import { tscCheck } from "../../tests/tscCheck"
import { MimeTypes } from "../../utils/MimeTypes"
import { HttpApi } from "../HttpApi"
import { HttpApi } from "../core/HttpApi"
import { ApiResponse, EventType, Operation } from "../runtime"
import { HttpApiClient } from "./HttpApiClient"

Expand Down
27 changes: 0 additions & 27 deletions src/http-api/client/client.ts.mu

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIV3 } from "openapi-types"

import { DocumentParser, ParsedOperation } from "./DocumentParser"
import { Document, ParameterObject, RequestBodyObject, ResponseObject } from "./types"
import { Document, ParameterObject, RequestBodyObject, ResponseObject } from "../openapi/types"
import { DocumentParser, OperationBundle } from "./DocumentParser"

const createDocument = ({
pathParameters,
Expand Down Expand Up @@ -115,7 +115,7 @@ describe(DocumentParser.name, () => {
}),
)

let operation: ParsedOperation | undefined
let operation: OperationBundle | undefined
await parser.walkOperations(async op => {
operation = op
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { OpenAPIV3 } from "openapi-types"

import { MimeTypes } from "../../utils/MimeTypes"
import { sanitizeSchema } from "../../utils/sanitizeSchema"
import { HttpApiOperation } from "../HttpApi"
import { DocumentTrace } from "./DocumentTrace"
import { DereferencedDocument, Document, OperationObject, ParameterObject, PathItemObject } from "./types"
import { DocumentTrace } from "../openapi/DocumentTrace"
import { DereferencedDocument, Document, OperationObject, ParameterObject, PathItemObject } from "../openapi/types"
import { HttpApiOperation } from "./HttpApi"

export interface OperationBundleBase {
document: Document
Expand Down Expand Up @@ -337,7 +337,7 @@ export class DocumentParser {
* Create list of request validation schemas.
* The resulting schemas are copies of the original schemas with sanitization applied.
*/
private createValidtorSchemas(operation: OperationBundle): Array<SchemaObject> {
public createValidtorSchemas(operation: OperationBundle): Array<SchemaObject> {
const {
request: { parameters, body },
} = operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { TerraformStack } from "cdktf"
import { OpenAPIV3 } from "openapi-types"
import { join } from "path"

import { App } from "../App"
import { Bundler } from "../bundler/Bundler"
import { requireFile } from "../tests/requireFile"
import * as setup from "../tests/setup"
import { tscCheck } from "../tests/tscCheck"
import { Bundler } from "../../bundler/Bundler"
import { App } from "../../core/App"
import { requireFile } from "../../tests/requireFile"
import * as setup from "../../tests/setup"
import { tscCheck } from "../../tests/tscCheck"
import { HttpApiLambdaAuthorizer } from "../authorizer"
import { HttpError } from "../error"
import { Document } from "../openapi/types"
import { Validators } from "../runtime/wrapper"
import { HttpApi } from "./HttpApi"
import { HttpApiLambdaAuthorizer } from "./authorizer"
import { HttpError } from "./error"
import { Document } from "./openapi/types"
import { Validators } from "./runtime/wrapper"

describe(HttpApi.name, () => {
const bundlerName = "test-service"
Expand Down
21 changes: 9 additions & 12 deletions src/http-api/HttpApi.ts → src/http-api/core/HttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import { camelCase, paramCase } from "change-case"
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { App, AppLifeCycle } from "../App"
import { Bundler } from "../bundler"
import { Lambda, LambdaConfig } from "../lambda/Lambda"
import { AsyncResolvable } from "../resolvable/AsyncResolvable"
import { HttpApiJwtAuthorizer, HttpApiLambdaAuthorizer } from "./authorizer"
import { HttpApiAuthorizer } from "./authorizer/HttpApiAuthorizer"
import { DocumentParser, OperationBundle, ParsedOperationSecurity } from "./openapi/DocumentParser"
import { Document } from "./openapi/types"
import { Bundler } from "../../bundler"
import { App, AppLifeCycle } from "../../core/App"
import { AsyncResolvable } from "../../core/resolvable/AsyncResolvable"
import { Lambda, LambdaConfig } from "../../lambda/Lambda"
import { HttpApiJwtAuthorizer, HttpApiLambdaAuthorizer } from "../authorizer"
import { HttpApiAuthorizer } from "../authorizer/HttpApiAuthorizer"
import { Document } from "../openapi/types"
import { DocumentParser, OperationBundle, ParsedOperationSecurity } from "./DocumentParser"

export interface HttpApiOperation extends OperationBundle {
// authorizer?: HttpApiAuthorizer

operationSchema: OpenAPIV3.SchemaObject & Required<Pick<OpenAPIV3.SchemaObject, "title">>

validatorSchemas: Array<SchemaObject>
}

Expand Down Expand Up @@ -285,7 +282,7 @@ export class HttpApi<OperationType extends object = object> extends Construct {

this.lambdas[operationId] = lambda

// add api gateway integration into the operation
// NOTICE: mutating the document
operationSpec["x-amazon-apigateway-integration"] = {
payloadFormatVersion: "2.0",
type: "aws_proxy",
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./HttpApi"
export * from "./core/HttpApi"
2 changes: 1 addition & 1 deletion src/http-api/runtime/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { APIGatewayProxyEventV2 } from "aws-lambda"
import { OpenAPIV3 } from "openapi-types"

import { MimeTypes } from "../../utils/MimeTypes"
import { DocumentParser } from "../core/DocumentParser"
import { HttpHeaders } from "../enum/HttpHeaders"
import { BadGateway } from "../error"
import { DocumentParser } from "../openapi/DocumentParser"
import { Document, OperationObject } from "../openapi/types"
import { ApiResponse } from "./ApiResponse"
import { LambdaHandler, wrapper } from "./wrapper"
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/runtime/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
import { OpenAPIV3 } from "openapi-types"

import { MimeTypes } from "../../utils/MimeTypes"
import { OperationBundleBase } from "../core/DocumentParser"
import { HttpHeaders } from "../enum/HttpHeaders"
import { BadRequest, InternalServerError, UnsupportedMediaType } from "../error"
import { HttpError } from "../error/HttpError"
import { OperationBundleBase } from "../openapi/DocumentParser"
import { DocumentTrace } from "../openapi/DocumentTrace"
import { DereferencedDocument } from "../openapi/types"
import { ApiResponse } from "./ApiResponse"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./App"
export * from "./core/"
export * from "./interfaces"
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BuildOptions } from "esbuild"

import type { App, AppOptions } from "./App"
import type { BundleManifest } from "./bundler/Bundler"
import type { App, AppOptions } from "./core/App"

export interface SdfConfig {
synth: (options: AppOptions) => Promise<App>
Expand Down
6 changes: 3 additions & 3 deletions src/lambda/Lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { Fn, TerraformResource, dependable } from "cdktf"
import { constantCase, paramCase } from "change-case"
import { Construct } from "constructs"

import { App, AppLifeCycle } from "../App"
import { Bundler } from "../bundler/Bundler"
import { AsyncResolvable } from "../resolvable/AsyncResolvable"
import { Resource } from "../resource/Resource"
import { App, AppLifeCycle } from "../core/App"
import { Resource } from "../core/Resource"
import { AsyncResolvable } from "../core/resolvable/AsyncResolvable"

export type LambdaFunctionConfig = Omit<AwsLambdaFunctionConfig, "role">

Expand Down
2 changes: 1 addition & 1 deletion src/resource/ResourceDynamodbTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DynamodbTable, DynamodbTableConfig } from "@cdktf/provider-aws/lib/dyna
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { Resource } from "./Resource"
import { Resource } from "../core/Resource"

export class ResourceDynamodbTable extends Resource {
public table: DynamodbTable
Expand Down
2 changes: 1 addition & 1 deletion src/resource/ResourceKmsKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { KmsKey, KmsKeyConfig } from "@cdktf/provider-aws/lib/kms-key"
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { Resource } from "./Resource"
import { Resource } from "../core/Resource"

export class ResourceKmsKey extends Resource {
public key: KmsKey
Expand Down
2 changes: 1 addition & 1 deletion src/resource/ResourceS3Bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DataAwsIamPolicyDocument } from "@cdktf/provider-aws/lib/data-aws-iam-p
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { Resource } from "./Resource"
import { Resource } from "../core/Resource"

export interface ResourceS3BucketConfig {
arn: string
Expand Down
2 changes: 1 addition & 1 deletion src/resource/ResourceStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SfnStateMachine } from "@cdktf/provider-aws/lib/sfn-state-machine"
import { Construct } from "constructs"
import { OpenAPIV3 } from "openapi-types"

import { Resource } from "./Resource"
import { Resource } from "../core/Resource"

export class ResourceStateMachine extends Resource {
get configSpec(): OpenAPIV3.SchemaObject {
Expand Down
1 change: 0 additions & 1 deletion src/resource/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./Resource"
export * from "./ResourceDynamodbTable"
export * from "./ResourceKmsKey"
export * from "./ResourceS3Bucket"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"resolveJsonModule": true
},
"include": ["./src"],
"exclude": ["./publish", "./src/**/*.test.ts"]
"exclude": ["./publish"]
}

0 comments on commit 55ac254

Please sign in to comment.