Add Document Key Retriever to Buffered Sender#13478
Conversation
xirzec
left a comment
There was a problem hiding this comment.
Looking pretty good, just a few thoughts about how we can tighten typing and make the prune function not mutate its parameters.
|
|
||
| while (counter < batch.length) { | ||
| const { __actionType, ...document } = batch[counter]; | ||
| // @ts-ignore |
There was a problem hiding this comment.
If I do not add this here, I get the following error:
src/searchIndexingBufferedSender.ts:405:45 - error TS2345: Argument of type 'IndexDocumentsAction<T>' is not assignable to parameter of type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'IndexDocumentsAction<T>'.
405 const key = this.documentKeyRetriever(document);
There was a problem hiding this comment.
This is interesting. Since merge and delete operations don't need to specify the entire document, IndexDocumentsAction maps to a Partial plus the action property.
Since the action can be a partial document, that means the mapping function might not be getting the whole document. This should still be fine as the partial document must contain the key, but TS doesn't know that, so what it wants is for documentKeyRetriever to look like this:
documentKeyRetriever: (document: T | IndexDocumentsAction<T>) => stringI notice that buffered sender doesn't actually ever take in partial documents, so I think in this case it's safe to avoid it with
const key = this.documentKeyRetriever(document as unknown as T);Which is still much better than ts-ignore as ts-ignore disables all checking instead of just one type check.
sdk/search/search-documents/src/searchIndexingBufferedSender.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Jeff Fisher <xirzec@xirzec.com>
xirzec
left a comment
There was a problem hiding this comment.
I think I'm happy with this as long as we can take out the ts-ignore (see suggestion in comment)
|
|
||
| while (counter < batch.length) { | ||
| const { __actionType, ...document } = batch[counter]; | ||
| // @ts-ignore |
There was a problem hiding this comment.
This is interesting. Since merge and delete operations don't need to specify the entire document, IndexDocumentsAction maps to a Partial plus the action property.
Since the action can be a partial document, that means the mapping function might not be getting the whole document. This should still be fine as the partial document must contain the key, but TS doesn't know that, so what it wants is for documentKeyRetriever to look like this:
documentKeyRetriever: (document: T | IndexDocumentsAction<T>) => stringI notice that buffered sender doesn't actually ever take in partial documents, so I think in this case it's safe to avoid it with
const key = this.documentKeyRetriever(document as unknown as T);Which is still much better than ts-ignore as ts-ignore disables all checking instead of just one type check.
This PR Contains the following changes:
@hiddento@internalvalues.codetostatusCode.@xirzec Please review and approve.