@@ -2,16 +2,13 @@ import { decode, encode } from '../encoding';
2
2
import { ValueError } from '../errors' ;
3
3
import { Payload , SearchAttributes } from '../interfaces' ;
4
4
import {
5
- isTypedSearchAttribute ,
5
+ isTypedSearchAttributeValue ,
6
6
isTypedSearchAttributePair ,
7
- toMetadataType ,
8
- toSearchAttributeType ,
9
7
TypedSearchAttributePair ,
10
8
TypedSearchAttributes ,
11
- TypedSearchAttribute ,
9
+ TypedSearchAttributeValue ,
12
10
SearchAttributeType ,
13
- isTypedSearchAttributeUpdate ,
14
- searchAttributePair ,
11
+ isTypedSearchAttributeUpdateValue ,
15
12
} from '../typed-search-attributes' ;
16
13
import {
17
14
PayloadConverter ,
@@ -93,7 +90,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
93
90
94
91
public toPayload < T > ( typedSearchAttribute : T ) : Payload {
95
92
// We check for deletion as well as regular typed search attributes.
96
- if ( ! isTypedSearchAttributeUpdate ( typedSearchAttribute ) ) {
93
+ if ( ! isTypedSearchAttributeUpdateValue ( typedSearchAttribute ) ) {
97
94
throw new ValueError ( `Invalid typed search attribute: ${ typedSearchAttribute } ` ) ;
98
95
}
99
96
@@ -124,7 +121,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
124
121
throw new ValueError ( 'Missing payload metadata' ) ;
125
122
}
126
123
// Add encoded type of search attribute to metatdata
127
- payload . metadata [ 'type' ] = encode ( toMetadataType ( type ) ) ;
124
+ payload . metadata [ 'type' ] = encode ( TypedSearchAttributes . toMetadataType ( type ) ) ;
128
125
return payload ;
129
126
}
130
127
@@ -140,7 +137,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
140
137
if ( payload . metadata . type == null ) {
141
138
return undefined as T ;
142
139
}
143
- const type = toSearchAttributeType ( decode ( payload . metadata . type ) ) ;
140
+ const type = TypedSearchAttributes . toSearchAttributeType ( decode ( payload . metadata . type ) ) ;
144
141
// Unrecognized metadata type (sanity check).
145
142
if ( type === undefined ) {
146
143
return undefined as T ;
@@ -161,7 +158,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
161
158
value = new Date ( value as string ) ;
162
159
}
163
160
// Check if the value is a valid typed search attribute. If not, skip.
164
- if ( ! isTypedSearchAttribute ( [ type , value ] ) ) {
161
+ if ( ! isTypedSearchAttributeValue ( [ type , value ] ) ) {
165
162
return undefined as T ;
166
163
}
167
164
return [ type , value ] as T ;
@@ -178,13 +175,12 @@ export function encodeUnifiedSearchAttributes(
178
175
return {
179
176
...( searchAttributes ? mapToPayloads ( searchAttributePayloadConverter , searchAttributes ) : { } ) ,
180
177
...( typedSearchAttributes
181
- ? typedMapToPayloads < string , TypedSearchAttribute > (
178
+ ? typedMapToPayloads < string , TypedSearchAttributeValue > (
182
179
typedSearchAttributePayloadConverter ,
183
180
Object . fromEntries (
184
- ( Array . isArray ( typedSearchAttributes )
185
- ? typedSearchAttributes
186
- : typedSearchAttributes . getSearchAttributes ( )
187
- ) . map ( ( [ k , v ] ) => [ k . name , v ] )
181
+ ( Array . isArray ( typedSearchAttributes ) ? typedSearchAttributes : typedSearchAttributes . getAttributes ( ) ) . map (
182
+ ( [ k , v ] ) => [ k . name , v ]
183
+ )
188
184
)
189
185
)
190
186
: { } ) ,
@@ -205,7 +201,7 @@ export function decodeTypedSearchAttributes(
205
201
) : TypedSearchAttributes {
206
202
return new TypedSearchAttributes (
207
203
Object . entries (
208
- typedMapFromPayloads < string , TypedSearchAttribute | undefined > (
204
+ typedMapFromPayloads < string , TypedSearchAttributeValue | undefined > (
209
205
typedSearchAttributePayloadConverter ,
210
206
indexedFields
211
207
) ?? { }
@@ -214,7 +210,7 @@ export function decodeTypedSearchAttributes(
214
210
if ( ! v ) {
215
211
return acc ;
216
212
}
217
- const pair = searchAttributePair ( k , v [ 0 ] , v [ 1 ] ) ;
213
+ const pair = TypedSearchAttributes . createAttribute ( k , v [ 0 ] , v [ 1 ] ) ;
218
214
// Ensure is valid pair.
219
215
if ( isTypedSearchAttributePair ( pair ) ) {
220
216
acc . push ( pair ) ;
0 commit comments