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

refactor(storage): add foundation deleteObject client #13795

Conversation

ashwinkumar6
Copy link
Member

@ashwinkumar6 ashwinkumar6 commented Sep 9, 2024

Description of changes

  • Add foundation DeleteObject client.
  • Duplicate code for the time being until all clients can be refactored into foundation. (smaller review PRs)
  • Add TODO, Question where appropriate
foundation
├── constants.ts
└── factories
    └── serviceClients
        ├── index.ts
        ├── s3data
        │   ├── constants.ts
        │   ├── deleteObject
        │   │   ├── createDeleteObjectClient.ts
        │   │   ├── createDeleteObjectDeserializer.ts
        │   │   └── createDeleteObjectSerializer.ts
        │   ├── endpointResolver.ts
        │   ├── index.ts
        │   ├── types
        │   │   ├── index.ts
        │   │   ├── sdk.ts
        │   │   └── serviceClient.ts
        │   └── validators
        │       └── isDnsCompatibleBucketName.ts
        └── shared
            ├── retryDecider.ts
            └── serdeUtils
                ├── deserializeBoolean.ts
                ├── deserializeMetadata.ts
                ├── serializeObjectConfigsToHeaders.ts
                ├── serializePathnameObjectKey.ts

Testing

  • Tested remove API on sampleApp

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashwinkumar6 ashwinkumar6 force-pushed the storage-browser/foundation/remove branch from f60b1fb to 328f0b2 Compare September 13, 2024 09:29
@ashwinkumar6 ashwinkumar6 marked this pull request as ready for review September 13, 2024 09:42
@ashwinkumar6 ashwinkumar6 changed the title refactor(storage): add client standard remove api refactor(storage): add foundation deleteObject client Sep 13, 2024
@ashwinkumar6 ashwinkumar6 requested a review from HuiSF September 17, 2024 19:53
@ashwinkumar6 ashwinkumar6 force-pushed the storage-browser/foundation/remove branch from edddbba to 024857b Compare September 17, 2024 22:33
@ashika112
Copy link
Member

High level looks good to me.

jimblanc
jimblanc previously approved these changes Sep 24, 2024
packages/storage/src/foundation/endpointResolver.ts Outdated Show resolved Hide resolved
Copy link
Member

@AllanZhengYP AllanZhengYP Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder structure under factories/serviceClient should better be this IMO:

factories/serviceClient
|_shared
   |_deserialization
   |_serialization
   |_parsePayload.ts // this can be moved into deserialization as well
   |_retryDecider.ts
|_index.ts
|_s3data
   |_constants.ts
   |_createDeleteObjectClient.ts
   |_index.ts
   |_validators
      |_isDnsCompatibleBucketName.ts

Let me what you think! @ashwinkumar6 @cshfang @HuiSF

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|_deserialization
|_serialization

We are using serde else where :D

Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to

foundation
├── constants.ts
└── factories
    └── serviceClients
        ├── index.ts
        ├── s3data
        │   ├── constants.ts
        │   ├── createDeleteObjectClient.ts
        │   ├── endpointResolver.ts
        │   ├── index.ts
        │   ├── shared
        │   │   └── serde
        │   │       ├── CreateDeleteObjectDeserializer.ts
        │   │       ├── CreateDeleteObjectSerializer.ts
        │   │       └── index.ts
        │   ├── types
        │   │   ├── index.ts
        │   │   ├── sdk.ts
        │   │   └── serviceClient.ts
        │   └── validators
        │       └── isDnsCompatibleBucketName.ts
        └── shared
            ├── retryDecider.ts
            └── serde
                ├── deserializeBoolean.ts
                ├── deserializeMetadata.ts
                ├── serializeObjectConfigsToHeaders.ts
                ├── serializePathnameObjectKey.ts......

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the things inside s3data/shared shared between? From the way it looks right now, the two functions don't look share-able?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tied to keep it similar to auth so it's easy to find clients/serde across packages.
But i see your point we can always add shared/serde if needed in future. updated

Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further discussion, every client has it's own specific serializer deserializer so we can create a folder for each client in this manner

