Skip to content

Commit 1a601a1

Browse files
committed
cleanup and names
1 parent 3261083 commit 1a601a1

File tree

5 files changed

+190
-191
lines changed

5 files changed

+190
-191
lines changed

packages/common/src/converter/payload-search-attributes.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import { decode, encode } from '../encoding';
22
import { ValueError } from '../errors';
33
import { Payload, SearchAttributes } from '../interfaces';
44
import {
5-
isTypedSearchAttribute,
5+
isTypedSearchAttributeValue,
66
isTypedSearchAttributePair,
7-
toMetadataType,
8-
toSearchAttributeType,
97
TypedSearchAttributePair,
108
TypedSearchAttributes,
11-
TypedSearchAttribute,
9+
TypedSearchAttributeValue,
1210
SearchAttributeType,
13-
isTypedSearchAttributeUpdate,
14-
searchAttributePair,
11+
isTypedSearchAttributeUpdateValue,
1512
} from '../typed-search-attributes';
1613
import {
1714
PayloadConverter,
@@ -93,7 +90,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
9390

9491
public toPayload<T>(typedSearchAttribute: T): Payload {
9592
// We check for deletion as well as regular typed search attributes.
96-
if (!isTypedSearchAttributeUpdate(typedSearchAttribute)) {
93+
if (!isTypedSearchAttributeUpdateValue(typedSearchAttribute)) {
9794
throw new ValueError(`Invalid typed search attribute: ${typedSearchAttribute}`);
9895
}
9996

@@ -124,7 +121,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
124121
throw new ValueError('Missing payload metadata');
125122
}
126123
// Add encoded type of search attribute to metatdata
127-
payload.metadata['type'] = encode(toMetadataType(type));
124+
payload.metadata['type'] = encode(TypedSearchAttributes.toMetadataType(type));
128125
return payload;
129126
}
130127

@@ -140,7 +137,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
140137
if (payload.metadata.type == null) {
141138
return undefined as T;
142139
}
143-
const type = toSearchAttributeType(decode(payload.metadata.type));
140+
const type = TypedSearchAttributes.toSearchAttributeType(decode(payload.metadata.type));
144141
// Unrecognized metadata type (sanity check).
145142
if (type === undefined) {
146143
return undefined as T;
@@ -161,7 +158,7 @@ export class TypedSearchAttributePayloadConverter implements PayloadConverter {
161158
value = new Date(value as string);
162159
}
163160
// Check if the value is a valid typed search attribute. If not, skip.
164-
if (!isTypedSearchAttribute([type, value])) {
161+
if (!isTypedSearchAttributeValue([type, value])) {
165162
return undefined as T;
166163
}
167164
return [type, value] as T;
@@ -178,13 +175,12 @@ export function encodeUnifiedSearchAttributes(
178175
return {
179176
...(searchAttributes ? mapToPayloads(searchAttributePayloadConverter, searchAttributes) : {}),
180177
...(typedSearchAttributes
181-
? typedMapToPayloads<string, TypedSearchAttribute>(
178+
? typedMapToPayloads<string, TypedSearchAttributeValue>(
182179
typedSearchAttributePayloadConverter,
183180
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+
)
188184
)
189185
)
190186
: {}),
@@ -205,7 +201,7 @@ export function decodeTypedSearchAttributes(
205201
): TypedSearchAttributes {
206202
return new TypedSearchAttributes(
207203
Object.entries(
208-
typedMapFromPayloads<string, TypedSearchAttribute | undefined>(
204+
typedMapFromPayloads<string, TypedSearchAttributeValue | undefined>(
209205
typedSearchAttributePayloadConverter,
210206
indexedFields
211207
) ?? {}
@@ -214,7 +210,7 @@ export function decodeTypedSearchAttributes(
214210
if (!v) {
215211
return acc;
216212
}
217-
const pair = searchAttributePair(k, v[0], v[1]);
213+
const pair = TypedSearchAttributes.createAttribute(k, v[0], v[1]);
218214
// Ensure is valid pair.
219215
if (isTypedSearchAttributePair(pair)) {
220216
acc.push(pair);

0 commit comments

Comments
 (0)