Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programmatic generate client config starter #43

Merged
merged 33 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ff97e5f
move ProjectEnvironmentIdentifier to primitives package
edwardfoyle Jun 9, 2023
9abd6ea
output fetching and construct data reconstruction
edwardfoyle Jun 10, 2023
d181028
rename schema const
edwardfoyle Jun 10, 2023
d377fb0
update test imports
edwardfoyle Jun 10, 2023
814c77a
Merge remote-tracking branch 'origin/main' into generate
edwardfoyle Jun 13, 2023
531f09c
rename plugin-types to backend-types
edwardfoyle Jun 13, 2023
0404853
getting everything to build
edwardfoyle Jun 13, 2023
db2ae4e
more refactoring
edwardfoyle Jun 13, 2023
fe79b6a
more refactoring
edwardfoyle Jun 13, 2023
a1e623c
update package json
edwardfoyle Jun 13, 2023
f7a3b72
fix tests
edwardfoyle Jun 13, 2023
3323e74
revert plugin-types rename
edwardfoyle Jun 13, 2023
e02dcf0
update api extract
edwardfoyle Jun 13, 2023
59e5273
renaming and self review
edwardfoyle Jun 13, 2023
d1fee64
a bit more cleanup
edwardfoyle Jun 14, 2023
79a56b1
update api extract
edwardfoyle Jun 14, 2023
d10e21b
remove unused file
edwardfoyle Jun 14, 2023
56f8ed2
add some comments
edwardfoyle Jun 14, 2023
00a574a
update import and sort lines
edwardfoyle Jun 14, 2023
11235af
put all amplify metadata under AWS::Amplify::Output key
edwardfoyle Jun 14, 2023
b23fb30
fixing some naming and comments
edwardfoyle Jun 14, 2023
cbc0f6e
tests for output retrieval strat
edwardfoyle Jun 14, 2023
bf0e849
renaming BackendStack => MainStack and some other renaming
edwardfoyle Jun 14, 2023
361f61e
rename BackendStackCreator => MainStackCreator and make returned stac…
edwardfoyle Jun 14, 2023
a6254c6
duplicate param key to avoid exporting impl details
edwardfoyle Jun 14, 2023
bdba6c5
update package json and import lint rules
edwardfoyle Jun 14, 2023
bf75d22
update lint rule
edwardfoyle Jun 14, 2023
6d4dcd5
update api extract
edwardfoyle Jun 14, 2023
66ea0d4
turn off lint rule that doesnt play nice with workspaces
edwardfoyle Jun 14, 2023
88ac24c
add tests
edwardfoyle Jun 14, 2023
bea561d
remove placeholder test
edwardfoyle Jun 14, 2023
4f7862d
update method name, add shared file for ssm test
edwardfoyle Jun 15, 2023
69cb0f0
update api extract
edwardfoyle Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"sourceType": "module",
"project": ["tsconfig.eslint.json"]
},
"plugins": ["@typescript-eslint", "unicorn", "jsdoc"],
"plugins": ["@typescript-eslint", "unicorn", "jsdoc", "import"],
"rules": {
"@typescript-eslint/switch-exhaustiveness-check": "error",
"no-duplicate-imports": "error",
"import/no-extraneous-dependencies": "error",
"unicorn/filename-case": [
"error",
{
Expand Down
16,411 changes: 9,876 additions & 6,535 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-xo-typescript": "^0.57.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsdoc": "^43.0.6",
"eslint-plugin-unicorn": "^46.0.0",
"execa": "^7.1.1",
Expand Down
16 changes: 4 additions & 12 deletions packages/backend-engine/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

```ts

import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { CfnElement } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { ConstructCache } from '@aws-amplify/plugin-types';
Expand All @@ -13,29 +15,18 @@ import { Stack } from 'aws-cdk-lib';

// @public
export class AmplifyStack extends Stack {
constructor(scope: Construct, id: string, props: AmplifyStackProps);
allocateLogicalId(element: CfnElement): string;
readonly projectEnvironmentIdentifier: ProjectEnvironmentIdentifier;
}

// @public
export type AmplifyStackProps = {
readonly projectEnvironmentIdentifier: ProjectEnvironmentIdentifier;
};
export const generateClientConfig: (credentialProvider: AwsCredentialIdentityProvider, backendIdentifier: BackendIdentifier) => Promise<void>;

// @public
export class NestedStackResolver implements StackResolver {
constructor(rootStack: Stack);
getStackFor(resourceGroupName: string): Stack;
}

// @public
export class ProjectEnvironmentIdentifier {
constructor(projectName: string, environmentName: string);
toOutputStackSSMParameterName(): string;
toStackName(): string;
}

// @public
export class SingletonConstructCache implements ConstructCache {
constructor(stackResolver: StackResolver);
Expand All @@ -45,6 +36,7 @@ export class SingletonConstructCache implements ConstructCache {
// @public
export class StackMetadataOutputStorageStrategy implements OutputStorageStrategy {
constructor(stack: Stack);
flush(): void;
storeOutput(constructPackage: string, constructVersion: string, data: Record<string, string>): void;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/backend-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
"scripts": {
"api:update": "api-extractor run --local"
},
"dependencies": {
"zod": "^3.21.4"
},
"devDependencies": {
"@aws-amplify/plugin-types": "^0.1.0",
"@aws-sdk/credential-providers": "^3.352.0",
"@aws-sdk/types": "^3.347.0",
edwardfoyle marked this conversation as resolved.
Show resolved Hide resolved
"aws-cdk-lib": "^2.72.0",
"constructs": "^10.0.0"
},
"peerDependencies": {
"@aws-sdk/client-cloudformation": "^3.352.0",
"@aws-sdk/client-ssm": "^3.352.0",
edwardfoyle marked this conversation as resolved.
Show resolved Hide resolved
"aws-cdk-lib": "^2.72.0",
"constructs": "^10.0.0"
},
Expand Down
19 changes: 1 addition & 18 deletions packages/backend-engine/src/amplify_stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ import { App, NestedStack } from 'aws-cdk-lib';
import { AmplifyStack } from './amplify_stack.js';
import { Template } from 'aws-cdk-lib/assertions';
import assert from 'node:assert';
import { ProjectEnvironmentIdentifier } from './project_environment_identifier.js';

describe('AmplifyStack', () => {
it('renames nested stack logical IDs to non-redundant value', () => {
const app = new App();
const rootStack = new AmplifyStack(app, 'test-id', {
projectEnvironmentIdentifier: new ProjectEnvironmentIdentifier(
'testProjName',
'testEnvName'
),
});
const rootStack = new AmplifyStack(app, 'test-id');
new NestedStack(rootStack, 'testName');

const rootStackTemplate = Template.fromStack(rootStack);
Expand All @@ -25,15 +19,4 @@ describe('AmplifyStack', () => {
assert.ok(actualStackLogicalId.startsWith('testName'));
assert.ok(!actualStackLogicalId.includes('NestedStack'));
});

it('names the stack based on the project and environment name', () => {
const app = new App();
const stack = new AmplifyStack(app, 'test-id', {
projectEnvironmentIdentifier: new ProjectEnvironmentIdentifier(
'testProjName',
'testEnvName'
),
});
assert.equal(stack.stackName, 'testProjName-testEnvName');
});
});
23 changes: 0 additions & 23 deletions packages/backend-engine/src/amplify_stack.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { CfnElement, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { ProjectEnvironmentIdentifier } from './project_environment_identifier.js';

/**
* Properties to initialize an AmplifyStack
*/
export type AmplifyStackProps = {
readonly projectEnvironmentIdentifier: ProjectEnvironmentIdentifier;
};

/**
* Amplify-specific Stack implementation to handle cross-cutting concerns for all Amplify stacks
*/
export class AmplifyStack extends Stack {
/**
* Identifier for the project environment this stack exists in
*/
readonly projectEnvironmentIdentifier: ProjectEnvironmentIdentifier;

/**
* Initializes the stack with a name that is unique to the provided Amplify environment
*/
constructor(scope: Construct, id: string, props: AmplifyStackProps) {
super(scope, id, {
stackName: props.projectEnvironmentIdentifier.toStackName(),
});
this.projectEnvironmentIdentifier = props.projectEnvironmentIdentifier;
}
/**
* Overrides Stack.allocateLogicalId to prevent redundant nested stack logical IDs
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const amplifyStackMetadataKey = 'AWS::Amplify::Output';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { z } from 'zod';

/**
* Schema for a single block of output written by a construct
*/
export const backendOutputEntrySchema = z.object({
constructVersion: z.string(),
stackOutputs: z.array(z.string()),
});

/**
* Inferred type from outputEntrySchema
*/
export type BackendOutputEntry = z.infer<typeof backendOutputEntrySchema>;

/**
* Schema for the record of all output written by all constructs
* The keys of the record are the package names of the constructs
*/
export const backendOutputSchema = z.record(backendOutputEntrySchema);

/**
* Inferred type from backendOutputSchema
*/
export type BackendOutput = z.infer<typeof backendOutputSchema>;
Loading