lazypock 0.19.1 → 0.19.2
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/dist/index.cjs +10 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +10 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/collection.ts +16 -2
- package/src/collections.ts +3 -2
package/package.json
CHANGED
package/src/collection.ts
CHANGED
|
@@ -48,6 +48,19 @@ type StableRequestValue =
|
|
|
48
48
|
* Strips request-transport keys (`requestKey`, `singleFlight`, `fetch`,
|
|
49
49
|
* `signal`) so functionally-identical calls share one key.
|
|
50
50
|
*/
|
|
51
|
+
/**
|
|
52
|
+
* Largest `perPage` the server accepts (`MAX_PER_PAGE` in lazypock's pagination).
|
|
53
|
+
* `getFullList()` pages at this size by default and never asks for more: a larger
|
|
54
|
+
* `perPage` is rejected with a 400 rather than clamped.
|
|
55
|
+
*/
|
|
56
|
+
export const MAX_PER_PAGE = 500;
|
|
57
|
+
|
|
58
|
+
/** Keep a requested page size within what the server accepts (1..MAX_PER_PAGE). */
|
|
59
|
+
export function clampBatch(batch: number): number {
|
|
60
|
+
if (!Number.isFinite(batch)) return MAX_PER_PAGE;
|
|
61
|
+
return Math.min(Math.max(1, Math.floor(batch)), MAX_PER_PAGE);
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
export function stableStringify(value: unknown): string {
|
|
52
65
|
const seen = new Set<object>();
|
|
53
66
|
const sort = (v: unknown): StableRequestValue => {
|
|
@@ -771,7 +784,7 @@ export class CollectionService<
|
|
|
771
784
|
}
|
|
772
785
|
|
|
773
786
|
/**
|
|
774
|
-
* Fetch all records at once (auto-paginates). Mirrors PocketBase's
|
|
787
|
+
* Fetch all records at once (auto-paginates; `batch` defaults to and is capped at 500, the server max `perPage`). Mirrors PocketBase's
|
|
775
788
|
* `pb.collection(name).getFullList()`.
|
|
776
789
|
*
|
|
777
790
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|
|
@@ -784,7 +797,8 @@ export class CollectionService<
|
|
|
784
797
|
>(
|
|
785
798
|
options?: ListOptions<TFields, E, S, F> & RequestOptions,
|
|
786
799
|
): Promise<Array<T2 & { expand?: ExpandObj<E, TExpand> }>> {
|
|
787
|
-
const { batch =
|
|
800
|
+
const { batch: requestedBatch = MAX_PER_PAGE, ...rest } = options ?? {};
|
|
801
|
+
const batch = clampBatch(requestedBatch as number);
|
|
788
802
|
|
|
789
803
|
// Resolve a `filter` callback before computing the dedup key so the key
|
|
790
804
|
// reflects the actual filter expression (a function is not serializable).
|
package/src/collections.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import type { HttpClient } from "./http";
|
|
14
14
|
import type { RealtimeService } from "./realtime";
|
|
15
|
-
import { stableStringify } from "./collection";
|
|
15
|
+
import { clampBatch, MAX_PER_PAGE, stableStringify } from "./collection";
|
|
16
16
|
import type { ListResult, RequestOptions, ApiRecord } from "./types";
|
|
17
17
|
|
|
18
18
|
const REGISTRY_TOPIC = "collections";
|
|
@@ -74,7 +74,8 @@ export class CollectionsService {
|
|
|
74
74
|
options?: Record<string, unknown> & RequestOptions,
|
|
75
75
|
): Promise<Array<T>> {
|
|
76
76
|
if (!this.http) return [];
|
|
77
|
-
const { batch =
|
|
77
|
+
const { batch: requestedBatch = MAX_PER_PAGE, ...rest } = options ?? {};
|
|
78
|
+
const batch = clampBatch(requestedBatch as number);
|
|
78
79
|
|
|
79
80
|
// Extract request-transport options so they never leak into query params.
|
|
80
81
|
const {
|