fixed the type of onPaginatedUpdate_experimental in simple_client#366
Open
UfukUstali wants to merge 1 commit intoget-convex:mainfrom
Open
fixed the type of onPaginatedUpdate_experimental in simple_client#366UfukUstali wants to merge 1 commit intoget-convex:mainfrom
UfukUstali wants to merge 1 commit intoget-convex:mainfrom
Conversation
Member
|
good catch! |
Author
|
i think the ci failed due to an unrelated rust issue. also on an unrelated note, can i open another pr to make it more viable for community framework bindings to use this function rather then reinventing the wheel for pagination themselves diff --git a/packages/convex-js/src/browser/simple_client.ts b/packages/convex-js/src/browser/simple_client.ts
index e614d42..5725005 100644
--- a/packages/convex-js/src/browser/simple_client.ts
+++ b/packages/convex-js/src/browser/simple_client.ts
@@ -8,9 +8,12 @@ import {
UserIdentityAttributes,
} from "./index.js";
import {
+ BetterOmit,
+ Expand,
FunctionArgs,
FunctionReference,
FunctionReturnType,
+ PaginationOptions,
PaginationResult,
} from "../server/index.js";
import { getFunctionName } from "../server/api.js";
@@ -22,6 +25,7 @@ import {
} from "./sync/paginated_query_client.js";
import { PaginatedQueryResult } from "./sync/pagination.js";
import { serializedQueryTokenIsPaginated } from "./sync/udf_path_utils.js";
+import { Value } from "../values/value.js";
// In Node.js builds this points to a bundled WebSocket implementation. If no
// WebSocket implementation is manually specified or globally available,
@@ -33,6 +37,17 @@ export function setDefaultWebSocketConstructor(ws: typeof WebSocket) {
defaultWebSocketConstructor = ws;
}
+type PaginatedQueryReference = FunctionReference<
+ "query",
+ "public",
+ { paginationOpts: PaginationOptions },
+ PaginationResult<any>
+>;
+
+type PaginatedQueryArgs<Query extends PaginatedQueryReference> = Expand<
+ BetterOmit<FunctionArgs<Query>, "paginationOpts">
+>;
+
export type ConvexClientOptions = BaseConvexClientOptions & {
/**
* `disabled` makes onUpdate callback registration a no-op and actions,
@@ -260,13 +275,15 @@ export class ConvexClient {
*
* @return an {@link Unsubscribe} function to stop calling the callback.
*/
- onPaginatedUpdate_experimental<Query extends FunctionReference<"query">>(
+ onPaginatedUpdate_experimental<Query extends PaginatedQueryReference>(
query: Query,
- args: FunctionArgs<Query>,
+ args: PaginatedQueryArgs<Query>,
options: { initialNumItems: number },
- callback: (result: PaginationResult<FunctionReturnType<Query>>) => unknown,
+ callback: (
+ result: PaginatedQueryResult<FunctionReturnType<Query>>,
+ ) => unknown,
onError?: (e: Error) => unknown,
- ): Unsubscribe<PaginatedQueryResult<FunctionReturnType<Query>[]>> {
+ ): Unsubscribe<PaginatedQueryResult<FunctionReturnType<Query>>> {
if (this.disabled) {
return this.createDisabledUnsubscribe<
PaginatedQueryResult<FunctionReturnType<Query>>
@@ -275,13 +292,12 @@ export class ConvexClient {
const paginationOptions = {
initialNumItems: options.initialNumItems,
- id: -1,
+ id: nextPaginationId(),
};
const { paginatedQueryToken, unsubscribe } = this.paginatedClient.subscribe(
getFunctionName(query),
- args,
- // Simple client doesn't use IDs, there's no expectation that these queries remain separate.
+ args as Record<string, Value>,
paginationOptions,
);
@@ -311,7 +327,7 @@ export class ConvexClient {
}
const unsubscribeProps: RemoveCallSignature<
- Unsubscribe<PaginatedQueryResult<FunctionReturnType<Query>[]>>
+ Unsubscribe<PaginatedQueryResult<FunctionReturnType<Query>>>
> = {
unsubscribe: () => {
if (this.closed) {
@@ -322,11 +338,8 @@ export class ConvexClient {
unsubscribe();
},
getCurrentValue: () => {
- const result = this.paginatedClient.localQueryResult(
- getFunctionName(query),
- args,
- paginationOptions,
- );
+ const result =
+ this.paginatedClient.localQueryResultByToken(paginatedQueryToken);
// cast to apply the specific function type
return result as
| PaginatedQueryResult<FunctionReturnType<Query>>
@@ -573,6 +586,13 @@ export class ConvexClient {
}
}
+let paginationId = 0;
+
+function nextPaginationId(): number {
+ paginationId++;
+ return paginationId;
+}
+
// internal information tracked about each registered callback
type QueryInfo = {
callback: (result: any, meta: unknown) => unknown; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://github.com/get-convex/convex-backend/blob/main/npm-packages/convex/src/browser/simple_client.ts#L451-L474
return of
localQueryResultByTokenisPaginatedQueryResultnotPaginationResult, this was a typo i think.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.