-
Notifications
You must be signed in to change notification settings - Fork 72
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
add basic function implementation #87
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f526892
add basic function implementation
edwardfoyle 179118a
switch to static factory for initializing functions
edwardfoyle 70391cc
update api extract
edwardfoyle 81e62ce
fix naming
edwardfoyle 67cad14
add tests
edwardfoyle fde3e2c
update package lock
edwardfoyle 563f3cb
update naming
edwardfoyle 693d232
update api extract
edwardfoyle d64dad1
add todo
edwardfoyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
# Be very careful editing this file. It is crafted to work around [this issue](https://github.com/npm/npm/issues/4479) | ||
|
||
# First ignore everything | ||
**/* | ||
|
||
# Then add back in transpiled js and ts declaration files | ||
!lib/**/*.js | ||
!lib/**/*.d.ts | ||
|
||
# Then ignore test js and ts declaration files | ||
*.test.js | ||
*.test.d.ts | ||
|
||
# This leaves us with including only js and ts declaration files of functional code |
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,40 @@ | ||
## API Report File for "@aws-amplify/backend-function" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
||
```ts | ||
|
||
import { AmplifyFunction } from '@aws-amplify/function-construct'; | ||
import { AmplifyFunctionProps } from '@aws-amplify/function-construct'; | ||
import { ConstructFactory } from '@aws-amplify/plugin-types'; | ||
import { ConstructFactoryGetInstanceProps } from '@aws-amplify/plugin-types'; | ||
|
||
// @public | ||
export class AmplifyFunctionFactory implements ConstructFactory<AmplifyFunction> { | ||
static build(props: AmplifyFunctionFactoryBuildProps): Promise<AmplifyFunctionFactory>; | ||
static fromDir(props: AmplifyFunctionFactoryFromDirProps): AmplifyFunctionFactory; | ||
getInstance({ constructContainer, }: ConstructFactoryGetInstanceProps): AmplifyFunction; | ||
} | ||
|
||
// @public (undocumented) | ||
export type AmplifyFunctionFactoryBaseProps = { | ||
name: string; | ||
}; | ||
|
||
// @public (undocumented) | ||
export type AmplifyFunctionFactoryBuildProps = AmplifyFunctionFactoryBaseProps & Omit<AmplifyFunctionProps, 'absoluteCodePath'> & { | ||
buildCommand: string; | ||
outDir: string; | ||
}; | ||
|
||
// @public (undocumented) | ||
export type AmplifyFunctionFactoryFromDirProps = AmplifyFunctionFactoryBaseProps & Omit<AmplifyFunctionProps, 'absoluteCodePath'> & { | ||
codePath: string; | ||
}; | ||
|
||
// @public | ||
export const Func: typeof AmplifyFunctionFactory; | ||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
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,3 @@ | ||
{ | ||
"extends": "../../api-extractor.base.json" | ||
} |
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,28 @@ | ||
{ | ||
"name": "@aws-amplify/backend-function", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"import": "./lib/index.js", | ||
"require": "./lib/index.js" | ||
} | ||
}, | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"update:api": "api-extractor run --local" | ||
}, | ||
"dependencies": { | ||
"@aws-amplify/function-construct": "^0.1.0", | ||
"execa": "^7.1.1" | ||
}, | ||
"devDependencies": { | ||
"@aws-amplify/backend-engine": "^0.1.0", | ||
"@aws-amplify/plugin-types": "^0.1.0" | ||
}, | ||
"peerDependencies": { | ||
"aws-cdk-lib": "~2.68.0", | ||
"constructs": "^10.0.0" | ||
} | ||
} |
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,74 @@ | ||
import { beforeEach, describe, it, mock } from 'node:test'; | ||
import { Func } from './factory.js'; | ||
import { App, Stack } from 'aws-cdk-lib'; | ||
import { | ||
NestedStackResolver, | ||
SingletonConstructContainer, | ||
StackMetadataBackendOutputStorageStrategy, | ||
} from '@aws-amplify/backend-engine'; | ||
import { | ||
BackendOutputEntry, | ||
BackendOutputStorageStrategy, | ||
ConstructContainer, | ||
} from '@aws-amplify/plugin-types'; | ||
import assert from 'node:assert'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
describe('AmplifyFunctionFactory', () => { | ||
let constructContainer: ConstructContainer; | ||
let outputStorageStrategy: BackendOutputStorageStrategy<BackendOutputEntry>; | ||
|
||
beforeEach(() => { | ||
const app = new App(); | ||
const stack = new Stack(app, 'testStack'); | ||
|
||
constructContainer = new SingletonConstructContainer( | ||
new NestedStackResolver(stack) | ||
); | ||
|
||
outputStorageStrategy = new StackMetadataBackendOutputStorageStrategy( | ||
stack | ||
); | ||
}); | ||
|
||
it('creates singleton function instance', () => { | ||
const functionFactory = Func.fromDir({ | ||
name: 'testFunc', | ||
codePath: '../test-assets/test-lambda', | ||
}); | ||
const instance1 = functionFactory.getInstance({ | ||
constructContainer, | ||
outputStorageStrategy, | ||
}); | ||
const instance2 = functionFactory.getInstance({ | ||
constructContainer, | ||
outputStorageStrategy, | ||
}); | ||
assert.strictEqual(instance1, instance2); | ||
}); | ||
|
||
it('executes build command from directory where constructor is used', async () => { | ||
const commandExecutorMock = mock.fn(); | ||
|
||
// Casting to never is necessary because commandExecutor is a private method. | ||
// TS yells that it's not a property on Func even though it is there | ||
mock.method(Func, 'commandExecutor' as never, commandExecutorMock); | ||
|
||
( | ||
await Func.build({ | ||
name: 'testFunc', | ||
outDir: '../test-assets/test-lambda', | ||
buildCommand: 'test command', | ||
}) | ||
).getInstance({ constructContainer, outputStorageStrategy }); | ||
|
||
assert.strictEqual(commandExecutorMock.mock.callCount(), 1); | ||
assert.deepStrictEqual(commandExecutorMock.mock.calls[0].arguments, [ | ||
'test command', | ||
{ | ||
cwd: fileURLToPath(new URL('../src', import.meta.url)), | ||
stdio: 'inherit', | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
factory method to produce factory that produces something :-)