Skip to content

Commit 8ba6368

Browse files
style(prettier): reformat whole code base using prettier
1 parent 1792360 commit 8ba6368

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+310
-247
lines changed

src/config/config.type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export interface Config {
1414
/**
1515
* mapper used for {@link DateProperty} decorated properties
1616
*/
17-
dateMapper: MapperForType<any, any>,
17+
dateMapper: MapperForType<any, any>
1818
/**
1919
* function used to create the table names
2020
*/
21-
tableNameResolver: TableNameResolver,
21+
tableNameResolver: TableNameResolver
2222
/**
2323
* function called before calling dynamoDB api
2424
*/
25-
sessionValidityEnsurer: SessionValidityEnsurer,
25+
sessionValidityEnsurer: SessionValidityEnsurer
2626
}

src/config/dynamo-easy-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const dynamoEasyConfig: Config = {
1212
dateMapper: DateToStringMapper,
1313
logReceiver: DEFAULT_LOG_RECEIVER,
1414
tableNameResolver: DEFAULT_TABLE_NAME_RESOLVER,
15-
sessionValidityEnsurer: DEFAULT_SESSION_VALIDITY_ENSURER
15+
sessionValidityEnsurer: DEFAULT_SESSION_VALIDITY_ENSURER,
1616
}

src/config/update-config.function.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ export function updateDynamoEasyConfig(config: Partial<Config>): void {
1010
if ('logReceiver' in config && typeof config.logReceiver !== 'function') {
1111
throw new Error('Config.logReceiver has to be a function')
1212
}
13-
if ('dateMapper' in config && (!config.dateMapper || typeof config.dateMapper.toDb !== 'function' || typeof config.dateMapper.fromDb !== 'function')) {
13+
if (
14+
'dateMapper' in config &&
15+
(!config.dateMapper ||
16+
typeof config.dateMapper.toDb !== 'function' ||
17+
typeof config.dateMapper.fromDb !== 'function')
18+
) {
1419
throw new Error('Config.dateMapper must be an object of type MapperForType')
1520
}
16-
if ('tableNameResolver' in config && typeof config.tableNameResolver !== 'function') {
21+
if ('tableNameResolver' in config && typeof config.tableNameResolver !== 'function') {
1722
throw new Error('Config.tableNameResolver must be function')
1823
}
1924
if ('sessionValidityEnsurer' in config && typeof config.sessionValidityEnsurer !== 'function') {

src/decorator/impl/index/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, ta
3434
initOrUpdateProperty(propertyMetadata, target, propertyKey)
3535
}
3636

37-
function initOrUpdateGSI(indexes: Record<string, DynamoDB.KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
37+
function initOrUpdateGSI(
38+
indexes: Record<string, DynamoDB.KeyType>,
39+
indexData: IndexData,
40+
): Partial<PropertyMetadata<any>> {
3841
if (indexes[indexData.name]) {
3942
// TODO LOW:INVESTIGATE when we throw an error we have a problem where multiple different classes extend one base class, this will be executed by multiple times
4043
// throw new Error(

src/decorator/impl/model/model.decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function getGlobalSecondaryIndexes(properties: Array<PropertyMetadata<any>>): Ma
8282
throw new Error(
8383
`there is already a partition key defined for global secondary index ${indexName} (property name: ${
8484
property.nameDb
85-
})`,
85+
})`,
8686
)
8787
}
8888

@@ -93,7 +93,7 @@ function getGlobalSecondaryIndexes(properties: Array<PropertyMetadata<any>>): Ma
9393
throw new Error(
9494
`there is already a sort key defined for global secondary index ${indexName} (property name: ${
9595
property.nameDb
96-
})`,
96+
})`,
9797
)
9898
}
9999

@@ -133,7 +133,7 @@ function getLocalSecondaryIndexes(
133133
throw new Error(
134134
`only one sort key can be defined for the same local secondary index, ${
135135
property.nameDb
136-
} is already defined as sort key for index ${indexName}`,
136+
} is already defined as sort key for index ${indexName}`,
137137
)
138138
}
139139

src/decorator/metadata/metadata.spec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tslint:disable:no-non-null-assertion
22
import {
3-
ModelWithABunchOfIndexes, ModelWithAutogeneratedId,
3+
ModelWithABunchOfIndexes,
4+
ModelWithAutogeneratedId,
45
ModelWithGSI,
56
ModelWithLSI,
67
SimpleWithCompositePartitionKeyModel,
@@ -41,15 +42,13 @@ describe('metadata', () => {
4142
expect(uuid[0].key).toBeDefined()
4243
expect(uuid[0].key!.uuid).toBeTruthy()
4344
expect(uuid[0].name).toBe('id')
44-
4545
})
4646

4747
it('getPartitionKey', () => {
4848
expect(metaDataPartitionKey.getPartitionKey()).toEqual('id')
4949
expect(metaDataGsi.getPartitionKey(INDEX_ACTIVE)).toEqual('active')
5050
expect(metaDataIndexes.getPartitionKey(INDEX_COUNT)).toEqual('myId')
5151
expect(metaDataIndexes.getPartitionKey(INDEX_ACTIVE_CREATED_AT)).toEqual('active')
52-
5352
})
5453

5554
it('getSortKey', () => {
@@ -61,12 +60,8 @@ describe('metadata', () => {
6160
})
6261

6362
it('getIndexes', () => {
64-
expect(metaDataLsi.getIndexes()).toEqual([
65-
{ partitionKey: 'id', sortKey: 'active' },
66-
])
67-
expect(metaDataGsi.getIndexes()).toEqual([
68-
{ partitionKey: 'active' },
69-
])
63+
expect(metaDataLsi.getIndexes()).toEqual([{ partitionKey: 'id', sortKey: 'active' }])
64+
expect(metaDataGsi.getIndexes()).toEqual([{ partitionKey: 'active' }])
7065
expect(metaDataIndexes.getIndexes()).toEqual([
7166
{ partitionKey: 'active', sortKey: 'createdAt' },
7267
{ partitionKey: 'myId', sortKey: 'count' },
@@ -81,5 +76,4 @@ describe('metadata', () => {
8176
sortKey: 'createdAt',
8277
})
8378
})
84-
8579
})

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,39 @@ export function batchGetItemsFetchAll(
1717
backoffTimer: IterableIterator<number>,
1818
throttleTimeSlot: number,
1919
): Observable<DynamoDB.BatchGetItemOutput> {
20-
return dynamoRx.batchGetItems(params)
21-
.pipe(
22-
mergeMap(response => {
23-
if (hasUnprocessedKeys(response)) {
24-
// in case of unprocessedItems do a follow-up requests
25-
return of(response.UnprocessedKeys)
26-
.pipe(
27-
// delay before doing the follow-up request
28-
delay(backoffTimer.next().value * throttleTimeSlot),
20+
return dynamoRx.batchGetItems(params).pipe(
21+
mergeMap(response => {
22+
if (hasUnprocessedKeys(response)) {
23+
// in case of unprocessedItems do a follow-up requests
24+
return of(response.UnprocessedKeys).pipe(
25+
// delay before doing the follow-up request
26+
delay(backoffTimer.next().value * throttleTimeSlot),
2927

30-
mergeMap((UnprocessedKeys: DynamoDB.BatchGetRequestMap) => {
31-
const nextParams = { ...params, RequestItems: UnprocessedKeys }
32-
// call recursively batchGetItemsFetchAll with the returned UnprocessedItems params
33-
return batchGetItemsFetchAll(dynamoRx, nextParams, backoffTimer, throttleTimeSlot)
34-
}),
35-
map(combineBatchGetResponses(response)),
36-
)
37-
}
38-
// no follow-up request necessary, return result
39-
return of(response)
40-
}),
41-
)
28+
mergeMap((UnprocessedKeys: DynamoDB.BatchGetRequestMap) => {
29+
const nextParams = { ...params, RequestItems: UnprocessedKeys }
30+
// call recursively batchGetItemsFetchAll with the returned UnprocessedItems params
31+
return batchGetItemsFetchAll(dynamoRx, nextParams, backoffTimer, throttleTimeSlot)
32+
}),
33+
map(combineBatchGetResponses(response)),
34+
)
35+
}
36+
// no follow-up request necessary, return result
37+
return of(response)
38+
}),
39+
)
4240
}
4341

44-
export type BatchGetItemOutputWithUnprocessedKeys =
45-
DynamoDB.BatchGetItemOutput
46-
& { UnprocessedKeys: DynamoDB.BatchGetRequestMap }
42+
export type BatchGetItemOutputWithUnprocessedKeys = DynamoDB.BatchGetItemOutput & {
43+
UnprocessedKeys: DynamoDB.BatchGetRequestMap
44+
}
4745

48-
export function hasUnprocessedKeys(response: DynamoDB.BatchGetItemOutput): response is BatchGetItemOutputWithUnprocessedKeys {
46+
export function hasUnprocessedKeys(
47+
response: DynamoDB.BatchGetItemOutput,
48+
): response is BatchGetItemOutputWithUnprocessedKeys {
4949
if (!response.UnprocessedKeys) {
5050
return false
5151
}
52-
return Object.values(response.UnprocessedKeys)
53-
.some(t => !!t && t.Keys && t.Keys.length > 0)
52+
return Object.values(response.UnprocessedKeys).some(t => !!t && t.Keys && t.Keys.length > 0)
5453
}
5554

5655
/**
@@ -65,14 +64,16 @@ export function combineBatchGetResponses(response1: DynamoDB.BatchGetItemOutput)
6564
.filter(tn => !tableNames.includes(tn))
6665
.forEach(tn => tableNames.push(tn))
6766

68-
const Responses = tableNames
69-
.reduce((u, tableName) => ({
67+
const Responses = tableNames.reduce(
68+
(u, tableName) => ({
7069
...u,
7170
[tableName]: [
72-
...(response1.Responses && response1.Responses[tableName] || []),
73-
...(response2.Responses && response2.Responses[tableName] || []),
71+
...((response1.Responses && response1.Responses[tableName]) || []),
72+
...((response2.Responses && response2.Responses[tableName]) || []),
7473
],
75-
}), {})
74+
}),
75+
{},
76+
)
7677
return {
7778
...response2,
7879
Responses,

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { batchGetItemsFetchAll } from './batch-get-utils'
1313
import { BATCH_GET_DEFAULT_TIME_SLOT, BATCH_GET_MAX_REQUEST_ITEM_COUNT } from './batch-get.const'
1414
import { BatchGetResponse } from './batch-get.response'
1515

16-
17-
1816
export class BatchGetRequest {
1917
readonly params: DynamoDB.BatchGetItemInput
2018
private readonly dynamoRx: DynamoRx
@@ -35,18 +33,23 @@ export class BatchGetRequest {
3533
* @returns {BatchGetSingleTableRequest}
3634
*/
3735
forModel<T>(modelClazz: ModelConstructor<T>, keys: Array<Partial<T>>, consistentRead = false): BatchGetRequest {
38-
3936
// check if modelClazz is really an @Model() decorated class
4037
const metadata = metadataForClass(modelClazz)
41-
if (!metadata.modelOptions) { throw new Error('given ModelConstructor has no @Model decorator')}
38+
if (!metadata.modelOptions) {
39+
throw new Error('given ModelConstructor has no @Model decorator')
40+
}
4241

4342
// check if table was already used in this request
4443
const tableName = getTableName(metadata)
45-
if (this.tables.has(tableName)) { throw new Error('table name already exists, please provide all the keys for the same table at once') }
44+
if (this.tables.has(tableName)) {
45+
throw new Error('table name already exists, please provide all the keys for the same table at once')
46+
}
4647
this.tables.set(tableName, modelClazz)
4748

4849
// check if keys to add do not exceed max count
49-
if (this.itemCounter + keys.length > BATCH_GET_MAX_REQUEST_ITEM_COUNT) { throw new Error(`you can request at max ${BATCH_GET_MAX_REQUEST_ITEM_COUNT} items per request`)}
50+
if (this.itemCounter + keys.length > BATCH_GET_MAX_REQUEST_ITEM_COUNT) {
51+
throw new Error(`you can request at max ${BATCH_GET_MAX_REQUEST_ITEM_COUNT} items per request`)
52+
}
5053

5154
this.params.RequestItems[tableName] = {
5255
Keys: keys.map(createToKeyFn(modelClazz)),
@@ -58,30 +61,34 @@ export class BatchGetRequest {
5861
return this
5962
}
6063

61-
execNoMap(backoffTimer = randomExponentialBackoffTimer, throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT): Observable<DynamoDB.BatchGetItemOutput> {
64+
execNoMap(
65+
backoffTimer = randomExponentialBackoffTimer,
66+
throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT,
67+
): Observable<DynamoDB.BatchGetItemOutput> {
6268
return this.fetch(backoffTimer, throttleTimeSlot)
6369
}
6470

65-
execFullResponse(backoffTimer = randomExponentialBackoffTimer, throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT): Observable<BatchGetFullResponse> {
66-
return this.fetch(backoffTimer, throttleTimeSlot)
67-
.pipe(
68-
map(this.mapResponse),
69-
)
71+
execFullResponse(
72+
backoffTimer = randomExponentialBackoffTimer,
73+
throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT,
74+
): Observable<BatchGetFullResponse> {
75+
return this.fetch(backoffTimer, throttleTimeSlot).pipe(map(this.mapResponse))
7076
}
7177

72-
exec(backoffTimer = randomExponentialBackoffTimer, throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT): Observable<BatchGetResponse> {
73-
return this.fetch(backoffTimer, throttleTimeSlot)
74-
.pipe(
75-
map(this.mapResponse),
76-
map(r => r.Responses),
77-
)
78+
exec(
79+
backoffTimer = randomExponentialBackoffTimer,
80+
throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT,
81+
): Observable<BatchGetResponse> {
82+
return this.fetch(backoffTimer, throttleTimeSlot).pipe(
83+
map(this.mapResponse),
84+
map(r => r.Responses),
85+
)
7886
}
7987

8088
private fetch(backoffTimer = randomExponentialBackoffTimer, throttleTimeSlot = BATCH_GET_DEFAULT_TIME_SLOT) {
8189
return batchGetItemsFetchAll(this.dynamoRx, { ...this.params }, backoffTimer(), throttleTimeSlot)
8290
}
8391

84-
8592
private mapResponse = (response: DynamoDB.BatchGetItemOutput): BatchGetFullResponse => {
8693
let Responses: BatchGetResponse = {}
8794

@@ -98,5 +105,4 @@ export class BatchGetRequest {
98105
Responses,
99106
}
100107
}
101-
102108
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// tslint:disable-next-line:interface-over-type-literal
2-
export type BatchGetResponse = Record<string /* tableName */ , any[]>
2+
export type BatchGetResponse = Record<string /* tableName */, any[]>

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

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Observable, of } from 'rxjs'
33
import { delay, mergeMap } from 'rxjs/operators'
44
import { DynamoRx } from '../dynamo-rx'
55

6-
76
/**
87
* Function which executes batchWriteItem operations until all given items (as params) are processed (written).
98
* Between each follow-up request (in case of unprocessed items) a delay is interposed calculated by the given backoffTime and throttleTimeSlot.
@@ -18,38 +17,37 @@ export function batchWriteItemsWriteAll(
1817
backoffTimer: IterableIterator<number>,
1918
throttleTimeSlot: number,
2019
): Observable<DynamoDB.BatchGetItemOutput> {
21-
return dynamoRx.batchWriteItem(params)
22-
.pipe(
23-
mergeMap(response => {
24-
if (hasUnprocessedItems(response)) {
25-
// in case of unprocessedItems do a follow-up requests
26-
return of(response.UnprocessedItems)
27-
.pipe(
28-
// delay before doing the follow-up request
29-
delay(backoffTimer.next().value * throttleTimeSlot),
20+
return dynamoRx.batchWriteItem(params).pipe(
21+
mergeMap(response => {
22+
if (hasUnprocessedItems(response)) {
23+
// in case of unprocessedItems do a follow-up requests
24+
return of(response.UnprocessedItems).pipe(
25+
// delay before doing the follow-up request
26+
delay(backoffTimer.next().value * throttleTimeSlot),
3027

31-
mergeMap((unprocessedKeys: DynamoDB.BatchWriteItemRequestMap) => {
32-
const nextParams: DynamoDB.BatchWriteItemInput = { ...params, RequestItems: unprocessedKeys }
33-
// call recursively batchWriteItemsWriteAll with the returned UnprocessedItems params
34-
return batchWriteItemsWriteAll(dynamoRx, nextParams, backoffTimer, throttleTimeSlot)
35-
}),
36-
// no combining of responses necessary, only the last response is returned
37-
)
38-
}
39-
// no follow-up request necessary, return result
40-
return of(response)
41-
}),
42-
)
28+
mergeMap((unprocessedKeys: DynamoDB.BatchWriteItemRequestMap) => {
29+
const nextParams: DynamoDB.BatchWriteItemInput = { ...params, RequestItems: unprocessedKeys }
30+
// call recursively batchWriteItemsWriteAll with the returned UnprocessedItems params
31+
return batchWriteItemsWriteAll(dynamoRx, nextParams, backoffTimer, throttleTimeSlot)
32+
}),
33+
// no combining of responses necessary, only the last response is returned
34+
)
35+
}
36+
// no follow-up request necessary, return result
37+
return of(response)
38+
}),
39+
)
4340
}
4441

45-
export type BatchWriteItemOutputWithUnprocessedItems =
46-
DynamoDB.BatchWriteItemOutput
47-
& { UnprocessedItems: DynamoDB.BatchWriteItemRequestMap }
42+
export type BatchWriteItemOutputWithUnprocessedItems = DynamoDB.BatchWriteItemOutput & {
43+
UnprocessedItems: DynamoDB.BatchWriteItemRequestMap
44+
}
4845

49-
export function hasUnprocessedItems(response: DynamoDB.BatchWriteItemOutput): response is BatchWriteItemOutputWithUnprocessedItems {
46+
export function hasUnprocessedItems(
47+
response: DynamoDB.BatchWriteItemOutput,
48+
): response is BatchWriteItemOutputWithUnprocessedItems {
5049
if (!response.UnprocessedItems) {
5150
return false
5251
}
53-
return Object.values(response.UnprocessedItems)
54-
.some(t => !!t && t.length > 0)
52+
return Object.values(response.UnprocessedItems).some(t => !!t && t.length > 0)
5553
}

0 commit comments

Comments
 (0)