diff --git a/.github/Architecture.md b/.github/Architecture.md index c140163d..dc8ac020 100644 --- a/.github/Architecture.md +++ b/.github/Architecture.md @@ -5,61 +5,61 @@ ``` 📦 training | |- 📂 training: +| | |- 📂 middleware: +| | | |- 📜 __init__.py +| | | |- 📜 health_check_middleware.py | | |- 📂 routes: -| | | |- 📂 tabular: -| | | | |- 📜 tabular.py +| | | |- 📂 datasets: +| | | | |- 📂 default: +| | | | | |- 📜 schemas.py +| | | | | |- 📜 __init__.py +| | | | | |- 📜 columns.py | | | | |- 📜 __init__.py -| | | | |- 📜 schemas.py | | | |- 📂 image: +| | | | |- 📜 schemas.py | | | | |- 📜 __init__.py | | | | |- 📜 image.py -| | | | |- 📜 schemas.py | | | |- 📂 audio: +| | | | |- 📜 schemas.py | | | | |- 📜 __init__.py | | | | |- 📜 audio.py +| | | |- 📂 tabular: | | | | |- 📜 schemas.py -| | | |- 📂 datasets: -| | | | |- 📂 default: -| | | | | |- 📜 columns.py -| | | | | |- 📜 __init__.py -| | | | | |- 📜 schemas.py | | | | |- 📜 __init__.py -| | | |- 📜 __init__.py +| | | | |- 📜 tabular.py | | | |- 📜 schemas.py -| | |- 📂 middleware: | | | |- 📜 __init__.py -| | | |- 📜 health_check_middleware.py | | |- 📂 core: | | | |- 📂 celery: +| | | | |- 📜 Dockerfile +| | | | |- 📜 __init__.py +| | | | |- 📜 optimizer.py : what optimizer to use (ie: SGD or Adam for now) +| | | | |- 📜 dataset.py : read in the dataset through URL or file upload +| | | | |- 📜 train_types.py | | | | |- 📜 trainer.py -| | | | |- 📜 criterion.py | | | | |- 📜 dl_model.py : torch model based on user specifications from drag and drop -| | | | |- 📜 train_types.py -| | | | |- 📜 dataset.py : read in the dataset through URL or file upload -| | | | |- 📜 __init__.py -| | | | |- 📜 Dockerfile +| | | | |- 📜 criterion.py | | | | |- 📜 worker.py -| | | | |- 📜 optimizer.py : what optimizer to use (ie: SGD or Adam for now) | | | |- 📜 __init__.py | | | |- 📜 authenticator.py -| | |- 📜 asgi.py -| | |- 📜 constants.py : list of helpful constants -| | |- 📜 celery_app.py -| | |- 📜 settings.py | | |- 📜 __init__.py | | |- 📜 wsgi.py -| | |- 📜 urls.py | | |- 📜 celeryconfig.py +| | |- 📜 settings.py +| | |- 📜 asgi.py +| | |- 📜 urls.py +| | |- 📜 celery_app.py +| | |- 📜 constants.py : list of helpful constants +| |- 📜 pytest.ini +| |- 📜 cli.py +| |- 📜 Dockerfile | |- 📜 README.md | |- 📜 docker-compose.yml -| |- 📜 cli.py +| |- 📜 docker-compose.prod.yml | |- 📜 pyproject.toml +| |- 📜 environment.yml | |- 📜 poetry.lock -| |- 📜 pytest.ini -| |- 📜 Dockerfile | |- 📜 manage.py -| |- 📜 environment.yml -| |- 📜 docker-compose.prod.yml ``` ## Frontend Architecture @@ -68,179 +68,179 @@ 📦 frontend | |- 📂 public: | | |- 📂 images: +| | | |- 📂 learn_mod_images: +| | | | |- 📜 neuralnet.png +| | | | |- 📜 ReLUactivation.png +| | | | |- 📜 binarystepactivation.png +| | | | |- 📜 neuron.png +| | | | |- 📜 sigmoidactivation.png +| | | | |- 📜 robotImage.jpg +| | | | |- 📜 LeakyReLUactivation.png +| | | | |- 📜 neuronWithEquation.png +| | | | |- 📜 lossExampleTable.png +| | | | |- 📜 lossExampleEquation.png +| | | | |- 📜 sigmoidfunction.png +| | | | |- 📜 tanhactivation.png +| | | | |- 📜 lossExample.png | | | |- 📂 logos: | | | | |- 📂 dlp_branding: -| | | | | |- 📜 dlp-logo.png : DLP Logo, duplicate of files in public, but essential as the frontend can't read public | | | | | |- 📜 dlp-logo.svg : DLP Logo, duplicate of files in public, but essential as the frontend can't read public -| | | | |- 📜 dsgt-logo-white-back.png +| | | | | |- 📜 dlp-logo.png : DLP Logo, duplicate of files in public, but essential as the frontend can't read public +| | | | |- 📜 dsgt-logo-light.png +| | | | |- 📜 pytorch-logo.png | | | | |- 📜 python-logo.png | | | | |- 📜 google.png -| | | | |- 📜 pandas-logo.png -| | | | |- 📜 react-logo.png -| | | | |- 📜 flask-logo.png | | | | |- 📜 aws-logo.png | | | | |- 📜 github.png +| | | | |- 📜 flask-logo.png +| | | | |- 📜 dsgt-logo-white-back.png | | | | |- 📜 dsgt-logo-dark.png -| | | | |- 📜 dsgt-logo-light.png -| | | | |- 📜 pytorch-logo.png -| | | |- 📂 learn_mod_images: -| | | | |- 📜 neuron.png -| | | | |- 📜 ReLUactivation.png -| | | | |- 📜 LeakyReLUactivation.png -| | | | |- 📜 lossExampleEquation.png -| | | | |- 📜 lossExampleTable.png -| | | | |- 📜 robotImage.jpg -| | | | |- 📜 neuralnet.png -| | | | |- 📜 sigmoidfunction.png -| | | | |- 📜 lossExample.png -| | | | |- 📜 tanhactivation.png -| | | | |- 📜 binarystepactivation.png -| | | | |- 📜 sigmoidactivation.png -| | | | |- 📜 neuronWithEquation.png +| | | | |- 📜 react-logo.png +| | | | |- 📜 pandas-logo.png | | | |- 📂 wiki_images: | | | | |- 📜 sigmoid_equation.png | | | | |- 📜 conv2d.gif -| | | | |- 📜 conv2d2.gif -| | | | |- 📜 avgpool_maxpool.gif | | | | |- 📜 softmax_equation.png : PNG file of Softmax equation -| | | | |- 📜 dropout_diagram.png | | | | |- 📜 batchnorm_diagram.png +| | | | |- 📜 dropout_diagram.png | | | | |- 📜 maxpool2d.gif +| | | | |- 📜 conv2d2.gif | | | | |- 📜 tanh_equation.png +| | | | |- 📜 avgpool_maxpool.gif | | | | |- 📜 tanh_plot.png | | | |- 📜 demo_video.gif : GIF tutorial of a simple classification training session -| | |- 📜 dlp-logo.ico : DLP Logo | | |- 📜 manifest.json : Default React file for choosing icon based on -| | |- 📜 index.html : Base HTML file that will be initially rendered | | |- 📜 robots.txt +| | |- 📜 index.html : Base HTML file that will be initially rendered +| | |- 📜 dlp-logo.ico : DLP Logo | |- 📂 layer_docs: | | |- 📜 Softmax.md : Doc for Softmax layer -| | |- 📜 Linear.md : Doc for Linear layer | | |- 📜 softmax_equation.png : PNG file of Softmax equation +| | |- 📜 Linear.md : Doc for Linear layer | | |- 📜 ReLU.md : Doc for ReLU later | |- 📂 src: -| | |- 📂 __tests__: -| | | |- 📂 common: -| | | | |- 📂 components: -| | | | | |- 📜 TitleText.test.tsx -| | |- 📂 backend_outputs: -| | | |- 📜 my_deep_learning_model.onnx : Last ONNX file output -| | | |- 📜 model.pkl -| | | |- 📜 model.pt : Last model.pt output -| | |- 📂 common: -| | | |- 📂 styles: -| | | | |- 📜 Home.module.css -| | | | |- 📜 globals.css -| | | |- 📂 redux: -| | | | |- 📜 hooks.ts -| | | | |- 📜 store.ts -| | | | |- 📜 train.ts -| | | | |- 📜 backendApi.ts -| | | | |- 📜 userLogin.ts -| | | |- 📂 utils: -| | | | |- 📜 dateFormat.ts -| | | | |- 📜 firebase.ts -| | | | |- 📜 dndHelpers.ts -| | | |- 📂 components: -| | | | |- 📜 EmailInput.tsx -| | | | |- 📜 HtmlTooltip.tsx -| | | | |- 📜 NavBarMain.tsx -| | | | |- 📜 Footer.tsx -| | | | |- 📜 DlpTooltip.tsx -| | | | |- 📜 ClientOnlyPortal.tsx -| | | | |- 📜 Spacer.tsx -| | | | |- 📜 TitleText.tsx +| | |- 📂 pages: +| | | |- 📂 train: +| | | | |- 📜 [train_space_id].tsx +| | | | |- 📜 index.tsx +| | | | |- 📜 metrics_to_charts.tsx +| | | |- 📜 settings.tsx +| | | |- 📜 dashboard.tsx +| | | |- 📜 login.tsx +| | | |- 📜 learn.tsx +| | | |- 📜 _app.tsx +| | | |- 📜 _document.tsx +| | | |- 📜 LearnContent.tsx +| | | |- 📜 feedback.tsx +| | | |- 📜 forgot.tsx +| | | |- 📜 wiki.tsx +| | | |- 📜 about.tsx | | |- 📂 features: -| | | |- 📂 LearnMod: -| | | | |- 📜 MCQuestion.tsx -| | | | |- 📜 ModulesSideBar.tsx -| | | | |- 📜 ImageComponent.tsx -| | | | |- 📜 ClassCard.tsx -| | | | |- 📜 FRQuestion.tsx -| | | | |- 📜 Exercise.tsx -| | | | |- 📜 LearningModulesContent.tsx -| | | |- 📂 OpenAi: -| | | | |- 📜 openAiUtils.ts -| | | |- 📂 Dashboard: -| | | | |- 📂 redux: -| | | | | |- 📜 dashboardApi.ts -| | | | |- 📂 components: -| | | | | |- 📜 TrainBarChart.tsx -| | | | | |- 📜 TrainDoughnutChart.tsx -| | | | | |- 📜 TrainDataGrid.tsx | | | |- 📂 Train: -| | | | |- 📂 redux: -| | | | | |- 📜 trainspaceSlice.ts -| | | | | |- 📜 trainspaceApi.ts -| | | | |- 📂 types: -| | | | | |- 📜 trainTypes.ts -| | | | |- 📂 constants: -| | | | | |- 📜 trainConstants.ts +| | | | |- 📂 components: +| | | | | |- 📜 DatasetStepLayout.tsx +| | | | | |- 📜 CreateTrainspace.tsx +| | | | | |- 📜 TrainspaceLayout.tsx | | | | |- 📂 features: -| | | | | |- 📂 Tabular: -| | | | | | |- 📂 redux: -| | | | | | | |- 📜 tabularActions.ts -| | | | | | | |- 📜 tabularApi.ts -| | | | | | |- 📂 types: -| | | | | | | |- 📜 tabularTypes.ts +| | | | | |- 📂 Image: +| | | | | | |- 📂 components: +| | | | | | | |- 📜 ImageFlow.tsx +| | | | | | | |- 📜 ImageParametersStep.tsx +| | | | | | | |- 📜 ImageDatasetStep.tsx +| | | | | | | |- 📜 ImageReviewStep.tsx +| | | | | | | |- 📜 ImageTrainspace.tsx | | | | | | |- 📂 constants: -| | | | | | | |- 📜 tabularConstants.ts +| | | | | | | |- 📜 imageConstants.ts +| | | | | | |- 📂 types: +| | | | | | | |- 📜 imageTypes.ts +| | | | | | |- 📂 redux: +| | | | | | | |- 📜 imageApi.ts +| | | | | | | |- 📜 imageActions.ts +| | | | | | |- 📜 index.ts +| | | | | |- 📂 Tabular: | | | | | | |- 📂 components: +| | | | | | | |- 📜 TabularParametersStep.tsx +| | | | | | | |- 📜 TabularFlow.tsx | | | | | | | |- 📜 TabularTrainspace.tsx | | | | | | | |- 📜 TabularReviewStep.tsx -| | | | | | | |- 📜 TabularParametersStep.tsx | | | | | | | |- 📜 TabularDatasetStep.tsx -| | | | | | | |- 📜 TabularFlow.tsx -| | | | | | |- 📜 index.ts -| | | | | |- 📂 Image: -| | | | | | |- 📂 redux: -| | | | | | | |- 📜 imageApi.ts -| | | | | | | |- 📜 imageActions.ts -| | | | | | |- 📂 types: -| | | | | | | |- 📜 imageTypes.ts | | | | | | |- 📂 constants: -| | | | | | | |- 📜 imageConstants.ts -| | | | | | |- 📂 components: -| | | | | | | |- 📜 ImageReviewStep.tsx -| | | | | | | |- 📜 ImageTrainspace.tsx -| | | | | | | |- 📜 ImageFlow.tsx -| | | | | | | |- 📜 ImageParametersStep.tsx -| | | | | | | |- 📜 ImageDatasetStep.tsx +| | | | | | | |- 📜 tabularConstants.ts +| | | | | | |- 📂 types: +| | | | | | | |- 📜 tabularTypes.ts +| | | | | | |- 📂 redux: +| | | | | | | |- 📜 tabularActions.ts +| | | | | | | |- 📜 tabularApi.ts | | | | | | |- 📜 index.ts -| | | | |- 📂 components: -| | | | | |- 📜 CreateTrainspace.tsx -| | | | | |- 📜 DatasetStepLayout.tsx -| | | | | |- 📜 TrainspaceLayout.tsx +| | | | |- 📂 constants: +| | | | | |- 📜 trainConstants.ts +| | | | |- 📂 types: +| | | | | |- 📜 trainTypes.ts +| | | | |- 📂 redux: +| | | | | |- 📜 trainspaceApi.ts +| | | | | |- 📜 trainspaceSlice.ts +| | | |- 📂 LearnMod: +| | | | |- 📜 FRQuestion.tsx +| | | | |- 📜 Exercise.tsx +| | | | |- 📜 ClassCard.tsx +| | | | |- 📜 ImageComponent.tsx +| | | | |- 📜 ModulesSideBar.tsx +| | | | |- 📜 MCQuestion.tsx +| | | | |- 📜 LearningModulesContent.tsx | | | |- 📂 Feedback: | | | | |- 📂 redux: | | | | | |- 📜 feedbackApi.ts -| | |- 📂 pages: -| | | |- 📂 train: -| | | | |- 📜 [train_space_id].tsx -| | | | |- 📜 metrics_to_charts.tsx -| | | | |- 📜 index.tsx -| | | |- 📜 _app.tsx -| | | |- 📜 forgot.tsx -| | | |- 📜 about.tsx -| | | |- 📜 settings.tsx -| | | |- 📜 _document.tsx -| | | |- 📜 feedback.tsx -| | | |- 📜 dashboard.tsx -| | | |- 📜 learn.tsx -| | | |- 📜 LearnContent.tsx -| | | |- 📜 login.tsx -| | | |- 📜 wiki.tsx -| | |- 📜 constants.ts +| | | |- 📂 OpenAi: +| | | | |- 📜 openAiUtils.ts +| | | |- 📂 Dashboard: +| | | | |- 📂 components: +| | | | | |- 📜 TrainDataGrid.tsx +| | | | | |- 📜 TrainBarChart.tsx +| | | | | |- 📜 TrainDoughnutChart.tsx +| | | | |- 📂 redux: +| | | | | |- 📜 dashboardApi.ts +| | |- 📂 common: +| | | |- 📂 components: +| | | | |- 📜 EmailInput.tsx +| | | | |- 📜 ClientOnlyPortal.tsx +| | | | |- 📜 Footer.tsx +| | | | |- 📜 TitleText.tsx +| | | | |- 📜 NavBarMain.tsx +| | | | |- 📜 Spacer.tsx +| | | | |- 📜 DlpTooltip.tsx +| | | | |- 📜 HtmlTooltip.tsx +| | | |- 📂 utils: +| | | | |- 📜 dateFormat.ts +| | | | |- 📜 firebase.ts +| | | | |- 📜 dndHelpers.ts +| | | |- 📂 styles: +| | | | |- 📜 globals.css +| | | | |- 📜 Home.module.css +| | | |- 📂 redux: +| | | | |- 📜 train.ts +| | | | |- 📜 backendApi.ts +| | | | |- 📜 userLogin.ts +| | | | |- 📜 hooks.ts +| | | | |- 📜 store.ts +| | |- 📂 __tests__: +| | | |- 📂 common: +| | | | |- 📂 components: +| | | | | |- 📜 TitleText.test.tsx +| | |- 📂 backend_outputs: +| | | |- 📜 my_deep_learning_model.onnx : Last ONNX file output +| | | |- 📜 model.pt : Last model.pt output +| | | |- 📜 model.pkl +| | |- 📜 next-env.d.ts | | |- 📜 iris.csv : Sample CSV data | | |- 📜 GlobalStyle.ts -| | |- 📜 next-env.d.ts -| |- 📜 pnpm-lock.yaml +| | |- 📜 constants.ts | |- 📜 tsconfig.json +| |- 📜 pnpm-lock.yaml | |- 📜 package.json -| |- 📜 .eslintrc.json | |- 📜 next.config.js -| |- 📜 next-env.d.ts | |- 📜 jest.config.ts +| |- 📜 next-env.d.ts | |- 📜 .eslintignore +| |- 📜 .eslintrc.json ``` diff --git a/serverless/packages/functions/src/trainspace/tests/create_trainspace.test.ts b/serverless/packages/functions/src/trainspace/tests/create_trainspace.test.ts index 5eab2c16..ed03877c 100644 --- a/serverless/packages/functions/src/trainspace/tests/create_trainspace.test.ts +++ b/serverless/packages/functions/src/trainspace/tests/create_trainspace.test.ts @@ -4,6 +4,8 @@ import { DynamoDBClient, PutItemCommand} from '@aws-sdk/client-dynamodb'; import { mockClient } from 'aws-sdk-client-mock'; import { handler } from '../create_trainspace'; +//note: event declaration errors are supressed becasue we only need +// certain parts of them for that specific function //mocks parseJwt so that the call just returns whatever the input is vi.mock('@dlp-sst-app/core/src/parseJwt', async () => { return { @@ -23,7 +25,7 @@ it("test successful create trainspace call", async () => { httpStatusCode: 200, } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : we only need authorization and body const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -48,7 +50,7 @@ it("test internal service error", async () => { httpStatusCode: 456, } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -73,7 +75,7 @@ it("test undefined event", async () => { httpStatusCode: 400, } }) - // @ts-expect-error : we are trying to cause an error + //@ts-expect-error : see test name const result = await handler(undefined); expect(result.statusCode).toEqual(404); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/trainspace/tests/delete_all_trainspace.test.ts b/serverless/packages/functions/src/trainspace/tests/delete_all_trainspace.test.ts index d137ee3f..8fd16a11 100644 --- a/serverless/packages/functions/src/trainspace/tests/delete_all_trainspace.test.ts +++ b/serverless/packages/functions/src/trainspace/tests/delete_all_trainspace.test.ts @@ -4,7 +4,6 @@ import { DynamoDBClient, QueryCommand, BatchExecuteStatementCommand } from '@aws import { mockClient } from 'aws-sdk-client-mock'; import { handler } from '../delete_all_trainspace'; - //mocks parseJwt so that the call just returns whatever the input is vi.mock('@dlp-sst-app/core/src/parseJwt', async () => { return { @@ -31,7 +30,7 @@ it("test successful delete all trainspace call", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : we only need the authorization const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -56,7 +55,7 @@ it("test no batch delete response call", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : see above note const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -81,7 +80,7 @@ it("test incorrect batch delete response failed call", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -104,7 +103,7 @@ it("test delete all on no existing trainspaces call", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -117,7 +116,7 @@ it("test delete all on no existing trainspaces call", async () => { it("test malformed call", async () => { - // @ts-expect-error : we are trying to cause an error + //@ts-expect-error : testing call with undefined parameters const result = await handler(undefined); expect(result.statusCode).toEqual(400); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/trainspace/tests/delete_trainspace.test.ts b/serverless/packages/functions/src/trainspace/tests/delete_trainspace.test.ts index e0d840a7..53cb7b7d 100644 --- a/serverless/packages/functions/src/trainspace/tests/delete_trainspace.test.ts +++ b/serverless/packages/functions/src/trainspace/tests/delete_trainspace.test.ts @@ -23,7 +23,7 @@ it("test successful delete trainspace call", async () => { httpStatusCode: 200, } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : we only need authorization, id, and a body const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -50,7 +50,7 @@ it("test no response failed operation call", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : same as above const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -76,7 +76,7 @@ it("test different status code failed operation call", async () => { httpStatusCode: 267, } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : see above const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -102,7 +102,7 @@ it("test no trainspace id given", async () => { } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error : we are giving an empty event const event: APIGatewayProxyEventV2 = { pathParameters: { } @@ -114,7 +114,7 @@ it("test no trainspace id given", async () => { it("test malformed call", async () => { - // @ts-expect-error : we are trying to cause an error + // @ts-expect-error : testing for null parameter response const result = await handler(undefined); expect(result.statusCode).toEqual(400); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/trainspace/tests/get_all_trainspace.test.ts b/serverless/packages/functions/src/trainspace/tests/get_all_trainspace.test.ts index 00ba8dfc..894da762 100644 --- a/serverless/packages/functions/src/trainspace/tests/get_all_trainspace.test.ts +++ b/serverless/packages/functions/src/trainspace/tests/get_all_trainspace.test.ts @@ -25,7 +25,7 @@ it("test successful get all trainspace call", async () => { }], "Count": 4 }); - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -42,7 +42,7 @@ it("test no existing trainspaces for user id", async () => { Items: undefined }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -54,7 +54,7 @@ it("test no existing trainspaces for user id", async () => { }); it("test malformed request", async () => { - // @ts-expect-error : we are trying to cause an error + //@ts-expect-error const result = await handler(undefined); expect(result.statusCode).toEqual(400); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/trainspace/tests/get_trainspace.test.ts b/serverless/packages/functions/src/trainspace/tests/get_trainspace.test.ts index fe8f7e2c..6aead77d 100644 --- a/serverless/packages/functions/src/trainspace/tests/get_trainspace.test.ts +++ b/serverless/packages/functions/src/trainspace/tests/get_trainspace.test.ts @@ -23,7 +23,7 @@ it("test successful get trainspace call", async () => { Item: { trainspaceID: { S: 'sample trainspace id' } } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { pathParameters: { id: "some trainspace_id" @@ -40,7 +40,7 @@ it("test no existing trainspace id", async () => { Item: undefined }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { pathParameters: { id: "some trainspace_id" @@ -56,7 +56,7 @@ it("test no trainspace id given", async () => { Item: { trainspaceID: { S: 'sample trainspace id' } } }) - // @ts-expect-error : error doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { pathParameters: { } @@ -67,7 +67,7 @@ it("test no trainspace id given", async () => { }); it("test malformed request", async () => { - // @ts-expect-error : we are trying to cause an error + //@ts-expect-error const result = await handler(undefined); expect(result.statusCode).toEqual(400); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/user/create_user.ts b/serverless/packages/functions/src/user/create_user.ts index 3072563c..5419cc67 100644 --- a/serverless/packages/functions/src/user/create_user.ts +++ b/serverless/packages/functions/src/user/create_user.ts @@ -1,21 +1,20 @@ import { APIGatewayProxyHandlerV2, APIGatewayProxyEventV2 } from "aws-lambda"; import parseJwt from "@dlp-sst-app/core/src/parseJwt"; import { v4 as uuidv4 } from 'uuid'; -import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -import { DynamoDBDocumentClient, PutCommand, PutCommandInput } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient, PutItemCommand, PutItemCommandInput } from '@aws-sdk/client-dynamodb'; export async function handler(event : APIGatewayProxyEventV2) { if (event) { const user_id: string = parseJwt(event.headers.authorization ?? "")["user_id"]; const eventBody = JSON.parse(event.body? event.body : ""); - let putCommandInput: PutCommandInput = { + let putCommandInput: PutItemCommandInput = { TableName: "UserTable", Item: { - user_id: user_id, - name: eventBody['name'], - email: eventBody['email'], - phone: eventBody['phone'] + user_id: {"S": user_id}, + name: {"S": eventBody['name']}, + email: {"S": eventBody['email']}, + phone: {"S": eventBody['phone']} } } @@ -28,10 +27,9 @@ export async function handler(event : APIGatewayProxyE } const client = new DynamoDBClient({}); - const docClient = DynamoDBDocumentClient.from(client); - const command = new PutCommand(putCommandInput); - const response = await docClient.send(command); + const command = new PutItemCommand(putCommandInput); + const response = await client.send(command); if (response.$metadata.httpStatusCode != 200) { return { diff --git a/serverless/packages/functions/src/user/delete_user.ts b/serverless/packages/functions/src/user/delete_user.ts index fdcb216f..315678ea 100644 --- a/serverless/packages/functions/src/user/delete_user.ts +++ b/serverless/packages/functions/src/user/delete_user.ts @@ -1,6 +1,5 @@ -import { APIGatewayProxyHandlerV2, APIGatewayProxyEventV2 } from "aws-lambda"; -import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -import { DynamoDBDocumentClient, DeleteCommand } from '@aws-sdk/lib-dynamodb'; +import { APIGatewayProxyEventV2 } from "aws-lambda"; +import { DynamoDBClient, DeleteItemCommand } from '@aws-sdk/client-dynamodb'; import parseJwt from "@dlp-sst-app/core/src/parseJwt"; export async function handler(event : APIGatewayProxyEventV2) { @@ -8,17 +7,16 @@ export async function handler(event : APIGatewayProxyE const user_id: string = parseJwt(event.headers.authorization ?? "")["user_id"]; const client = new DynamoDBClient({}); - const docClient = DynamoDBDocumentClient.from(client); - const command = new DeleteCommand({ + const command = new DeleteItemCommand({ TableName : "UserTable", Key : { - user_id: user_id + user_id: {"S": user_id} } }); - const response = await docClient.send(command); + const response = await client.send(command); if (response.$metadata.httpStatusCode == undefined || response.$metadata.httpStatusCode != 200) { diff --git a/serverless/packages/functions/src/user/get_user.ts b/serverless/packages/functions/src/user/get_user.ts index ada5d2f4..fa2886c6 100644 --- a/serverless/packages/functions/src/user/get_user.ts +++ b/serverless/packages/functions/src/user/get_user.ts @@ -1,6 +1,5 @@ -import { APIGatewayProxyHandlerV2, APIGatewayProxyEventV2 } from "aws-lambda"; -import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb'; +import { APIGatewayProxyEventV2 } from "aws-lambda"; +import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'; import parseJwt from "@dlp-sst-app/core/src/parseJwt"; export async function handler(event : APIGatewayProxyEventV2) { @@ -8,17 +7,16 @@ export async function handler(event : APIGatewayProxyE { const user_id: string = parseJwt(event.headers.authorization ?? "")["user_id"]; const client: DynamoDBClient = new DynamoDBClient({}); - const docClient = DynamoDBDocumentClient.from(client); - const command : GetCommand = new GetCommand({ + const command : GetItemCommand = new GetItemCommand({ TableName : "UserTable", Key : { - user_id : user_id + user_id : {"S": user_id} } }); - const response = await docClient.send(command); + const response = await client.send(command); if (!response.Item) { diff --git a/serverless/packages/functions/src/user/tests/create_user.test.ts b/serverless/packages/functions/src/user/tests/create_user.test.ts index 215a43c4..4ea3b845 100644 --- a/serverless/packages/functions/src/user/tests/create_user.test.ts +++ b/serverless/packages/functions/src/user/tests/create_user.test.ts @@ -1,10 +1,11 @@ import { APIGatewayProxyEventV2 } from "aws-lambda"; import { beforeEach, expect, it, vi} from "vitest"; -import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb'; import { mockClient } from 'aws-sdk-client-mock'; import { handler } from '../create_user'; - +//note: event declaration errors are supressed becasue we only need +//certain parts of them for that specific function //mocks parseJwt so that the call just returns whatever the input is vi.mock('@dlp-sst-app/core/src/parseJwt', async () => { return { @@ -16,15 +17,15 @@ beforeEach(async () => { ddbMock.reset(); }) -const ddbMock = mockClient(DynamoDBDocumentClient); +const ddbMock = mockClient(DynamoDBClient); it("test successful create user call", async () => { - ddbMock.on(PutCommand).resolves({ + ddbMock.on(PutItemCommand).resolves({ $metadata: { httpStatusCode: 200, } }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -40,12 +41,12 @@ it("test successful create user call", async () => { }); it("test internal service error", async () => { - ddbMock.on(PutCommand).resolves({ + ddbMock.on(PutItemCommand).resolves({ $metadata: { httpStatusCode: 456, } }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -62,11 +63,12 @@ it("test internal service error", async () => { }); it("test undefined event", async () => { - ddbMock.on(PutCommand).resolves({ + ddbMock.on(PutItemCommand).resolves({ $metadata: { httpStatusCode: 400, } }) + //@ts-expect-error const result = await handler(undefined); expect(result.statusCode).toEqual(404); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/user/tests/delete_user.test.ts b/serverless/packages/functions/src/user/tests/delete_user.test.ts index 5809e35e..709ed395 100644 --- a/serverless/packages/functions/src/user/tests/delete_user.test.ts +++ b/serverless/packages/functions/src/user/tests/delete_user.test.ts @@ -1,10 +1,9 @@ import { APIGatewayProxyEventV2 } from "aws-lambda"; import { beforeEach, expect, it, vi} from "vitest"; -import { DeleteCommand, DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient, DeleteItemCommand } from '@aws-sdk/client-dynamodb'; import { mockClient } from 'aws-sdk-client-mock'; import { handler } from '../delete_user'; - //mocks parseJwt so that the call just returns whatever the input is vi.mock('@dlp-sst-app/core/src/parseJwt', async () => { return { @@ -16,15 +15,15 @@ beforeEach(async () => { ddbMock.reset(); }) -const ddbMock = mockClient(DynamoDBDocumentClient); +const ddbMock = mockClient(DynamoDBClient); it("test successful delete user call", async () => { - ddbMock.on(DeleteCommand).resolves({ + ddbMock.on(DeleteItemCommand).resolves({ $metadata: { httpStatusCode: 200, } }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -41,12 +40,13 @@ it("test successful delete user call", async () => { }); it("test no response failed operation call", async () => { - ddbMock.on(DeleteCommand).resolves({ + ddbMock.on(DeleteItemCommand).resolves({ $metadata: { httpStatusCode: undefined, } }) + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -63,12 +63,12 @@ it("test no response failed operation call", async () => { }); it("test different status code failed operation call", async () => { - ddbMock.on(DeleteCommand).resolves({ + ddbMock.on(DeleteItemCommand).resolves({ $metadata: { httpStatusCode: 267, } }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -85,6 +85,7 @@ it("test different status code failed operation call", async () => { }); it("test malformed call", async () => { - const result = await handler(undefined); - expect(result.statusCode).toEqual(400); + //@ts-expect-error + const result = await handler(undefined); + expect(result.statusCode).toEqual(400); }); \ No newline at end of file diff --git a/serverless/packages/functions/src/user/tests/get_user.test.ts b/serverless/packages/functions/src/user/tests/get_user.test.ts index 661b122b..1107017c 100644 --- a/serverless/packages/functions/src/user/tests/get_user.test.ts +++ b/serverless/packages/functions/src/user/tests/get_user.test.ts @@ -1,6 +1,6 @@ import { APIGatewayProxyEventV2 } from "aws-lambda"; import { beforeEach, expect, it, vi} from "vitest"; -import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'; import { mockClient } from 'aws-sdk-client-mock'; import { handler } from '../get_user'; @@ -15,14 +15,14 @@ beforeEach(async () => { ddbMock.reset(); }) -const ddbMock = mockClient(DynamoDBDocumentClient); +const ddbMock = mockClient(DynamoDBClient); it("test successful get user call", async () => { - ddbMock.on(GetCommand).resolves({ + ddbMock.on(GetItemCommand).resolves({ Item: { user_id: { S: 'UID' } } }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -34,11 +34,11 @@ it("test successful get user call", async () => { }); it("test no existing user id", async () => { - ddbMock.on(GetCommand).resolves({ + ddbMock.on(GetItemCommand).resolves({ Item: undefined }) - //error is fine, doesn't affect functionality. We don't need the rest of the event, and it's really long for no reason + //@ts-expect-error const event: APIGatewayProxyEventV2 = { headers: { authorization: 'abcd', @@ -50,7 +50,7 @@ it("test no existing user id", async () => { }); it("test malformed request", async () => { - + //@ts-expect-error const result = await handler(undefined); expect(result.statusCode).toEqual(400); }); \ No newline at end of file