11import Dynamode from '@lib/dynamode/index' ;
22import 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}
0 commit comments