s3data/deleteObject
|--createClient.ts
|--createDeserializer.ts
|--createSerializer.ts

dir structure

foundation
└── factories
    └── serviceClients
        ├── index.ts
        ├── s3data
        │   ├── constants.ts
        │   ├── deleteObject
        │   │   ├── createClient.ts
        │   │   ├── createDeserializer.ts
        │   │   └── createSerializer.ts
        │   ├── endpointResolver.ts
        │   ├── index.ts
        │   ├── types
        │   │   ├── index.ts
        │   │   ├── sdk.ts
        │   │   └── serviceClient.ts
        │   └── validators
        │       └── isDnsCompatibleBucketName.ts
        └── shared
            ├── retryDecider.ts
            └── serde
                ├── deserializeMetadata.ts
                ├── deserializeNumber.ts
                ├── serializeObjectConfigsToHeaders.ts
                ├── serializePathnameObjectKey.ts

Copy link
Member

@ashika112 ashika112 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions for me here:

  • having shared/serde makes it read like its all serializer or deserializer. Rather since these are utils for serde should we put it as shared/utils/serde or shared/serdeUtils?

Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to foundation/factories/serviceClients/shared/serde -> foundation/factories/serviceClients/shared/serdeUtils

latest dir structure cc @ashika112 @cshfang @HuiSF @AllanZhengYP

foundation
├── constants.ts
└── factories
    └── serviceClients
        ├── index.ts
        ├── s3data
        │   ├── constants.ts
        │   ├── deleteObject
        │   │   ├── createDeleteObjectClient.ts
        │   │   ├── createDeleteObjectDeserializer.ts
        │   │   └── createDeleteObjectSerializer.ts
        │   ├── endpointResolver.ts
        │   ├── index.ts
        │   ├── types
        │   │   ├── index.ts
        │   │   ├── sdk.ts
        │   │   └── serviceClient.ts
        │   └── validators
        │       └── isDnsCompatibleBucketName.ts
        └── shared
            ├── retryDecider.ts
            └── serdeUtils
                ├── deserializeBoolean.ts
                ├── deserializeMetadata.ts
                ├── serializeObjectConfigsToHeaders.ts
                ├── serializePathnameObjectKey.ts

packages/storage/src/providers/s3/apis/internal/remove.ts Outdated Show resolved Hide resolved
deserializer: (value: any[]) => T,
): T => {
if (value === '') {
return [] as any as T;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [] as any as T;
return [] as unknown as T;

Is this double casting really needed? as [] should conform to any[]?

Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to return [] as unknown as T;
Looks like double casting is needed [] as T gives error:

'never[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'any[]'


import { StorageError } from '../../../../../errors/StorageError';

export function validateS3RequiredParameter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in serde?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal comment to rename serde to serdeUtils since technically all of these are just utils/helpers not serde in itself.

With that in mind validateS3RequiredParameter is used by createDeleteObjectSerializer

@ashwinkumar6 ashwinkumar6 changed the base branch from storage-browser/integrity to storage-browser/foundation September 25, 2024 18:12
@ashwinkumar6 ashwinkumar6 requested a review from a team as a code owner September 25, 2024 18:12
@ashwinkumar6 ashwinkumar6 changed the base branch from storage-browser/foundation to storage-browser/integrity September 26, 2024 01:10
cshfang
cshfang previously approved these changes Sep 26, 2024
ashika112
ashika112 previously approved these changes Sep 26, 2024
@ashwinkumar6 ashwinkumar6 changed the base branch from storage-browser/integrity to storage-browser/foundation September 27, 2024 17:16
@ashwinkumar6 ashwinkumar6 dismissed stale reviews from ashika112 and cshfang via 30e5484 September 27, 2024 17:37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should me moved to the validators/ folder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will address this on the next PR

Copy link
Member

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I only had 1 non-blocking comment. feel free address it in follow PRs?

@ashwinkumar6 ashwinkumar6 merged commit 4e164ab into aws-amplify:storage-browser/foundation Sep 27, 2024
28 checks passed
@ashwinkumar6 ashwinkumar6 deleted the storage-browser/foundation/remove branch September 27, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants