Skip to content

Commit

Permalink
Require user to return token when Query provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson committed Feb 23, 2024
1 parent 5287940 commit 935d999
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,25 @@ export class Client {
);
}

let streamToken: StreamToken | null = null;
if (query instanceof Query) {
const toStreamQuery = fql`${query}.toStream()`;

streamToken = (await this.query<StreamToken>(toStreamQuery).then(
(res) => res.data
)) as StreamToken;
} else {
streamToken = query;
}

const streamClient = this.#httpClient;

if (implementsStreamClient(streamClient)) {
let streamToken: StreamToken | null = null;
if (query instanceof Query) {
streamToken = await this.query<StreamToken>(query).then(
(res) => res.data
);

if (!(streamToken instanceof StreamToken)) {
throw new ClientError(
`Error requesting a stream token. Expected a StreamToken as the query result, but received ${typeof streamToken}. Your query must return the result of '<Set>.toStream' or '<Set>.changesOn')\n` +
`Query result: ${JSON.stringify(streamToken, null)}`
);
}
} else {
streamToken = query;
}

return new StreamClient(
streamToken,
this.#clientConfiguration,
Expand Down

0 comments on commit 935d999

Please sign in to comment.