@@ -29,6 +29,11 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
29
29
this . functionName = this . getEnvVarsService ( ) . getLambdaFunctionName ( ) + '.' + functionName ;
30
30
}
31
31
32
+ /**
33
+ * Deletes a record from the persistence store for the persistence key generated from the data passed in.
34
+ *
35
+ * @param data - the data payload that will be hashed to create the hash portion of the idempotency key
36
+ */
32
37
public async deleteRecord ( data : unknown ) : Promise < void > {
33
38
const idempotencyRecord : IdempotencyRecord =
34
39
new IdempotencyRecord ( this . getHashedIdempotencyKey ( data ) ,
@@ -41,7 +46,11 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
41
46
42
47
this . _deleteRecord ( idempotencyRecord ) ;
43
48
}
44
-
49
+ /**
50
+ * Retrieves idempotency key for the provided data and fetches data for that key from the persistence store
51
+ *
52
+ * @param data - the data payload that will be hashed to create the hash portion of the idempotency key
53
+ */
45
54
public async getRecord ( data : unknown ) : Promise < IdempotencyRecord > {
46
55
const idempotencyKey : string = this . getHashedIdempotencyKey ( data ) ;
47
56
@@ -66,6 +75,13 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
66
75
return this . _putRecord ( idempotencyRecord ) ;
67
76
}
68
77
78
+ /**
79
+ * Saves a record of the function completing successfully. This will create a record with a COMPLETED status
80
+ * and will save the result of the completed function in the idempotency record.
81
+ *
82
+ * @param data - the data payload that will be hashed to create the hash portion of the idempotency key
83
+ * @param result - the result of the successfully completed function
84
+ */
69
85
public async saveSuccess ( data : unknown , result : unknown ) : Promise < void > {
70
86
const idempotencyRecord : IdempotencyRecord =
71
87
new IdempotencyRecord ( this . getHashedIdempotencyKey ( data ) ,
@@ -85,6 +101,12 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
85
101
protected abstract _putRecord ( record : IdempotencyRecord ) : Promise < void > ;
86
102
protected abstract _updateRecord ( record : IdempotencyRecord ) : Promise < void > ;
87
103
104
+ /**
105
+ * Generates a hash of the data and returns the digest of that hash
106
+ *
107
+ * @param data the data payload that will generate the hash
108
+ * @returns the digest of the generated hash
109
+ */
88
110
private generateHash ( data : string ) : string {
89
111
const hash : Hash = createHash ( this . hashFunction ) ;
90
112
hash . update ( data ) ;
@@ -100,12 +122,23 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
100
122
return this . envVarsService ;
101
123
}
102
124
125
+ /**
126
+ * Creates the expiry timestamp for the idempotency record
127
+ *
128
+ * @returns the expiry time for the record expressed as number of seconds past the UNIX epoch
129
+ */
103
130
private getExpiryTimestamp ( ) : number {
104
131
const currentTime : number = Date . now ( ) / 1000 ;
105
132
106
133
return currentTime + this . expiresAfterSeconds ;
107
134
}
108
135
136
+ /**
137
+ * Generates the idempotency key used to identify records in the persistence store.
138
+ *
139
+ * @param data the data payload that will be hashed to create the hash portion of the idempotency key
140
+ * @returns the idempotency key
141
+ */
109
142
private getHashedIdempotencyKey ( data : unknown ) : string {
110
143
if ( ! data ) {
111
144
console . warn ( 'No data found for idempotency key' ) ;
0 commit comments