Skip to content

Commit 2faca68

Browse files
authored
Merge pull request #42 from blazejkustra/bump-deps
Update package dependencies and improve type safety in the codebase.
2 parents 2b6f43e + 6e13460 commit 2faca68

10 files changed

Lines changed: 5844 additions & 3999 deletions

File tree

lib/entity/helpers/transformValues.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import Dynamode from '@lib/dynamode/index';
22
import Entity from '@lib/entity';
3-
import { InvalidParameter } from '@lib/utils';
3+
import { InvalidParameter, LiteralKey } from '@lib/utils';
44

5-
export function prefixSuffixValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
5+
export function prefixSuffixValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
66
if (typeof value !== 'string') {
77
return value;
88
}
99

1010
const attributes = Dynamode.storage.getEntityAttributes(entity.name);
1111
const separator = Dynamode.separator.get();
12-
const prefix = attributes[key]?.prefix || '';
13-
const suffix = attributes[key]?.suffix || '';
12+
const prefix = attributes[key as string]?.prefix || '';
13+
const suffix = attributes[key as string]?.suffix || '';
1414

1515
return [prefix, value, suffix].filter((p) => p).join(separator);
1616
}
1717

18-
export function truncateValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
18+
export function truncateValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
1919
if (typeof value !== 'string') {
2020
return value;
2121
}
2222

2323
const attributes = Dynamode.storage.getEntityAttributes(entity.name);
2424
const separator = Dynamode.separator.get();
25-
const prefix = attributes[key].prefix || '';
26-
const suffix = attributes[key].suffix || '';
25+
const prefix = attributes[key as string].prefix || '';
26+
const suffix = attributes[key as string].suffix || '';
2727

2828
const valueSections = value.split(separator);
2929

@@ -38,9 +38,9 @@ export function truncateValue<E extends typeof Entity>(entity: E, key: string, v
3838
return valueSections.join(separator);
3939
}
4040

41-
export function transformDateValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
41+
export function transformDateValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
4242
const attributes = Dynamode.storage.getEntityAttributes(entity.name);
43-
const attribute = attributes[key];
43+
const attribute = attributes[key as string];
4444

4545
if (value instanceof Date) {
4646
if (attribute.role !== 'date') {
@@ -63,7 +63,7 @@ export function transformDateValue<E extends typeof Entity>(entity: E, key: stri
6363
return value;
6464
}
6565

66-
export function transformValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
66+
export function transformValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
6767
const processedValue = transformDateValue(entity, key, value);
6868
return prefixSuffixValue(entity, key, processedValue);
6969
}

lib/entity/types.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@ export type BuildGetProjectionExpression = {
9595
* @template T - The object type
9696
* @template Value - The value type to filter by
9797
*/
98-
export type PickByType<T, Value> = Omit<
99-
{
100-
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
101-
},
102-
'dynamodeEntity'
103-
> extends infer U
104-
? U extends Record<string, never>
105-
? Record<string, never>
106-
: U | Record<string, never>
107-
: never;
98+
export type PickByType<T, Value> =
99+
Omit<
100+
{
101+
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
102+
},
103+
'dynamodeEntity'
104+
> extends infer U
105+
? U extends Record<string, never>
106+
? Record<string, never>
107+
: U | Record<string, never>
108+
: never;
108109

109110
/**
110111
* Update operations for entity update operations.

lib/module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import transactionWrite from '@lib/transactionWrite';
1515
// so we need them to exist to compile without having DOM.
1616
declare global {
1717
/* eslint-disable @typescript-eslint/no-empty-interface */
18+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
1819
interface ReadableStream {}
20+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
1921
interface File {}
2022
}
2123

lib/query/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
*/
5858
export default class Query<M extends Metadata<E>, E extends typeof Entity> extends RetrieverBase<M, E> {
5959
/** The DynamoDB QueryInput object */
60-
protected declare input: QueryInput;
60+
declare protected input: QueryInput;
6161
/** Key condition operators for building key condition expressions */
6262
protected keyOperators: Operators = [];
6363
/** Metadata for the partition key attribute */

lib/scan/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { ExpressionBuilder, isNotEmptyString } from '@lib/utils';
4242
*/
4343
export default class Scan<M extends Metadata<E>, E extends typeof Entity> extends RetrieverBase<M, E> {
4444
/** The DynamoDB ScanInput object */
45-
protected declare input: ScanInput;
45+
declare protected input: ScanInput;
4646

4747
/**
4848
* Creates a new Scan instance.

lib/utils/ExpressionBuilder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AttributeValues,
44
InvalidParameter,
55
isNotEmpty,
6+
LiteralKey,
67
Operators,
78
RESERVED_WORDS,
89
splitListPathReference,
@@ -49,8 +50,8 @@ export class ExpressionBuilder {
4950
.join('');
5051
}
5152

52-
public substituteName(key: string): string {
53-
return key
53+
public substituteName(key: LiteralKey): string {
54+
return (key as string)
5455
.split('.')
5556
.map((key) => {
5657
const [keyPart, listReferencePart] = splitListPathReference(key);
@@ -66,8 +67,8 @@ export class ExpressionBuilder {
6667
.join('.');
6768
}
6869

69-
public substituteValue(key: string, value: unknown): string {
70-
const valueName = key.replace(/\[/g, '_index').replace(/\]/g, '').split('.').join('_');
70+
public substituteValue(key: LiteralKey, value: unknown): string {
71+
const valueName = (key as string).replace(/\[/g, '_index').replace(/\]/g, '').split('.').join('_');
7172

7273
for (let i = 0; i < 1000; i++) {
7374
const suffix = i ? `__${i}` : '';
@@ -78,6 +79,6 @@ export class ExpressionBuilder {
7879
}
7980
}
8081

81-
throw new InvalidParameter(`Couldn't substitute a value for key: ${key}. Value key out of range`);
82+
throw new InvalidParameter(`Couldn't substitute a value for key: ${key as string}. Value key out of range`);
8283
}
8384
}

0 commit comments

Comments
 (0)