-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat(idempotency): create initial class structure for function idempotency #1086
Conversation
…ithub.com/jeffrey-baker-vg/aws-lambda-powertools-typescript into typescript-idempotency-initial-dev-branch
…itial-dev-branch Typescript idempotency initial dev branch
For reviewers (@dreamorosi @flochaz), here's a class diagram in Mermaid: Note that the scope of this design is only for FR2 (making a wrapper function for idempotency at function level) classDiagram
class IdempotencyRecord {
-status: string
+expiryTimestamp: number
+inProgressExpiryTimestamp: number
+responseData: string
+payloadHash: string
+getStatus() string
+isExpired() boolean
+responseJsonAsObject() Record<string, unknown>
}
class PersistenceLayerInterface{
<<interface>>
+configure(functionName: string)
+saveInProgress() void
+saveSuccess() void
+deleteRecord() void
+getRecord() Idempotency
}
class PersistenceLayer {
+constructor()
+configure(functionName: string)
+deleteRecord() void
+getRecord() IdempotencyRecord
+saveInProgress() void
+saveSuccess() void
#_deleteRecord()* void
#_getRecord()* IdempotencyRecord
#_putRecord(record: IdempotencyRecord)* void
#_updateRecord()* void
}
class DynamoDBPersistenceLayer {
#_deleteRecord()* void
#_getRecord()* IdempotencyRecord
#_putRecord(record: IdempotencyRecord)* void
#_updateRecord()* void
}
class makeFunctionIdempotent{
<<topLevelMethod>>
}
class IdempotencyOptions{
<<type>>
}
PersistenceLayerInterface <|-- PersistenceLayer
PersistenceLayer <|-- DynamoDBPersistenceLayer
IdempotencyRecord <..PersistenceLayer
IdempotencyRecord <..DynamoDBPersistenceLayer
PersistenceLayer<..IdempotencyOptions
IdempotencyOptions<..makeFunctionIdempotent
|
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.
I have a few changes requested and asked some questions.
@@ -0,0 +1,189 @@ | |||
@aws-lambda-powertools/commons |
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.
Apart from @aws-lambda-powertools/commons
, @types/aws-lambdaand
lodash`, let's remove the other libraries we are not sure if we will be using yet.
@@ -0,0 +1,83 @@ | |||
# AWS Lambda Powertools for TypeScript |
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.
To maintainers ( @flochaz @dreamorosi)
I know that this is all packages have the same copy. But this duplicates the top-level README.md
and confuses readers that there is a new information here that is different from the top-level one.
I propose having just a link to our documentation page for now. Then we can use this README.md
for any dev related items like design, class diagram, etc. The usages should always be the doc. Do you agree?
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.
Hi,
Until we publish the package we can use the README like you suggest since it won't be published anywhere. It's good to have design, class diagrams, etc. near the code & version controlled.
Once we start publishing the package on NPM however I would be inclined to follow the same structure we have for all the others since it's the "landing page" of the package on NPM and customers might arrive to that page without having seen our repo or our docs.
packages/idempotency/package.json
Outdated
{ | ||
"name": "@aws-lambda-powertools/idempotency", | ||
"version": "0.0.11", | ||
"description": "TBD", |
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.
"description": "TBD", | |
"description": "The idempotency package for the AWS Lambda Powertools for TypeScript library. It provides options to make your Lambda functions idempotent and safe to retry.", |
@@ -0,0 +1,8 @@ | |||
import { PersistenceLayer } from './persistence/PersistenceLayer'; | |||
|
|||
type IdempotencyOptions = { |
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.
(Note for reviewers): The term "Options" is consistent with other utilities (logger, metrics, tracer).
However, Python's idempotency uses the term "Config" instead (code). Still, I prefer "Options" as used here. It's more consistent. Let me know if you disagree.
|
||
class IdempotencyRecord { | ||
public constructor(public idempotencyKey: string, | ||
private status: string = '', |
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.
Shall we use an enum here instead?
Python uses these values. We should keep them consistent.
INPROGRESS
COMPLETED
EXPIRED
private status: string = '', | ||
public expiryTimestamp: number | undefined, | ||
public inProgressExpiryTimestamp: number | undefined, | ||
public responseData: string = '', |
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.
public responseData: string = '', | |
public responseData: string | undefined, |
Let's use undefined
to explicitly say that we don't have responseData
yet.
I doubt if any good API will return an empty string. But it could happen.
public async getRecord(): Promise<IdempotencyRecord> { | ||
return Promise.resolve({} as IdempotencyRecord); | ||
} | ||
public async saveInProgress(): Promise<void> { } |
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.
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { PersistenceLayerInterface } from './PersistenceLayerInterface'; | ||
|
||
class IdempotencyRecord { |
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.
Should we have this class in a separated file?
@jeffrey-baker-vg Also, please update the PR description and check any box that's relevant. |
feat: addressing comments in initial PR
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.
LGTM
Description of your changes
How to verify this change
Related issues, RFCs
Issue number:
PR status
Is this ready for review?: NO
Is it a breaking change?: NO
Checklist
Breaking change checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.