@rebasepro/common 0.11.1-canary.gfd39654 → 0.12.0

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.
@@ -28,10 +28,10 @@ export declare function buildRebaseData(driver: DataDriver, options?: EntityData
28
28
  /**
29
29
  * Wrap a flat {@link RebaseSdkData} into a Entity-shaped {@link RebaseData}.
30
30
  *
31
- * This is the **CMS boundary**: the SDK client (`client.data`) returns flat
31
+ * This is the **admin boundary**: the SDK client (`client.data`) returns flat
32
32
  * rows, but the admin renders the `Entity` view-model (`entity.values.*`).
33
33
  * `core/Rebase.tsx` wraps `client.data` through this before handing it to the
34
- * CMS `RebaseDataContext` — without it the admin renders rows with only their
34
+ * admin `RebaseDataContext` — without it the admin renders rows with only their
35
35
  * `id`.
36
36
  */
37
37
  export declare function wrapAsEntityData(sdkData: RebaseSdkData, options?: EntityDataOptions): RebaseData;
@@ -49,7 +49,11 @@ export declare function wrapAsSdkData(entityData: RebaseData): RebaseSdkData;
49
49
  *
50
50
  * This is the developer-facing SDK data layer used by backend framework
51
51
  * callbacks & scripts (`context.data` / `rebase.data`). It returns flat rows —
52
- * identical in shape to the frontend SDK client so the API is symmetric
53
- * across front and back. The admin CMS uses {@link buildRebaseData} (Entity).
52
+ * identical in shape to the frontend SDK client, down to how a relation is
53
+ * served: a foreign key stays a foreign key, and a relation named in `include`
54
+ * arrives as the target's own columns. The `{ __type: "relation" }` envelope is
55
+ * the admin's view-model and never reaches here.
56
+ *
57
+ * The admin uses {@link buildRebaseData} (Entity) over its own driver.
54
58
  */
55
59
  export declare function buildSdkData(driver: DataDriver): RebaseSdkData;
@@ -0,0 +1,75 @@
1
+ import { FindAllParams, FindParams, FindResult, IterateParams } from "@rebasepro/types";
2
+ /**
3
+ * The pagination engine behind `iterate()` / `findAll()`.
4
+ *
5
+ * It lives here, above both transports, on purpose: the HTTP client and the
6
+ * in-process accessor implement the same `SDKCollectionClient` contract, and a
7
+ * helper written twice is a helper that drifts. Both call into this file, so
8
+ * "the SDK paginates like *this*" has exactly one definition.
9
+ *
10
+ * Everything below is expressed in terms of a single `find(params)` function,
11
+ * which is all either transport has to supply.
12
+ */
13
+ /** Rows requested per page when the caller does not say. */
14
+ export declare const DEFAULT_PAGE_SIZE = 200;
15
+ /** Rows `findAll()` will materialise before it refuses to continue. */
16
+ export declare const DEFAULT_FIND_ALL_MAX_ROWS = 10000;
17
+ /**
18
+ * Requests one walk may make before it gives up on the server ever saying
19
+ * `hasMore: false`. At the default page size that is two million rows — far
20
+ * past any legitimate walk, and short of running forever.
21
+ */
22
+ export declare const DEFAULT_MAX_PAGES = 10000;
23
+ /** Why a pagination walk refused to continue. */
24
+ export type PaginationErrorCode =
25
+ /** `findAll()` matched more rows than its ceiling allows. */
26
+ "max-rows"
27
+ /** The walk made its maximum number of requests without the server finishing. */
28
+ | "max-pages"
29
+ /** A cursor row carried no value for the cursor column. */
30
+ | "cursor-missing"
31
+ /** Two consecutive pages ended on the same cursor value, so the walk cannot advance. */
32
+ | "cursor-stalled"
33
+ /** A `cursor` was asked for on one column while `orderBy` sorted by another. */
34
+ | "cursor-order-mismatch";
35
+ /**
36
+ * Thrown when a walk stops for a reason the caller needs to know about.
37
+ *
38
+ * Every one of these is a case where the alternative would be silent: a
39
+ * truncated array that looks complete, or a loop that never returns. Check
40
+ * {@link code} to tell them apart.
41
+ */
42
+ export declare class RebasePaginationError extends Error {
43
+ readonly code: PaginationErrorCode;
44
+ constructor(code: PaginationErrorCode, message: string);
45
+ }
46
+ /** The one thing a transport has to provide to be paginated. */
47
+ export type PageFinder<M extends Record<string, unknown> = Record<string, unknown>> = (params: FindParams<M>) => Promise<FindResult<M>>;
48
+ /**
49
+ * Walk every row a query matches, yielding one row at a time and fetching the
50
+ * next page only when the consumer asks for it.
51
+ *
52
+ * See {@link SDKCollectionClient.iterate} for the caller-facing contract,
53
+ * including the offset-drift caveat and the `cursor` alternative.
54
+ *
55
+ * @param find the transport's single-page read
56
+ * @param params `find()` parameters minus the window, plus the walk options
57
+ * @param label the collection name, so an error says which walk failed
58
+ */
59
+ export declare function paginateFind<M extends Record<string, unknown> = Record<string, unknown>>(find: PageFinder<M>, params?: IterateParams<M>, label?: string): AsyncGenerator<M, void, undefined>;
60
+ /**
61
+ * {@link paginateFind}, collected into an array under a ceiling.
62
+ *
63
+ * See {@link SDKCollectionClient.findAll}.
64
+ */
65
+ export declare function collectAllPages<M extends Record<string, unknown> = Record<string, unknown>>(find: PageFinder<M>, params?: FindAllParams<M>, label?: string): Promise<M[]>;
66
+ /**
67
+ * Build the `iterate` / `findAll` pair for one collection from its `find`.
68
+ *
69
+ * Both transports call this, which is what keeps the two implementations from
70
+ * being two implementations.
71
+ */
72
+ export declare function createPaginationHelpers<M extends Record<string, unknown> = Record<string, unknown>>(find: PageFinder<M>, label: string): {
73
+ iterate: (params?: IterateParams<M>) => AsyncIterableIterator<M>;
74
+ findAll: (params?: FindAllParams<M>) => Promise<M[]>;
75
+ };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./data/buildRebaseData";
4
4
  export * from "./data/buildRoutedRebaseData";
5
5
  export * from "./data/resolveDataSource";
6
6
  export * from "./data/query_builder";
7
+ export * from "./data/paginate";
7
8
  export * from "./data/filter-dialect";
8
9
  export * from "./data/sort-dialect";
9
10
  export * from "./table-classification";