convex-helpers 0.1.98 → 0.1.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/react/cache/hooks.d.ts.map +1 -1
- package/react/cache/hooks.js +25 -24
- package/react/cache/hooks.ts +25 -23
- package/react.d.ts.map +1 -1
- package/react.js +5 -3
- package/react.ts +3 -2
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAOtB,OAAO,KAAK,EAEV,iBAAiB,EACjB,kBAAkB,EAInB,MAAM,eAAe,CAAC;AAkBvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,KAAK,CAAC,CAgCzC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,iBAAiB,CAAC,OAAO,CAAC,EAC/D,KAAK,EAAE,KAAK,EACZ,GAAG,SAAS,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAC1C,kBAAkB,CAAC,KAAK,CAAC,GAAG,SAAS,CAoBvC;AAoHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,uBAAuB,EACrE,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,GAAG,MAAM,EACxC,OAAO,EAAE;IACP,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,GACA,2BAA2B,CAAC,KAAK,CAAC,CA6PpC"}
|
package/react/cache/hooks.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useConvex,
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
+
ConvexProvider, useQueries as useQueriesCore, } from "convex/react";
|
|
2
4
|
import { getFunctionName } from "convex/server";
|
|
3
5
|
import { useContext, useEffect, useMemo, useState } from "react";
|
|
4
6
|
import { ConvexQueryCacheContext } from "./provider.js";
|
|
@@ -83,7 +85,6 @@ export function useQueries(queries) {
|
|
|
83
85
|
};
|
|
84
86
|
},
|
|
85
87
|
// Safe to ignore query and args since queryKey is derived from them
|
|
86
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
87
88
|
[registry, JSON.stringify(queryKeys)]);
|
|
88
89
|
const memoizedQueries = useMemo(() => queries, [JSON.stringify(queryKeys)]);
|
|
89
90
|
return useQueriesCore(memoizedQueries);
|
|
@@ -245,7 +246,7 @@ const completeSplitQuery = (key) => (prevState) => {
|
|
|
245
246
|
*/
|
|
246
247
|
export function usePaginatedQuery(query, args, options) {
|
|
247
248
|
if (typeof options?.initialNumItems !== "number" ||
|
|
248
|
-
options.initialNumItems
|
|
249
|
+
options.initialNumItems <= 0) {
|
|
249
250
|
throw new Error(`\`options.initialNumItems\` must be a positive number. Received \`${options?.initialNumItems}\`.`);
|
|
250
251
|
}
|
|
251
252
|
const skip = args === "skip";
|
|
@@ -282,9 +283,7 @@ export function usePaginatedQuery(query, args, options) {
|
|
|
282
283
|
// ESLint doesn't like that we're stringifying the args. We do this because
|
|
283
284
|
// we want to avoid rerendering if the args are a different
|
|
284
285
|
// object that serializes to the same result.
|
|
285
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
286
286
|
}, [
|
|
287
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
288
287
|
JSON.stringify(convexToJson(argsObject)),
|
|
289
288
|
queryName,
|
|
290
289
|
options.initialNumItems,
|
|
@@ -369,25 +368,27 @@ export function usePaginatedQuery(query, args, options) {
|
|
|
369
368
|
logger,
|
|
370
369
|
]);
|
|
371
370
|
const statusObject = useMemo(() => {
|
|
372
|
-
if (maybeLastResult === undefined) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
371
|
+
if (maybeLastResult === undefined && currState.pageKeys.length <= 1) {
|
|
372
|
+
return {
|
|
373
|
+
status: "LoadingFirstPage",
|
|
374
|
+
isLoading: true,
|
|
375
|
+
loadMore: (_numItems) => {
|
|
376
|
+
// Intentional noop.
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
else if (maybeLastResult === undefined ||
|
|
381
|
+
// The last page (which isn't the first page) is splitting, which is how
|
|
382
|
+
// we model loading more with custom pagination.
|
|
383
|
+
(options.customPagination &&
|
|
384
|
+
currState.ongoingSplits[currState.pageKeys.at(-1)] !== undefined)) {
|
|
385
|
+
return {
|
|
386
|
+
status: "LoadingMore",
|
|
387
|
+
isLoading: true,
|
|
388
|
+
loadMore: (_numItems) => {
|
|
389
|
+
// Intentional noop.
|
|
390
|
+
},
|
|
391
|
+
};
|
|
391
392
|
}
|
|
392
393
|
if (maybeLastResult.isDone) {
|
|
393
394
|
return {
|
package/react/cache/hooks.ts
CHANGED
|
@@ -6,8 +6,9 @@ import type {
|
|
|
6
6
|
UsePaginatedQueryReturnType,
|
|
7
7
|
} from "convex/react";
|
|
8
8
|
import {
|
|
9
|
-
ConvexProvider,
|
|
10
9
|
useConvex,
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
ConvexProvider,
|
|
11
12
|
useQueries as useQueriesCore,
|
|
12
13
|
} from "convex/react";
|
|
13
14
|
import type {
|
|
@@ -117,7 +118,6 @@ export function useQueries(
|
|
|
117
118
|
};
|
|
118
119
|
},
|
|
119
120
|
// Safe to ignore query and args since queryKey is derived from them
|
|
120
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
121
|
[registry, JSON.stringify(queryKeys)],
|
|
122
122
|
);
|
|
123
123
|
const memoizedQueries = useMemo(() => queries, [JSON.stringify(queryKeys)]);
|
|
@@ -336,7 +336,7 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
|
|
|
336
336
|
): UsePaginatedQueryReturnType<Query> {
|
|
337
337
|
if (
|
|
338
338
|
typeof options?.initialNumItems !== "number" ||
|
|
339
|
-
options.initialNumItems
|
|
339
|
+
options.initialNumItems <= 0
|
|
340
340
|
) {
|
|
341
341
|
throw new Error(
|
|
342
342
|
`\`options.initialNumItems\` must be a positive number. Received \`${options?.initialNumItems}\`.`,
|
|
@@ -376,9 +376,7 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
|
|
|
376
376
|
// ESLint doesn't like that we're stringifying the args. We do this because
|
|
377
377
|
// we want to avoid rerendering if the args are a different
|
|
378
378
|
// object that serializes to the same result.
|
|
379
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
380
379
|
}, [
|
|
381
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
382
380
|
JSON.stringify(convexToJson(argsObject as Value)),
|
|
383
381
|
queryName,
|
|
384
382
|
options.initialNumItems,
|
|
@@ -489,24 +487,28 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
|
|
|
489
487
|
]);
|
|
490
488
|
|
|
491
489
|
const statusObject = useMemo(() => {
|
|
492
|
-
if (maybeLastResult === undefined) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
490
|
+
if (maybeLastResult === undefined && currState.pageKeys.length <= 1) {
|
|
491
|
+
return {
|
|
492
|
+
status: "LoadingFirstPage",
|
|
493
|
+
isLoading: true,
|
|
494
|
+
loadMore: (_numItems: number) => {
|
|
495
|
+
// Intentional noop.
|
|
496
|
+
},
|
|
497
|
+
} as const;
|
|
498
|
+
} else if (
|
|
499
|
+
maybeLastResult === undefined ||
|
|
500
|
+
// The last page (which isn't the first page) is splitting, which is how
|
|
501
|
+
// we model loading more with custom pagination.
|
|
502
|
+
(options.customPagination &&
|
|
503
|
+
currState.ongoingSplits[currState.pageKeys.at(-1)!] !== undefined)
|
|
504
|
+
) {
|
|
505
|
+
return {
|
|
506
|
+
status: "LoadingMore",
|
|
507
|
+
isLoading: true,
|
|
508
|
+
loadMore: (_numItems: number) => {
|
|
509
|
+
// Intentional noop.
|
|
510
|
+
},
|
|
511
|
+
} as const;
|
|
510
512
|
}
|
|
511
513
|
if (maybeLastResult.isDone) {
|
|
512
514
|
return {
|
package/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,UAAU,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["react.ts"],"names":[],"mappings":"AAAA,OAAO,KA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AClB,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;CACf,CAsDN;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,uBAAuB,EACrE,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,GAAG,MAAM,EACxC,OAAO,EAAE;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,GACnC,2BAA2B,CAAC,KAAK,CAAC,CA8OpC"}
|
package/react.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ConvexError } from "convex/values";
|
|
2
2
|
import { convexToJson } from "convex/values";
|
|
3
|
-
import { useConvex, useQueries,
|
|
3
|
+
import { useConvex, useQueries,
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
useQuery as useQueryOriginal, } from "convex/react";
|
|
4
6
|
import { getFunctionName } from "convex/server";
|
|
5
7
|
import { useMemo, useState } from "react";
|
|
6
8
|
/**
|
|
@@ -271,7 +273,7 @@ export function usePaginatedQuery(query, args, options) {
|
|
|
271
273
|
logger,
|
|
272
274
|
]);
|
|
273
275
|
const statusObject = useMemo(() => {
|
|
274
|
-
if (maybeLastResult === undefined && currState.
|
|
276
|
+
if (maybeLastResult === undefined && currState.pageKeys.length <= 1) {
|
|
275
277
|
return {
|
|
276
278
|
status: "LoadingFirstPage",
|
|
277
279
|
isLoading: true,
|
|
@@ -283,7 +285,7 @@ export function usePaginatedQuery(query, args, options) {
|
|
|
283
285
|
else if (maybeLastResult === undefined ||
|
|
284
286
|
// The last page (which isn't the first page) is splitting, which is how
|
|
285
287
|
// we model loading more in this helper
|
|
286
|
-
currState.ongoingSplits[currState.
|
|
288
|
+
currState.ongoingSplits[currState.pageKeys.at(-1)] !== undefined) {
|
|
287
289
|
return {
|
|
288
290
|
status: "LoadingMore",
|
|
289
291
|
isLoading: true,
|
package/react.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { convexToJson } from "convex/values";
|
|
|
9
9
|
import {
|
|
10
10
|
useConvex,
|
|
11
11
|
useQueries,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
13
|
useQuery as useQueryOriginal,
|
|
13
14
|
} from "convex/react";
|
|
14
15
|
import type {
|
|
@@ -355,7 +356,7 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
|
|
|
355
356
|
]);
|
|
356
357
|
|
|
357
358
|
const statusObject = useMemo(() => {
|
|
358
|
-
if (maybeLastResult === undefined && currState.
|
|
359
|
+
if (maybeLastResult === undefined && currState.pageKeys.length <= 1) {
|
|
359
360
|
return {
|
|
360
361
|
status: "LoadingFirstPage",
|
|
361
362
|
isLoading: true,
|
|
@@ -367,7 +368,7 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
|
|
|
367
368
|
maybeLastResult === undefined ||
|
|
368
369
|
// The last page (which isn't the first page) is splitting, which is how
|
|
369
370
|
// we model loading more in this helper
|
|
370
|
-
currState.ongoingSplits[currState.
|
|
371
|
+
currState.ongoingSplits[currState.pageKeys.at(-1)!] !== undefined
|
|
371
372
|
) {
|
|
372
373
|
return {
|
|
373
374
|
status: "LoadingMore",
|