Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/entity/helpers/transformValues.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Dynamode from '@lib/dynamode/index';
import Entity from '@lib/entity';
import { InvalidParameter } from '@lib/utils';
import { InvalidParameter, LiteralKey } from '@lib/utils';

export function prefixSuffixValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
export function prefixSuffixValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
if (typeof value !== 'string') {
return value;
}

const attributes = Dynamode.storage.getEntityAttributes(entity.name);
const separator = Dynamode.separator.get();
const prefix = attributes[key]?.prefix || '';
const suffix = attributes[key]?.suffix || '';
const prefix = attributes[key as string]?.prefix || '';
const suffix = attributes[key as string]?.suffix || '';

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

export function truncateValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
export function truncateValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
if (typeof value !== 'string') {
return value;
}

const attributes = Dynamode.storage.getEntityAttributes(entity.name);
const separator = Dynamode.separator.get();
const prefix = attributes[key].prefix || '';
const suffix = attributes[key].suffix || '';
const prefix = attributes[key as string].prefix || '';
const suffix = attributes[key as string].suffix || '';

const valueSections = value.split(separator);

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

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

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

export function transformValue<E extends typeof Entity>(entity: E, key: string, value: unknown): unknown {
export function transformValue<E extends typeof Entity>(entity: E, key: LiteralKey, value: unknown): unknown {
const processedValue = transformDateValue(entity, key, value);
return prefixSuffixValue(entity, key, processedValue);
}
21 changes: 11 additions & 10 deletions lib/entity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ export type BuildGetProjectionExpression = {
* @template T - The object type
* @template Value - The value type to filter by
*/
export type PickByType<T, Value> = Omit<
{
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
},
'dynamodeEntity'
> extends infer U
? U extends Record<string, never>
? Record<string, never>
: U | Record<string, never>
: never;
export type PickByType<T, Value> =
Omit<
{
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
},
'dynamodeEntity'
> extends infer U
? U extends Record<string, never>
? Record<string, never>
: U | Record<string, never>
: never;

/**
* Update operations for entity update operations.
Expand Down
2 changes: 2 additions & 0 deletions lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import transactionWrite from '@lib/transactionWrite';
// so we need them to exist to compile without having DOM.
declare global {
/* eslint-disable @typescript-eslint/no-empty-interface */
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface ReadableStream {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface File {}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
*/
export default class Query<M extends Metadata<E>, E extends typeof Entity> extends RetrieverBase<M, E> {
/** The DynamoDB QueryInput object */
protected declare input: QueryInput;
declare protected input: QueryInput;
/** Key condition operators for building key condition expressions */
protected keyOperators: Operators = [];
/** Metadata for the partition key attribute */
Expand Down
2 changes: 1 addition & 1 deletion lib/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { ExpressionBuilder, isNotEmptyString } from '@lib/utils';
*/
export default class Scan<M extends Metadata<E>, E extends typeof Entity> extends RetrieverBase<M, E> {
/** The DynamoDB ScanInput object */
protected declare input: ScanInput;
declare protected input: ScanInput;

/**
* Creates a new Scan instance.
Expand Down
11 changes: 6 additions & 5 deletions lib/utils/ExpressionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AttributeValues,
InvalidParameter,
isNotEmpty,
LiteralKey,
Operators,
RESERVED_WORDS,
splitListPathReference,
Expand Down Expand Up @@ -49,8 +50,8 @@ export class ExpressionBuilder {
.join('');
}

public substituteName(key: string): string {
return key
public substituteName(key: LiteralKey): string {
return (key as string)
.split('.')
.map((key) => {
const [keyPart, listReferencePart] = splitListPathReference(key);
Expand All @@ -66,8 +67,8 @@ export class ExpressionBuilder {
.join('.');
}

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

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

throw new InvalidParameter(`Couldn't substitute a value for key: ${key}. Value key out of range`);
throw new InvalidParameter(`Couldn't substitute a value for key: ${key as string}. Value key out of range`);
}
}
Loading
Loading