Skip to content

Commit 179c684

Browse files
refactor(dynamo-rx): rename to dynamo-promisified
and add some doc for promise-delay and promise-tap
1 parent 1cb9882 commit 179c684

34 files changed

+89
-81
lines changed

src/dynamo/batchget/batch-get-utils.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
2-
import { DynamoRx } from '../dynamo-rx'
2+
import { DynamoPromisified } from '../dynamo-promisified'
33
import { batchGetItemsFetchAll, combineBatchGetResponses, hasUnprocessedKeys } from './batch-get-utils'
44

55
describe('batch-get utils', () => {
@@ -51,7 +51,7 @@ describe('batch-get utils', () => {
5151

5252
describe('batchGetItemsFetchAll', () => {
5353
let batchGetItemsSpy: jasmine.Spy
54-
let dynamoRx: DynamoRx
54+
let dynamoRx: DynamoPromisified
5555
let backoffTimerMock: { next: jasmine.Spy }
5656

5757
const output1: DynamoDB.BatchGetItemOutput = {

src/dynamo/batchget/batch-get-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
22
import { promiseDelay } from '../../helper'
3-
import { DynamoRx } from '../dynamo-rx'
3+
import { DynamoPromisified } from '../dynamo-promisified'
44

55
/**
66
* Function which executes batchGetItem operations until all given items (as params) are processed (fetched).
@@ -11,7 +11,7 @@ import { DynamoRx } from '../dynamo-rx'
1111
* @param throttleTimeSlot used to calculate the effective wait time
1212
*/
1313
export function batchGetItemsFetchAll(
14-
dynamoRx: DynamoRx,
14+
dynamoRx: DynamoPromisified,
1515
params: DynamoDB.BatchGetItemInput,
1616
backoffTimer: IterableIterator<number>,
1717
throttleTimeSlot: number,

src/dynamo/batchget/batch-get.request.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
33
import { Organization, SimpleWithCompositePartitionKeyModel, SimpleWithPartitionKeyModel } from '../../../test/models'
44
import { Attributes, toDb } from '../../mapper'
5-
import { DynamoRx } from '../dynamo-rx'
5+
import { DynamoPromisified } from '../dynamo-promisified'
66
import { getTableName } from '../get-table-name.function'
77
import { BatchGetRequest } from './batch-get.request'
88

@@ -117,7 +117,7 @@ describe('batch get', () => {
117117
request.forModel(SimpleWithPartitionKeyModel, [jsItem1, jsItem2])
118118

119119
batchGetItemsSpy = jasmine.createSpy().and.returnValues(Promise.resolve(output1), Promise.resolve(output2))
120-
const dynamoRx: DynamoRx = <any>{ batchGetItems: batchGetItemsSpy }
120+
const dynamoRx: DynamoPromisified = <any>{ batchGetItems: batchGetItemsSpy }
121121

122122
Object.assign(request, { dynamoRx })
123123

@@ -182,7 +182,7 @@ describe('batch get', () => {
182182

183183
beforeEach(() => {
184184
batchGetItemsSpy = jasmine.createSpy().and.returnValue(Promise.resolve(sampleResponse))
185-
const dynamoRx: DynamoRx = <any>{ batchGetItems: batchGetItemsSpy }
185+
const dynamoRx: DynamoPromisified = <any>{ batchGetItems: batchGetItemsSpy }
186186
request = new BatchGetRequest()
187187
Object.assign(request, { dynamoRx })
188188
request.forModel(SimpleWithPartitionKeyModel, [{ id: 'idVal' }])

src/dynamo/batchget/batch-get.request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { randomExponentialBackoffTimer } from '../../helper'
44
import { createToKeyFn, fromDb } from '../../mapper'
55
import { Attributes } from '../../mapper/type/attribute.type'
66
import { ModelConstructor } from '../../model/model-constructor'
7-
import { DynamoRx } from '../dynamo-rx'
7+
import { DynamoPromisified } from '../dynamo-promisified'
88
import { getTableName } from '../get-table-name.function'
99
import { BatchGetFullResponse } from './batch-get-full.response'
1010
import { batchGetItemsFetchAll } from './batch-get-utils'
@@ -13,12 +13,12 @@ import { BatchGetResponse } from './batch-get.response'
1313

1414
export class BatchGetRequest {
1515
readonly params: DynamoDB.BatchGetItemInput
16-
private readonly dynamoRx: DynamoRx
16+
private readonly dynamoRx: DynamoPromisified
1717
private readonly tables: Map<string, ModelConstructor<any>> = new Map()
1818
private itemCounter = 0
1919

2020
constructor() {
21-
this.dynamoRx = new DynamoRx()
21+
this.dynamoRx = new DynamoPromisified()
2222
this.params = {
2323
RequestItems: {},
2424
}

src/dynamo/batchwrite/batch-write-utils.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
2-
import { DynamoRx } from '../dynamo-rx'
2+
import { DynamoPromisified } from '../dynamo-promisified'
33
import { batchWriteItemsWriteAll, hasUnprocessedItems } from './batch-write-utils'
44

55
describe('batch-write-utils', () => {
66
describe('batchWriteItemsWriteAll', () => {
77
let batchWriteItemSpy: jasmine.Spy
8-
let dynamoRx: DynamoRx
8+
let dynamoRx: DynamoPromisified
99
let backoffTimerMock: { next: jasmine.Spy }
1010

1111
const output1: DynamoDB.BatchWriteItemOutput = {

src/dynamo/batchwrite/batch-write-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as DynamoDB from 'aws-sdk/clients/dynamodb'
22
import { promiseDelay } from '../../helper'
3-
import { DynamoRx } from '../dynamo-rx'
3+
import { DynamoPromisified } from '../dynamo-promisified'
44

55
/**
66
* Function which executes batchWriteItem operations until all given items (as params) are processed (written).
@@ -11,7 +11,7 @@ import { DynamoRx } from '../dynamo-rx'
1111
* @param throttleTimeSlot used to calculate the effective wait time
1212
*/
1313
export function batchWriteItemsWriteAll(
14-
dynamoRx: DynamoRx,
14+
dynamoRx: DynamoPromisified,
1515
params: DynamoDB.BatchWriteItemInput,
1616
backoffTimer: IterableIterator<number>,
1717
throttleTimeSlot: number,

src/dynamo/batchwrite/batch-write.request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import * as DynamoDB from 'aws-sdk/clients/dynamodb'
22
import { randomExponentialBackoffTimer } from '../../helper'
33
import { createToKeyFn, toDb } from '../../mapper'
44
import { ModelConstructor } from '../../model'
5-
import { DynamoRx } from '../dynamo-rx'
5+
import { DynamoPromisified } from '../dynamo-promisified'
66
import { getTableName } from '../get-table-name.function'
77
import { batchWriteItemsWriteAll } from './batch-write-utils'
88
import { BATCH_WRITE_DEFAULT_TIME_SLOT, BATCH_WRITE_MAX_REQUEST_ITEM_COUNT } from './batch-write.const'
99

1010
export class BatchWriteRequest {
1111
readonly params: DynamoDB.BatchWriteItemInput
12-
private readonly dynamoRx: DynamoRx
12+
private readonly dynamoRx: DynamoPromisified
1313
private itemCount = 0
1414

1515
constructor() {
16-
this.dynamoRx = new DynamoRx()
16+
this.dynamoRx = new DynamoPromisified()
1717
this.params = {
1818
RequestItems: {},
1919
}

src/dynamo/dynamo-rx.spec.ts renamed to src/dynamo/dynamo-promisified.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import { Config, Credentials } from 'aws-sdk/global'
55
import { resetDynamoEasyConfig } from '../../test/helper/resetDynamoEasyConfig.function'
66
import { updateDynamoEasyConfig } from '../config'
7-
import { DynamoRx } from './dynamo-rx'
7+
import { DynamoPromisified } from './dynamo-promisified'
88

99
describe('dynamo rx', () => {
1010
describe('should call the validity ensurer before each call and call the correct dynamoDB method', () => {
11-
let dynamoRx: DynamoRx
11+
let dynamoRx: DynamoPromisified
1212
let sessionValidityEnsurerSpy: jasmine.Spy
1313
let dynamoDBSpy: jasmine.Spy
1414
let pseudoParams: any
@@ -17,7 +17,7 @@ describe('dynamo rx', () => {
1717
pseudoParams = { TableName: 'tableName', KeyConditionExpression: 'blub' }
1818
sessionValidityEnsurerSpy = jasmine.createSpy().and.returnValue(Promise.resolve())
1919
updateDynamoEasyConfig({ sessionValidityEnsurer: sessionValidityEnsurerSpy })
20-
dynamoRx = new DynamoRx()
20+
dynamoRx = new DynamoPromisified()
2121
})
2222

2323
afterEach(() => {
@@ -79,7 +79,7 @@ describe('dynamo rx', () => {
7979
})
8080

8181
describe('makeRequest', async () => {
82-
let dynamoRx: DynamoRx
82+
let dynamoRx: DynamoPromisified
8383
let sessionValidityEnsurerSpy: jasmine.Spy
8484
let dynamoDBSpy: jasmine.Spy
8585
let pseudoParams: any
@@ -88,7 +88,7 @@ describe('dynamo rx', () => {
8888
pseudoParams = { TableName: 'tableName', KeyConditionExpression: 'blub' }
8989
sessionValidityEnsurerSpy = jasmine.createSpy().and.returnValue(Promise.resolve(true))
9090
updateDynamoEasyConfig({ sessionValidityEnsurer: sessionValidityEnsurerSpy })
91-
dynamoRx = new DynamoRx()
91+
dynamoRx = new DynamoPromisified()
9292
})
9393

9494
afterEach(() => {
@@ -107,13 +107,13 @@ describe('dynamo rx', () => {
107107
describe('query', () => {
108108
beforeEach(() => {})
109109
it('should throw when no KeyConditionExpression was given', () => {
110-
const dynamoRx = new DynamoRx()
110+
const dynamoRx = new DynamoPromisified()
111111
expect(() => dynamoRx.query({ TableName: 'tableName' })).toThrow()
112112
})
113113
})
114114

115115
it('should call makeRequest with the given params', async () => {
116-
const dynamoRx = new DynamoRx()
116+
const dynamoRx = new DynamoPromisified()
117117
const makeRequest = jasmine.createSpy().and.returnValue({ promise: () => Promise.resolve(null) })
118118
Object.assign(dynamoRx, { dynamoDB: { makeRequest } })
119119

@@ -123,7 +123,7 @@ describe('dynamo rx', () => {
123123
})
124124

125125
it('should update the credentials', () => {
126-
const dynamoRx = new DynamoRx()
126+
const dynamoRx = new DynamoPromisified()
127127
const credentials = new Credentials({ secretAccessKey: '', sessionToken: '', accessKeyId: '' })
128128
dynamoRx.updateAwsConfigCredentials(new Config({ credentials }))
129129
expect(dynamoRx.dynamoDB.config.credentials).toBe(credentials)

src/dynamo/dynamo-rx.ts renamed to src/dynamo/dynamo-promisified.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Config } from 'aws-sdk/global'
33
import { dynamoEasyConfig } from '../config/dynamo-easy-config'
44

55
/**
6-
* Simply brings calls the sessionValidityEnsurer before each standard dynamoDB operations
6+
* Simply calls the sessionValidityEnsurer before each standard dynamoDB operations and returns a promise for each
7+
* request
78
*/
8-
// todo: rename
9-
export class DynamoRx {
9+
export class DynamoPromisified {
1010
readonly dynamoDB: DynamoDB
1111

1212
constructor() {

src/dynamo/dynamo-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promiseTap } from '../helper'
33
import { createLogger, Logger } from '../logger/logger'
44
import { ModelConstructor } from '../model'
55
import { DynamoApiOperations } from './dynamo-api-operations.type'
6-
import { DynamoRx } from './dynamo-rx'
6+
import { DynamoPromisified } from './dynamo-promisified'
77
import { getTableName } from './get-table-name.function'
88
import {
99
BatchGetSingleTableRequest,
@@ -24,11 +24,11 @@ export class DynamoStore<T> {
2424

2525
readonly tableName: string
2626
private readonly logger: Logger
27-
private readonly dynamoRx: DynamoRx
27+
private readonly dynamoRx: DynamoPromisified
2828

2929
constructor(private modelClazz: ModelConstructor<T>) {
3030
this.logger = createLogger('dynamo.DynamoStore', modelClazz)
31-
this.dynamoRx = new DynamoRx()
31+
this.dynamoRx = new DynamoPromisified()
3232
this.tableName = getTableName(modelClazz)
3333
this.logger.debug('instance created')
3434
}

0 commit comments

Comments
 (0)