@visulima/pagination 5.0.0-alpha.12 → 5.0.0-alpha.14

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/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## @visulima/pagination [5.0.0-alpha.14](https://github.com/visulima/visulima/compare/@visulima/pagination@5.0.0-alpha.13...@visulima/pagination@5.0.0-alpha.14) (2026-06-13)
2
+
3
+ ### Features
4
+
5
+ * **pagination:** fix docs, add cursor/window pagination + openapi nullability ([d33feb8](https://github.com/visulima/visulima/commit/d33feb85ad49a1336c55b5ab12a18a80c9a776b0))
6
+
7
+ ### Bug Fixes
8
+
9
+ * **pagination:** accept rows as an array, not variadic ([f4c3940](https://github.com/visulima/visulima/commit/f4c3940a7c799b32f1639473c01e2d43426f3c0c))
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * **pagination:** apply formatting ([52c9c3b](https://github.com/visulima/visulima/commit/52c9c3b312d9e918235e2403918539a653c53a87))
14
+ * **pagination:** reformat long lines and normalize markdown italics ([8467425](https://github.com/visulima/visulima/commit/84674254fb5dcb2fcab600abe3f006b41bfabb88))
15
+
16
+ ## @visulima/pagination [5.0.0-alpha.13](https://github.com/visulima/visulima/compare/@visulima/pagination@5.0.0-alpha.12...@visulima/pagination@5.0.0-alpha.13) (2026-06-04)
17
+
18
+ ### Bug Fixes
19
+
20
+ * **pagination:** 3 bug fixes ([bcc5dbf](https://github.com/visulima/visulima/commit/bcc5dbf91aac391b3df1d83d6a1850a7b4bdbcc2))
21
+
22
+ ### Miscellaneous Chores
23
+
24
+ * apply eslint + prettier autofixes across packages ([c1bb784](https://github.com/visulima/visulima/commit/c1bb7848a0d93d0dfe2960c77e3cda22239c79a0))
25
+
1
26
  ## @visulima/pagination [5.0.0-alpha.12](https://github.com/visulima/visulima/compare/@visulima/pagination@5.0.0-alpha.11...@visulima/pagination@5.0.0-alpha.12) (2026-05-27)
2
27
 
3
28
  ### Bug Fixes
package/LICENSE.md CHANGED
@@ -23,11 +23,14 @@ SOFTWARE.
23
23
  <!-- DEPENDENCIES -->
24
24
 
25
25
  # Licenses of bundled dependencies
26
+
26
27
  The published @visulima/pagination artifact additionally contains code with the following licenses:
27
28
  BSD-3-Clause
28
29
 
29
30
  # Bundled dependencies:
31
+
30
32
  ## qs-esm
33
+
31
34
  License: BSD-3-Clause
32
35
  By: Payload, Jordan Harband
33
36
  Repository: https://github.com/payloadcms/qs-esm.git
@@ -42,11 +45,9 @@ Repository: https://github.com/payloadcms/qs-esm.git
42
45
  >
43
46
  > 1. Redistributions of source code must retain the above copyright notice, this
44
47
  > list of conditions and the following disclaimer.
45
- >
46
48
  > 2. Redistributions in binary form must reproduce the above copyright notice,
47
49
  > this list of conditions and the following disclaimer in the documentation
48
50
  > and/or other materials provided with the distribution.
49
- >
50
51
  > 3. Neither the name of the copyright holder nor the names of its
51
52
  > contributors may be used to endorse or promote products derived from
52
53
  > this software without specific prior written permission.
package/README.md CHANGED
@@ -36,6 +36,18 @@
36
36
 
37
37
  ## Features
38
38
 
39
+ - **Zero runtime dependencies** — tiny offset/limit paginator (Adonis-style).
40
+ - **`Paginator`** — an `Array` subclass holding the current page's rows, with rich meta (`total`, `lastPage`, first/last/next/previous URLs).
41
+ - **`CursorPaginator`** — cursor/keyset pagination for stable infinite scroll over large tables.
42
+ - **URL helpers** — `baseUrl()`, `queryString()`, `getUrl()`, `getUrlsForRange()`, and `getUrlsForWindow()` (windowed page links with `…` ellipsis markers).
43
+ - **Naming strategies** — emit `camelCase` (default) or `snake_case` (`per_page`, `last_page`, …) meta keys.
44
+ - **OpenAPI schema builders** — `createPaginationSchemaObject` / `createPaginationMetaSchemaObject`, with correct nullability + `required`, and an OpenAPI 3.1 variant.
45
+
46
+ > **Important:** `Paginator`/`paginate()` do **not** slice your rows. Pass in the
47
+ > rows for the current page already sliced at the data source
48
+ > (offset `(page - 1) * perPage`, limit `perPage`). `total` is the count of _all_
49
+ > matching records and is what drives `lastPage` and the URLs.
50
+
39
51
  ## Installation
40
52
 
41
53
  ```sh
@@ -52,30 +64,103 @@ pnpm add @visulima/pagination
52
64
 
53
65
  ## Usage
54
66
 
67
+ `paginate(page, perPage, total, rows)` returns a `Paginator` — an `Array`
68
+ subclass that holds the **current page's rows** (it does not slice them for you).
69
+ Call `.toJSON()` (or `JSON.stringify`) to get the `{ data, meta }` shape.
70
+
55
71
  ```ts
56
72
  import { paginate } from "@visulima/pagination";
57
73
 
58
- const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
74
+ const allItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
75
+
76
+ const page = 1;
77
+ const perPage = 5;
59
78
 
60
- const pagination = paginate(1, 5, items.length, items);
79
+ // Slice the rows for the current page yourself (a real app would do this in SQL).
80
+ const pageRows = allItems.slice((page - 1) * perPage, page * perPage);
61
81
 
62
- console.log(pagination);
82
+ const pagination = paginate(page, perPage, allItems.length, pageRows);
83
+
84
+ console.log(pagination.toJSON());
63
85
  // {
64
86
  // data: [1, 2, 3, 4, 5],
65
87
  // meta: {
66
- // total: 10,
67
- // perPage: 5,
68
- // page: 1,
69
- // lastPage: 2,
70
88
  // firstPage: 1,
71
89
  // firstPageUrl: "/?page=1",
90
+ // lastPage: 2,
72
91
  // lastPageUrl: "/?page=2",
73
92
  // nextPageUrl: "/?page=2",
93
+ // page: 1,
94
+ // perPage: 5,
74
95
  // previousPageUrl: null,
96
+ // total: 10,
75
97
  // }
76
98
  // }
99
+
100
+ // Note: `console.log(pagination)` prints just the array rows ([1,2,3,4,5]),
101
+ // because `Paginator` extends `Array`. Use `.toJSON()` / `JSON.stringify` for
102
+ // the full `{ data, meta }` payload.
103
+ ```
104
+
105
+ ### URLs and query strings
106
+
107
+ ```ts
108
+ const p = paginate(2, 10, 200, pageRows).baseUrl("/api/items").queryString({ sort: "asc" });
109
+
110
+ p.getUrl(3); // "/api/items?sort=asc&page=3"
111
+ p.getNextPageUrl(); // "/api/items?sort=asc&page=3"
112
+ p.getPreviousPageUrl(); // "/api/items?sort=asc&page=1"
113
+
114
+ // Windowed page links with ellipsis markers (page === null => render "…").
115
+ p.getUrlsForWindow({ eachSide: 2 });
116
+ // [ {page:1,...}, {page:null,url:null,...}, ...window..., {page:null,url:null}, {page:20,...} ]
77
117
  ```
78
118
 
119
+ ### snake_case meta (Laravel / AdonisJS style)
120
+
121
+ ```ts
122
+ import { paginate, snakeCaseNamingStrategy } from "@visulima/pagination";
123
+
124
+ paginate(1, 10, 100, pageRows).getMeta(snakeCaseNamingStrategy);
125
+ // { first_page: 1, per_page: 10, last_page: 10, ... }
126
+ ```
127
+
128
+ ### Cursor-based pagination
129
+
130
+ For stable infinite scroll / keyset pagination over large tables, use
131
+ `CursorPaginator`:
132
+
133
+ ```ts
134
+ import { CursorPaginator } from "@visulima/pagination";
135
+
136
+ const rows = [{ id: 5 }, { id: 6 }]; // pre-fetched page rows
137
+
138
+ const p = CursorPaginator.fromArray(2, rows, { currentCursor: "4", hasMore: true }).baseUrl("/api/items");
139
+
140
+ p.getMeta();
141
+ // {
142
+ // nextCursor: "6",
143
+ // nextPageUrl: "/api/items?cursor=6",
144
+ // perPage: 2,
145
+ // previousCursor: "5",
146
+ // previousPageUrl: "/api/items?cursor=5",
147
+ // }
148
+ ```
149
+
150
+ ### OpenAPI schemas
151
+
152
+ ```ts
153
+ import { createPaginationMetaSchemaObject, createPaginationSchemaObject } from "@visulima/pagination";
154
+
155
+ const meta = createPaginationMetaSchemaObject("PaginationData"); // OpenAPI 3.0
156
+ const meta31 = createPaginationMetaSchemaObject("PaginationData", { openApiVersion: "3.1" });
157
+
158
+ const schema = createPaginationSchemaObject("UserList", { $ref: "#/components/schemas/User" });
159
+ ```
160
+
161
+ `nextPageUrl`/`previousPageUrl` are emitted as nullable (they are `null` on the
162
+ last/first page) and every field is listed in `required`.
163
+
79
164
  ## Supported Node.js Versions
80
165
 
81
166
  Libraries in this ecosystem make the best effort to track
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import { OpenAPIV3 } from 'openapi-types';
2
2
  interface PaginationMeta {
3
3
  firstPage: number;
4
- firstPageUrl: string | null;
4
+ /**
5
+ * The URL for the first page. Always a string — `getUrl()` never returns null.
6
+ */
7
+ firstPageUrl: string;
5
8
  lastPage: number;
6
- lastPageUrl: string | null;
9
+ /**
10
+ * The URL for the last page. Always a string — `getUrl()` never returns null.
11
+ */
12
+ lastPageUrl: string;
7
13
  nextPageUrl: string | null;
8
14
  page: number;
9
15
  perPage: number;
@@ -14,12 +20,71 @@ interface PaginationResult<Result> {
14
20
  data: Result[];
15
21
  meta: PaginationMeta;
16
22
  }
23
+ /**
24
+ * A key-transform applied to {@link PaginationMeta} keys. Return the desired
25
+ * output key for a given camelCase meta key (e.g. `perPage` -> `per_page`).
26
+ */
27
+ type NamingStrategy = (key: string) => string;
28
+ /**
29
+ * A windowed page-range entry. A `null` `page`/`url` represents an ellipsis ("…")
30
+ * gap that a UI should render between page links.
31
+ */
32
+ interface WindowedUrl {
33
+ isActive: boolean;
34
+ page: number | null;
35
+ url: string | null;
36
+ }
37
+ interface WindowOptions {
38
+ eachSide?: number;
39
+ }
40
+ interface CursorPaginatorOptions<T> {
41
+ /**
42
+ * The cursor that was used to fetch the current page (e.g. the `cursor`
43
+ * query parameter), if any. Used to derive `previousCursor`.
44
+ */
45
+ currentCursor?: string | null;
46
+
47
+ /**
48
+ * Derives the opaque cursor string for a row. Defaults to `String(row.id)`
49
+ * when the row has an `id`, otherwise `String(row)`.
50
+ */
51
+ getCursor?: (row: T) => string;
52
+
53
+ /**
54
+ * Whether a next page exists. Defaults to `false`.
55
+ */
56
+ hasMore?: boolean;
57
+ }
58
+ interface CursorPaginationMeta {
59
+ nextCursor: string | null;
60
+ nextPageUrl: string | null;
61
+ perPage: number;
62
+ previousCursor: string | null;
63
+ previousPageUrl: string | null;
64
+ }
65
+ interface CursorPaginationResult<Result> {
66
+ data: Result[];
67
+ meta: CursorPaginationMeta;
68
+ }
69
+ interface CursorPaginator$1<Result> extends Array<Result> {
70
+ all: () => Result[];
71
+ baseUrl: (url: string) => this;
72
+ getMeta: () => CursorPaginationMeta;
73
+ getNextCursor: () => string | null;
74
+ getPreviousCursor: () => string | null;
75
+ getUrl: (cursor: string | null) => string | null;
76
+ readonly hasMorePages: boolean;
77
+ readonly isEmpty: boolean;
78
+ readonly perPage: number;
79
+ queryString: (values: Record<string, unknown>) => this;
80
+ toJSON: () => CursorPaginationResult<Result>;
81
+ }
17
82
  interface Paginator$1<Result> extends Array<Result> {
18
83
  all: () => Result[];
19
84
  baseUrl: (url: string) => this;
20
- readonly currentPage: number;
85
+ currentPage: number;
21
86
  readonly firstPage: number;
22
- getMeta: () => PaginationMeta;
87
+ getMeta: (namingStrategy?: NamingStrategy) => PaginationMeta;
23
88
  getNextPageUrl: () => string | null;
24
89
  getPreviousPageUrl: () => string | null;
25
90
  getUrl: (page: number) => string;
@@ -28,6 +93,7 @@ interface Paginator$1<Result> extends Array<Result> {
28
93
  page: number;
29
94
  url: string;
30
95
  }[];
96
+ getUrlsForWindow: (options?: WindowOptions) => WindowedUrl[];
31
97
  readonly hasMorePages: boolean;
32
98
  readonly hasPages: boolean;
33
99
  readonly hasTotal: boolean;
@@ -35,22 +101,111 @@ interface Paginator$1<Result> extends Array<Result> {
35
101
  readonly lastPage: number;
36
102
  readonly perPage: number;
37
103
  queryString: (values: Record<string, unknown>) => this;
38
- toJSON: () => PaginationResult<Result>;
104
+ toJSON: (namingStrategy?: NamingStrategy) => PaginationResult<Result>;
39
105
  readonly total: number;
40
106
  }
107
+ /**
108
+ * Cursor-based paginator for stable infinite-scroll / keyset pagination over
109
+ * large tables. Unlike the offset-based `Paginator`, it exposes opaque
110
+ * `nextCursor` / `previousCursor` values instead of page numbers.
111
+ *
112
+ * Like `Paginator`, the rows you pass are the pre-fetched rows for the current
113
+ * page — they are not sliced. `nextCursor` is derived from the last row via
114
+ * `getCursor`.
115
+ */
116
+ declare class CursorPaginator<T = unknown> extends Array<T> implements CursorPaginator$1<T> {
117
+ static override get [Symbol.species](): ArrayConstructor;
118
+ /**
119
+ * Construct a `CursorPaginator` from an array of rows without spreading them
120
+ * as call arguments (safe for large row sets).
121
+ * @param perPage Rows requested per page (clamped to be at least 1).
122
+ * @param rows The pre-fetched rows for the current page.
123
+ * @param options Current cursor, `hasMore` flag and `getCursor` resolver.
124
+ */
125
+ static fromArray<Result = unknown>(perPage: number, rows: Result[], options?: CursorPaginatorOptions<Result>): CursorPaginator<Result>;
126
+ readonly isEmpty: boolean;
127
+ readonly perPage: number;
128
+ private url;
129
+ private qs;
130
+ private baseQuery;
131
+ private readonly currentCursor;
132
+ private readonly getCursor;
133
+ private readonly hasMore;
134
+ constructor(perPage: number, options?: CursorPaginatorOptions<T>);
135
+ /**
136
+ * A shallow copy of the result rows for the current page (plain `Array`).
137
+ */
138
+ all(): T[];
139
+ /**
140
+ * Define base url for making the pagination links.
141
+ */
142
+ baseUrl(url: string): this;
143
+ /**
144
+ * Define query string to be appended to the pagination links.
145
+ */
146
+ queryString(values: Record<string, unknown>): this;
147
+ /**
148
+ * The cursor pointing at the next page, or `null` when there is no next page.
149
+ */
150
+ getNextCursor(): string | null;
151
+ /**
152
+ * The cursor pointing at the previous page (the cursor of the first row of
153
+ * the current page), or `null` when there is no previous page.
154
+ */
155
+ getPreviousCursor(): string | null;
156
+ /**
157
+ * Returns the url for a given cursor, or `null` when the cursor is `null`.
158
+ */
159
+ getUrl(cursor: string | null): string | null;
160
+ /**
161
+ * Returns JSON meta data for the cursor page.
162
+ */
163
+ getMeta(): CursorPaginationMeta;
164
+ /**
165
+ * Returns JSON representation of the paginated data.
166
+ */
167
+ toJSON(): CursorPaginationResult<T>;
168
+ /**
169
+ * Whether there are more pages to come.
170
+ */
171
+ get hasMorePages(): boolean;
172
+ }
41
173
  type UrlsForRange = {
42
174
  isActive: boolean;
43
175
  page: number;
44
176
  url: string;
45
177
  }[];
46
178
  /**
179
+ * Built-in `snake_case` naming strategy. Use it to emit Laravel/AdonisJS-style
180
+ * meta keys (`per_page`, `last_page`, …).
181
+ */
182
+ declare const snakeCaseNamingStrategy: NamingStrategy;
183
+ /**
47
184
  * Simple paginator works with the data set provided by the standard
48
185
  * `offset` and `limit` based pagination.
186
+ *
187
+ * `Paginator` is an `Array` subclass that holds **only the rows for the current
188
+ * page**. It does NOT slice the rows you pass in — you are expected to pre-slice
189
+ * the page rows (via your data store's `offset`/`limit`) before constructing it.
190
+ * `total` is the count of *all* matching records, used to compute `lastPage` and
191
+ * the pagination URLs.
49
192
  */
50
193
  declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T> {
51
- private readonly totalNumber;
52
- readonly perPage: number;
53
- currentPage: number;
194
+ /**
195
+ * Ensure inherited Array methods (map/filter/slice/...) return plain Arrays
196
+ * instead of partially-constructed Paginator instances.
197
+ */
198
+ static override get [Symbol.species](): ArrayConstructor;
199
+ /**
200
+ * Construct a `Paginator` from an array of rows. Alias for the array-based
201
+ * constructor; kept for backward compatibility. Safe for arbitrarily large
202
+ * row sets (no `Maximum call stack size exceeded`).
203
+ * @param totalNumber Total number of matching records.
204
+ * @param perPage Rows per page (clamped to be at least 1).
205
+ * @param currentPage The current page number (clamped to be at least 1).
206
+ * @param rows The pre-sliced rows for the current page.
207
+ */
208
+ static fromArray<Result = unknown>(totalNumber: number, perPage: number, currentPage: number, rows: Result[]): Paginator<Result>;
54
209
  /**
55
210
  * The first page is always 1
56
211
  */
@@ -59,12 +214,40 @@ declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T>
59
214
  * Find if results set is empty or not
60
215
  */
61
216
  readonly isEmpty: boolean;
217
+ /**
218
+ * Current page number. Always clamped to be at least 1.
219
+ */
220
+ currentPage: number;
221
+ private readonly totalNumber;
222
+ private readonly perPageNumber;
62
223
  private qs;
63
- private readonly rows;
64
224
  private url;
65
- constructor(totalNumber: number, perPage: number, currentPage: number, ...rows: T[]);
66
225
  /**
67
- * A reference to the result rows.
226
+ * Pre-serialized query string (without the trailing `page` parameter),
227
+ * recomputed only when `queryString()` changes. Avoids re-iterating and
228
+ * re-serializing `this.qs` on every `getUrl()` call in the `getMeta()` hot path.
229
+ */
230
+ private baseQuery;
231
+ /**
232
+ * The `rows` array is accepted as a single parameter (not spread as call
233
+ * arguments): spreading rows (`new Paginator(t, p, c, ...rows)`) or
234
+ * `this.push(...rows)` throws `RangeError: Maximum call stack size exceeded`
235
+ * around ~100k rows on V8. Index-writing the array avoids that entirely.
236
+ * @param totalNumber Total number of matching records (used for `lastPage`/URL math).
237
+ * @param perPage Rows per page (clamped to be at least 1).
238
+ * @param currentPage The current page number (clamped to be at least 1).
239
+ * @param rows The pre-sliced rows for the current page. They are NOT sliced by the paginator. Defaults to an empty array.
240
+ */
241
+ constructor(totalNumber: number, perPage: number, currentPage: number, rows?: T[]);
242
+ /**
243
+ * The number of rows shown per page.
244
+ */
245
+ get perPage(): number;
246
+ /**
247
+ * A reference to the result rows for the current page.
248
+ *
249
+ * Returns a shallow copy so callers cannot mutate the paginator's backing
250
+ * store, and so the returned value is a plain `Array` (not a `Paginator`).
68
251
  */
69
252
  all(): T[];
70
253
  /**
@@ -72,9 +255,11 @@ declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T>
72
255
  */
73
256
  baseUrl(url: string): this;
74
257
  /**
75
- * Returns JSON meta data.
258
+ * Returns JSON meta data. Pass `snakeCaseNamingStrategy` for
259
+ * Laravel/AdonisJS-style output.
260
+ * @param namingStrategy Optional key-transform applied to every meta key.
76
261
  */
77
- getMeta(): PaginationMeta;
262
+ getMeta(namingStrategy?: NamingStrategy): PaginationMeta;
78
263
  /**
79
264
  * Returns url for the next page.
80
265
  */
@@ -85,21 +270,29 @@ declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T>
85
270
  getPreviousPageUrl(): string | null;
86
271
  /**
87
272
  * Returns url for a given page. Doesn't validate the integrity of the
88
- * page.
273
+ * page (only clamps the page number to be at least 1).
89
274
  */
90
275
  getUrl(page: number): string;
91
276
  /**
92
- * Returns an array of urls under a given range.
277
+ * Returns an array of urls under a given inclusive range.
93
278
  */
94
279
  getUrlsForRange(start: number, end: number): UrlsForRange;
95
280
  /**
281
+ * Returns a windowed list of page urls centered on the current page, with
282
+ * `null`-page ellipsis markers for the gaps (e.g. `1 … 4 [5] 6 … 20`).
283
+ *
284
+ * Use the `page === null` entries to render an ellipsis ("…") in your UI.
285
+ */
286
+ getUrlsForWindow(options?: WindowOptions): WindowedUrl[];
287
+ /**
96
288
  * Define query string to be appended to the pagination links.
97
289
  */
98
290
  queryString(values: Record<string, unknown>): this;
99
291
  /**
100
292
  * Returns JSON representation of the paginated data.
293
+ * @param namingStrategy Optional key-transform applied to the `meta` keys.
101
294
  */
102
- toJSON(): PaginationResult<T>;
295
+ toJSON(namingStrategy?: NamingStrategy): PaginationResult<T>;
103
296
  /**
104
297
  * Find if there are more pages to come.
105
298
  */
@@ -126,7 +319,59 @@ declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T>
126
319
  */
127
320
  get total(): number;
128
321
  }
129
- declare const createPaginationMetaSchemaObject: (name?: string) => Record<string, OpenAPIV3.SchemaObject>;
130
- declare const createPaginationSchemaObject: (name: string, items: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, metaReference?: string) => Record<string, OpenAPIV3.SchemaObject>;
322
+ /**
323
+ * Which OpenAPI version to target. `"3.0"` (default) emits `nullable: true` on
324
+ * nullable URL fields; `"3.1"` emits the JSON-Schema `type: ["string", "null"]`
325
+ * form instead.
326
+ */
327
+ type OpenApiVersion = "3.0" | "3.1";
328
+ interface CreatePaginationMetaSchemaOptions {
329
+ /**
330
+ * Target OpenAPI version. Controls how nullable URL fields are encoded.
331
+ * Defaults to `"3.0"`.
332
+ */
333
+ openApiVersion?: OpenApiVersion;
334
+ }
335
+ interface CreatePaginationSchemaOptions {
336
+ /**
337
+ * The `$ref` pointing to the meta schema component.
338
+ * Defaults to `"#/components/schemas/PaginationData"`.
339
+ */
340
+ metaReference?: string;
341
+ }
342
+ /**
343
+ * Builds an OpenAPI schema object describing the `meta` block returned by
344
+ * `Paginator.getMeta()`.
345
+ *
346
+ * `nextPageUrl` and `previousPageUrl` are nullable at runtime (the paginator
347
+ * returns `null` on the first/last page), so they are emitted as nullable.
348
+ * `firstPageUrl`/`lastPageUrl` are always strings. A `required` array is emitted
349
+ * so generated clients treat every field as present. Pass
350
+ * `{ openApiVersion: "3.1" }` to emit JSON-Schema-style nullability.
351
+ * @param name The schema/component name. Defaults to `"PaginationData"`.
352
+ * @param options Schema-building options.
353
+ */
354
+ declare const createPaginationMetaSchemaObject: (name?: string, options?: CreatePaginationMetaSchemaOptions) => Record<string, OpenAPIV3.SchemaObject>;
355
+ /**
356
+ * Builds an OpenAPI schema object describing a full paginated response
357
+ * (`{ data: Item[], meta: PaginationData }`). Both `data` and `meta` are emitted
358
+ * as `required`.
359
+ * @param name The schema/component name.
360
+ * @param items The schema (or `$ref`) for a single item in `data`.
361
+ * @param metaReferenceOrOptions Either the meta `$ref` string (legacy) or an options object.
362
+ */
363
+ declare const createPaginationSchemaObject: (name: string, items: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, metaReferenceOrOptions?: string | CreatePaginationSchemaOptions) => Record<string, OpenAPIV3.SchemaObject>;
364
+ /**
365
+ * Create a {@link PaginatorInterface} for the given page of rows.
366
+ * @remarks
367
+ * The `rows` you pass in are treated as the rows for the current page **as-is** —
368
+ * they are NOT sliced. Pre-slice your rows at the data source using the offset
369
+ * (`(page - 1) * perPage`) and `perPage` limit. `total` is the count of all
370
+ * matching records and drives `lastPage`/URL computation.
371
+ * @param page The current page (clamped to be at least 1).
372
+ * @param perPage Rows per page (clamped to be at least 1).
373
+ * @param total Total number of matching records.
374
+ * @param rows The pre-sliced rows for the current page.
375
+ */
131
376
  declare const paginate: <Result>(page: number, perPage: number, total: number, rows: Result[]) => Paginator$1<Result>;
132
- export { type PaginationMeta, type PaginationResult, Paginator, type Paginator$1 as PaginatorInterface, createPaginationMetaSchemaObject, createPaginationSchemaObject, paginate };
377
+ export { type CreatePaginationMetaSchemaOptions, type CreatePaginationSchemaOptions, type CursorPaginationMeta, type CursorPaginationResult, CursorPaginator, type CursorPaginator$1 as CursorPaginatorInterface, type CursorPaginatorOptions, type NamingStrategy, type OpenApiVersion, type PaginationMeta, type PaginationResult, Paginator, type Paginator$1 as PaginatorInterface, type WindowOptions, type WindowedUrl, createPaginationMetaSchemaObject, createPaginationSchemaObject, paginate, snakeCaseNamingStrategy };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});import i from"./packem_shared/Paginator-Dj-l47Lc.js";import{createPaginationMetaSchemaObject as j,createPaginationSchemaObject as u}from"./packem_shared/createPaginationMetaSchemaObject-DGZPqai2.js";var c=Object.defineProperty,g=t((e,a)=>c(e,"name",{value:a,configurable:!0}),"e");const b=g((e,a,r,n)=>new i(r,a,e,...n),"paginate");export{i as Paginator,j as createPaginationMetaSchemaObject,u as createPaginationSchemaObject,b as paginate};
1
+ import o from"./packem_shared/Paginator-BvWV_Gen.js";import{snakeCaseNamingStrategy as c}from"./packem_shared/Paginator-BvWV_Gen.js";import{default as p}from"./packem_shared/CursorPaginator-6bNX6Dri.js";import{createPaginationMetaSchemaObject as x,createPaginationSchemaObject as P}from"./packem_shared/createPaginationMetaSchemaObject-BLaJWuDt.js";const i=(a,r,t,e)=>o.fromArray(t,r,a,e);export{p as CursorPaginator,o as Paginator,x as createPaginationMetaSchemaObject,P as createPaginationSchemaObject,i as paginate,c as snakeCaseNamingStrategy};
@@ -0,0 +1 @@
1
+ const h=s=>s!==null&&typeof s=="object"&&"id"in s?String(s.id):String(s);class o extends Array{static get[Symbol.species](){return Array}static fromArray(r,t,i={}){const e=new o(r,i),{length:n}=t;e.length=n;for(let u=0;u<n;u++)e[u]=t[u];return e.isEmpty=n===0,e}isEmpty;perPage;url="/";qs={};baseQuery="";currentCursor;getCursor;hasMore;constructor(r,t={}){super(),this.perPage=Number.isFinite(r)&&r>0?Math.trunc(r):1,this.currentCursor=t.currentCursor??null,this.getCursor=t.getCursor??h,this.hasMore=t.hasMore??!1,this.isEmpty=!0}all(){return[...this]}baseUrl(r){return this.url=r,this}queryString(r){this.qs=r;const t=new URLSearchParams;for(const[i,e]of Object.entries(this.qs))e!=null&&t.append(i,String(e));return this.baseQuery=t.toString(),this}getNextCursor(){return!this.hasMorePages||this.length===0?null:this.getCursor(this[this.length-1])}getPreviousCursor(){return this.currentCursor===null||this.length===0?null:this.getCursor(this[0])}getUrl(r){if(r===null)return null;const t=`cursor=${encodeURIComponent(r)}`;return this.baseQuery===""?`${this.url}?${t}`:`${this.url}?${this.baseQuery}&${t}`}getMeta(){const r=this.getNextCursor(),t=this.getPreviousCursor();return{nextCursor:r,nextPageUrl:this.getUrl(r),perPage:this.perPage,previousCursor:t,previousPageUrl:this.getUrl(t)}}toJSON(){return{data:this.all(),meta:this.getMeta()}}get hasMorePages(){return this.hasMore}}export{o as default};
@@ -0,0 +1 @@
1
+ const h=n=>n,P={firstPage:"first_page",firstPageUrl:"first_page_url",lastPage:"last_page",lastPageUrl:"last_page_url",nextPageUrl:"next_page_url",page:"page",perPage:"per_page",previousPageUrl:"previous_page_url",total:"total"},c=n=>P[n]??n;class o extends Array{static get[Symbol.species](){return Array}static fromArray(r,e,s,t){return new o(r,e,s,t)}firstPage=1;isEmpty;currentPage;totalNumber;perPageNumber;qs={};url="/";baseQuery="";constructor(r,e,s,t=[]){super();const{length:a}=t;this.length=a;for(let i=0;i<a;i++)this[i]=t[i];this.totalNumber=Number.isFinite(r)?Math.max(Math.trunc(r),0):0,this.perPageNumber=Number.isFinite(e)&&e>0?Math.trunc(e):1,this.currentPage=Number.isFinite(s)?Math.max(Math.trunc(s),1):1,this.isEmpty=a===0}get perPage(){return this.perPageNumber}all(){return[...this]}baseUrl(r){return this.url=r,this}getMeta(r=h){const e={firstPage:this.firstPage,firstPageUrl:this.getUrl(1),lastPage:this.lastPage,lastPageUrl:this.getUrl(this.lastPage),nextPageUrl:this.getNextPageUrl(),page:this.currentPage,perPage:this.perPage,previousPageUrl:this.getPreviousPageUrl(),total:this.total};if(r===h)return e;const s={};for(const[t,a]of Object.entries(e))s[r(t)]=a;return s}getNextPageUrl(){return this.hasMorePages?this.getUrl(this.currentPage+1):null}getPreviousPageUrl(){return this.currentPage>1?this.getUrl(this.currentPage-1):null}getUrl(r){const e=`page=${encodeURIComponent(String(Math.max(r,1)))}`;return this.baseQuery===""?`${this.url}?${e}`:`${this.url}?${this.baseQuery}&${e}`}getUrlsForRange(r,e){const s=[];for(let t=r;t<=e;t++)s.push({isActive:t===this.currentPage,page:t,url:this.getUrl(t)});return s}getUrlsForWindow(r={}){const e=r.eachSide,s=typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.trunc(e):2,{lastPage:t}=this;if(t<=s*2+3)return this.getUrlsForRange(1,t).map(l=>({...l}));const a=Math.max(this.currentPage-s,1),i=Math.min(this.currentPage+s,t),g=[],u={isActive:!1,page:null,url:null};a>1&&(g.push({isActive:this.currentPage===1,page:1,url:this.getUrl(1)}),a>2&&g.push({...u}));for(const l of this.getUrlsForRange(a,i))g.push(l);return i<t&&(i<t-1&&g.push({...u}),g.push({isActive:this.currentPage===t,page:t,url:this.getUrl(t)})),g}queryString(r){this.qs=r;const e=new URLSearchParams;for(const[s,t]of Object.entries(this.qs))t!=null&&e.append(s,String(t));return this.baseQuery=e.toString(),this}toJSON(r){return{data:this.all(),meta:this.getMeta(r)}}get hasMorePages(){return this.lastPage>this.currentPage}get hasPages(){return this.lastPage!==1}get hasTotal(){return this.total>0}get lastPage(){return Math.max(Math.ceil(this.total/this.perPageNumber),1)}get total(){return this.totalNumber}}export{o as default,c as snakeCaseNamingStrategy};
@@ -0,0 +1 @@
1
+ const n=["firstPage","firstPageUrl","lastPage","lastPageUrl","nextPageUrl","page","perPage","previousPageUrl","total"],r=(e,a)=>a==="3.1"?{description:e,type:["string","null"]}:{description:e,nullable:!0,type:"string"},o=(e="PaginationData",a={})=>{const{openApiVersion:t="3.0"}=a;return{[e]:{properties:{firstPage:{description:"Returns the number for the first page. It is always 1",minimum:0,type:"integer"},firstPageUrl:{description:"The URL for the first page",type:"string"},lastPage:{description:"Returns the value for the last page by taking the total of rows into account",minimum:0,type:"integer"},lastPageUrl:{description:"The URL for the last page",type:"string"},nextPageUrl:r("The URL for the next page, or null when on the last page",t),page:{description:"Current page number",minimum:1,type:"integer"},perPage:{description:"Returns the value for the limit passed to the paginate method",minimum:0,type:"integer"},previousPageUrl:r("The URL for the previous page, or null when on the first page",t),total:{description:"Holds the value for the total number of rows in the database",minimum:0,type:"integer"}},required:[...n],type:"object",xml:{name:e}}}},s=(e,a,t="#/components/schemas/PaginationData")=>{const i=typeof t=="string"?t:t.metaReference??"#/components/schemas/PaginationData";return{[e]:{properties:{data:{items:a,type:"array",xml:{name:"data",wrapped:!0}},meta:{$ref:i}},required:["data","meta"],type:"object",xml:{name:e}}}};export{o as createPaginationMetaSchemaObject,s as createPaginationSchemaObject};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/pagination",
3
- "version": "5.0.0-alpha.12",
3
+ "version": "5.0.0-alpha.14",
4
4
  "description": "Simple Pagination for Node.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -1 +0,0 @@
1
- var ot=Object.defineProperty;var P=(t,e)=>ot(t,"name",{value:e,configurable:!0});var nt=Object.defineProperty,B=P((t,e)=>nt(t,"name",{value:e,configurable:!0}),"e");const at=String.prototype.replace,lt=/%20/g,W={RFC1738:"RFC1738",RFC3986:"RFC3986"},K={RFC1738:B(function(t){return at.call(t,lt,"+")},"RFC1738"),RFC3986:B(function(t){return String(t)},"RFC3986")},it=W.RFC1738,G=W.RFC3986;var st=Object.defineProperty,d=P((t,e)=>st(t,"name",{value:e,configurable:!0}),"p");const I=Object.prototype.hasOwnProperty,j=Array.isArray,F=new WeakMap;var J=d(function(t,e){return F.set(t,e),t},"markOverflow");function U(t){return F.has(t)}P(U,"isOverflow");d(U,"isOverflow");var z=d(function(t){return F.get(t)},"getMaxIndex"),L=d(function(t,e){F.set(t,e)},"setMaxIndex");const m=(function(){const t=[];for(let e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t})(),ct=d(function(t){for(;t.length>1;){const e=t.pop(),o=e.obj[e.prop];if(j(o)){const r=[];for(let a=0;a<o.length;++a)typeof o[a]<"u"&&r.push(o[a]);e.obj[e.prop]=r}}},"compactQueue"),X=d(function(t,e){const o=e&&e.plainObjects?Object.create(null):{};for(let r=0;r<t.length;++r)typeof t[r]<"u"&&(o[r]=t[r]);return o},"arrayToObject");d(P(function t(e,o,r){if(!o)return e;if(typeof o!="object"){if(j(e))e.push(o);else if(e&&typeof e=="object")if(U(e)){var a=z(e)+1;e[a]=o,L(e,a)}else(r&&(r.plainObjects||r.allowPrototypes)||!I.call(Object.prototype,o))&&(e[o]=!0);else return[e,o];return e}if(!e||typeof e!="object"){if(U(o)){for(var s=Object.keys(o),p=r&&r.plainObjects?{__proto__:null,0:e}:{0:e},u=0;u<s.length;u++){var i=parseInt(s[u],10);p[i+1]=o[s[u]]}return J(p,z(o)+1)}return[e].concat(o)}let c=e;return j(e)&&!j(o)&&(c=X(e,r)),j(e)&&j(o)?(o.forEach(function(n,y){if(I.call(e,y)){const h=e[y];h&&typeof h=="object"&&n&&typeof n=="object"?e[y]=t(h,n,r):e.push(n)}else e[y]=n}),e):Object.keys(o).reduce(function(n,y){const h=o[y];return I.call(n,y)?n[y]=t(n[y],h,r):n[y]=h,n},c)},"f"),"merge");d(function(t,e){return Object.keys(e).reduce(function(o,r){return o[r]=e[r],o},t)},"assignSingleSource");d(function(t){const e=t.replace(/\+/g," ");try{return decodeURIComponent(e)}catch{return e}},"decode");const T=1024,ut=d(function(t,e,o,r){if(t.length===0)return t;let a=t;typeof t=="symbol"?a=Symbol.prototype.toString.call(t):typeof t!="string"&&(a=String(t));let s="";for(let p=0;p<a.length;p+=T){const u=a.length>=T?a.slice(p,p+T):a,i=[];for(let c=0;c<u.length;++c){let n=u.charCodeAt(c);if(n===45||n===46||n===95||n===126||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122||r===it&&(n===40||n===41)){i[i.length]=u.charAt(c);continue}if(n<128){i[i.length]=m[n];continue}if(n<2048){i[i.length]=m[192|n>>6]+m[128|n&63];continue}if(n<55296||n>=57344){i[i.length]=m[224|n>>12]+m[128|n>>6&63]+m[128|n&63];continue}c+=1,n=65536+((n&1023)<<10|u.charCodeAt(c)&1023),i[i.length]=m[240|n>>18]+m[128|n>>12&63]+m[128|n>>6&63]+m[128|n&63]}s+=i.join("")}return s},"encode");d(function(t){const e=[{obj:{o:t},prop:"o"}],o=[];for(let r=0;r<e.length;++r){const a=e[r],s=a.obj[a.prop],p=Object.keys(s);for(let u=0;u<p.length;++u){const i=p[u],c=s[i];typeof c=="object"&&c!==null&&o.indexOf(c)===-1&&(e.push({obj:s,prop:i}),o.push(c))}}return ct(e),t},"compact");d(function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},"isRegExp");const ft=d(function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},"isBuffer");d(function(t,e,o,r){if(U(t)){var a=z(t)+1;return t[a]=e,L(t,a),t}var s=[].concat(t,e);return s.length>o?J(X(s,{plainObjects:r}),s.length-1):s},"combine");const _=d(function(t,e){if(j(t)){const o=[];for(let r=0;r<t.length;r+=1)o.push(e(t[r]));return o}return e(t)},"maybeMap");var pt=Object.defineProperty,w=P((t,e)=>pt(t,"name",{value:e,configurable:!0}),"s");const yt=Object.prototype.hasOwnProperty,Y={brackets:w(function(t){return t+"[]"},"brackets"),comma:"comma",indices:w(function(t,e){return t+"["+e+"]"},"indices"),repeat:w(function(t){return t},"repeat")},b=Array.isArray,gt=Array.prototype.push,Z=w(function(t,e){gt.apply(t,b(e)?e:[e])},"pushToArray"),dt=Date.prototype.toISOString,$=G,f={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:ut,encodeValuesOnly:!1,format:$,formatter:K[$],indices:!1,serializeDate:w(function(t){return dt.call(t)},"serializeDate"),skipNulls:!1,strictNullHandling:!1},ht=w(function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},"isNonNullishPrimitive"),M={},tt=w(function(t,e,o,r,a,s,p,u,i,c,n,y,h,v,E,x,k){let l=t,D=k,N=0,Q=!1;for(;(D=D.get(M))!==void 0&&!Q;){const g=D.get(t);if(N+=1,typeof g<"u"){if(g===N)throw new RangeError("Cyclic object value");Q=!0}typeof D.get(M)>"u"&&(N=0)}if(typeof c=="function"?l=c(e,l):l instanceof Date?l=h(l):o==="comma"&&b(l)&&(l=_(l,function(g){return g instanceof Date?h(g):g})),l===null){if(s)return i&&!x?i(e,f.encoder,"key",v):e;l=""}if(ht(l)||ft(l)){if(i){const g=x?e:i(e,f.encoder,"key",v);return[E(g)+"="+E(i(l,f.encoder,"value",v))]}return[E(e)+"="+E(String(l))]}const C=[];if(typeof l>"u")return C;let R;if(o==="comma"&&b(l))x&&i&&(l=_(l,i)),R=[{value:l.length>0?l.join(",")||null:void 0}];else if(b(c))R=c;else{const g=Object.keys(l);R=n?g.sort(n):g}const H=u?e.replace(/\./g,"%2E"):e,A=r&&b(l)&&l.length===1?H+"[]":H;if(a&&b(l)&&l.length===0)return A+"[]";for(let g=0;g<R.length;++g){const O=R[g],V=typeof O=="object"&&typeof O.value<"u"?O.value:l[O];if(p&&V===null)continue;const S=y&&u?O.replace(/\./g,"%2E"):O,rt=b(l)?typeof o=="function"?o(A,S):A:A+(y?"."+S:"["+S+"]");k.set(t,N);const q=new WeakMap;q.set(M,k),Z(C,tt(V,rt,o,r,a,s,p,u,o==="comma"&&x&&b(l)?null:i,c,n,y,h,v,E,x,q))}return C},"stringify"),mt=w(function(t){if(!t)return f;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.encodeDotInKeys<"u"&&typeof t.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(t.encoder!==null&&typeof t.encoder<"u"&&typeof t.encoder!="function")throw new TypeError("Encoder has to be a function.");let e=G;if(typeof t.format<"u"){if(!yt.call(K,t.format))throw new TypeError("Unknown format option provided.");e=t.format}const o=K[e];let r=f.filter;(typeof t.filter=="function"||b(t.filter))&&(r=t.filter);let a;if(t.arrayFormat in Y?a=t.arrayFormat:"indices"in t?a=t.indices?"indices":"repeat":a=f.arrayFormat,"commaRoundTrip"in t&&typeof t.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const s=typeof t.allowDots>"u"?t.encodeDotInKeys===!0?!0:f.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:f.addQueryPrefix,allowDots:s,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:f.allowEmptyArrays,arrayFormat:a,commaRoundTrip:t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?f.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:f.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:f.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:f.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:f.encodeValuesOnly,filter:r,format:e,formatter:o,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:f.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:f.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:f.strictNullHandling}},"normalizeStringifyOptions");function et(t,e){let o=t;const r=mt(e);let a,s;typeof r.filter=="function"?(s=r.filter,o=s("",o)):b(r.filter)&&(s=r.filter,a=s);const p=[];if(typeof o!="object"||o===null)return"";const u=Y[r.arrayFormat],i=u==="comma"&&r.commaRoundTrip;a||(a=Object.keys(o)),r.sort&&a.sort(r.sort);const c=new WeakMap;for(let h=0;h<a.length;++h){const v=a[h];r.skipNulls&&o[v]===null||Z(p,tt(o[v],v,u,i,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,c))}const n=p.join(r.delimiter),y=r.addQueryPrefix===!0?"?":"";return n.length>0?y+n:""}P(et,"stringify");w(et,"stringify");var bt=Object.defineProperty,Pt=P((t,e)=>bt(t,"name",{value:e,configurable:!0}),"n");class vt extends Array{static{P(this,"g")}constructor(e,o,r,...a){super(...a),this.totalNumber=e,this.perPage=o,this.currentPage=r,this.totalNumber=e,this.rows=a,this.isEmpty=this.rows.length===0}totalNumber;perPage;currentPage;static{Pt(this,"Paginator")}firstPage=1;isEmpty;qs={};rows;url="/";all(){return this.rows}baseUrl(e){return this.url=e,this}getMeta(){return{firstPage:this.firstPage,firstPageUrl:this.getUrl(1),lastPage:this.lastPage,lastPageUrl:this.getUrl(this.lastPage),nextPageUrl:this.getNextPageUrl(),page:this.currentPage,perPage:this.perPage,previousPageUrl:this.getPreviousPageUrl(),total:this.total}}getNextPageUrl(){return this.hasMorePages?this.getUrl(this.currentPage+1):null}getPreviousPageUrl(){return this.currentPage>1?this.getUrl(this.currentPage-1):null}getUrl(e){const o=et({...this.qs,page:Math.max(e,1)});return`${this.url}?${o}`}getUrlsForRange(e,o){const r=[];for(let a=e;a<=o;a++)r.push({isActive:a===this.currentPage,page:a,url:this.getUrl(a)});return r}queryString(e){return this.qs=e,this}toJSON(){return{data:this.all(),meta:this.getMeta()}}get hasMorePages(){return this.lastPage>this.currentPage}get hasPages(){return this.lastPage!==1}get hasTotal(){return this.total>0}get lastPage(){return Math.max(Math.ceil(this.total/this.perPage),1)}get total(){return this.totalNumber}}export{vt as default};
@@ -1 +0,0 @@
1
- var n=Object.defineProperty;var a=(e,t)=>n(e,"name",{value:t,configurable:!0});var o=Object.defineProperty,r=a((e,t)=>o(e,"name",{value:t,configurable:!0}),"r");const s=r((e="PaginationData")=>({[e]:{properties:{firstPage:{description:"Returns the number for the first page. It is always 1",minimum:0,type:"integer"},firstPageUrl:{description:"The URL for the first page",type:"string"},lastPage:{description:"Returns the value for the last page by taking the total of rows into account",minimum:0,type:"integer"},lastPageUrl:{description:"The URL for the last page",type:"string"},nextPageUrl:{description:"The URL for the next page",type:"string"},page:{description:"Current page number",minimum:1,type:"integer"},perPage:{description:"Returns the value for the limit passed to the paginate method",minimum:0,type:"integer"},previousPageUrl:{description:"The URL for the previous page",type:"string"},total:{description:"Holds the value for the total number of rows in the database",minimum:0,type:"integer"}},type:"object",xml:{name:e}}}),"createPaginationMetaSchemaObject"),m=r((e,t,i="#/components/schemas/PaginationData")=>({[e]:{properties:{data:{items:t,type:"array",xml:{name:"data",wrapped:!0}},meta:{$ref:i}},type:"object",xml:{name:e}}}),"createPaginationSchemaObject");export{s as createPaginationMetaSchemaObject,m as createPaginationSchemaObject};