-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract BackendIdentifierResolver (#270)
* refactor: extract BackendIdentifierResolver
- Loading branch information
1 parent
314677b
commit 813cdfb
Showing
10 changed files
with
95 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/backend-cli': patch | ||
--- | ||
|
||
Extract BackendIdentifierResolver into its own class |
35 changes: 35 additions & 0 deletions
35
packages/cli/src/backend-identifier/backend_identifier_resolver.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import assert from 'node:assert'; | ||
import { describe, it } from 'node:test'; | ||
import { BackendIdentifierResolver } from './backend_identifier_resolver.js'; | ||
|
||
describe('BackendIdentifierResolver', () => { | ||
it('returns an App Name and Branch identifier', async () => { | ||
const backendIdResolver = new BackendIdentifierResolver({ | ||
resolve: () => Promise.resolve('testAppName'), | ||
}); | ||
assert.deepEqual(await backendIdResolver.resolve({ branch: 'test' }), { | ||
appName: 'testAppName', | ||
branchName: 'test', | ||
}); | ||
}); | ||
it('returns a App Id identifier', async () => { | ||
const backendIdResolver = new BackendIdentifierResolver({ | ||
resolve: () => Promise.resolve('testAppName'), | ||
}); | ||
assert.deepEqual( | ||
await backendIdResolver.resolve({ appId: 'my-id', branch: 'my-branch' }), | ||
{ | ||
backendId: 'my-id', | ||
branchName: 'my-branch', | ||
} | ||
); | ||
}); | ||
it('returns a Stack name identifier', async () => { | ||
const backendIdResolver = new BackendIdentifierResolver({ | ||
resolve: () => Promise.resolve('testAppName'), | ||
}); | ||
assert.deepEqual(await backendIdResolver.resolve({ stack: 'my-stack' }), { | ||
stackName: 'my-stack', | ||
}); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/cli/src/backend-identifier/backend_identifier_resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BackendIdentifier } from '@aws-amplify/deployed-backend-client'; | ||
import { AppNameResolver } from './local_app_name_resolver.js'; | ||
|
||
type BackendIdentifierParameters = { | ||
stack?: string; | ||
appId?: string; | ||
branch?: string; | ||
}; | ||
/** | ||
* Translates args to BackendIdentifier. | ||
* Throws if translation can't be made (this should never happen if command validation works correctly). | ||
*/ | ||
export class BackendIdentifierResolver { | ||
/** | ||
* Instantiates BackendIdentifierResolver | ||
*/ | ||
constructor(private appNameResolver: AppNameResolver) {} | ||
resolve = async ( | ||
args: BackendIdentifierParameters | ||
): Promise<BackendIdentifier> => { | ||
if (args.stack) { | ||
return { stackName: args.stack }; | ||
} else if (args.appId && args.branch) { | ||
return { backendId: args.appId, branchName: args.branch }; | ||
} else if (args.branch) { | ||
return { | ||
appName: await this.appNameResolver.resolve(), | ||
branchName: args.branch, | ||
}; | ||
} | ||
throw new Error( | ||
'Unable to resolve BackendIdentifier with provided parameters' | ||
); | ||
}; | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/cli/src/local_app_name_resolver.ts → ...end-identifier/local_app_name_resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters