@visulima/pagination 5.0.0-alpha.11 → 5.0.0-alpha.13

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,32 @@
1
+ ## @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)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **pagination:** 3 bug fixes ([bcc5dbf](https://github.com/visulima/visulima/commit/bcc5dbf91aac391b3df1d83d6a1850a7b4bdbcc2))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * apply eslint + prettier autofixes across packages ([c1bb784](https://github.com/visulima/visulima/commit/c1bb7848a0d93d0dfe2960c77e3cda22239c79a0))
10
+
11
+ ## @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)
12
+
13
+ ### Bug Fixes
14
+
15
+ * **storage-client:** percent-encode user fields in defaultFingerprint ([7c78a0f](https://github.com/visulima/visulima/commit/7c78a0f9512e2a673b941d80839e9f1e86b7b5d0))
16
+
17
+ ### Miscellaneous Chores
18
+
19
+ * **ci-stability:** green CI across vis, native, lint, tests, attw ([#651](https://github.com/visulima/visulima/issues/651)) ([d4eb684](https://github.com/visulima/visulima/commit/d4eb684b5f75c818c9251048c605a0ed54a268e3))
20
+ * **pagination:** housekeeping cleanup ([bfd1f8f](https://github.com/visulima/visulima/commit/bfd1f8fb9263481b7bda22f5000c8b5aed49e62e))
21
+ * **pagination:** upgrade packem to 2.0.0-alpha.76 ([443e12d](https://github.com/visulima/visulima/commit/443e12d4f90977f1d807d5d4d73f0bc17c2bd044))
22
+ * re-sort workspace package.json files via vis sort-package-json ([f625696](https://github.com/visulima/visulima/commit/f625696cfac974325774b3243e1a83c3d23acbd7))
23
+ * **repo:** sort package.json keys across all packages ([e1fd9ab](https://github.com/visulima/visulima/commit/e1fd9ab467ef96a98c777da1572ff6a50fcf7e71))
24
+ * sorted package.json ([b47c545](https://github.com/visulima/visulima/commit/b47c545591600fdab17d5cd3a3fbc68b61e199da))
25
+
26
+ ### Tests
27
+
28
+ * **repo:** add dist runtime + types integration tests ([32ee300](https://github.com/visulima/visulima/commit/32ee300b7184117a0ddf9f9d390f75f8932d5ed9))
29
+
1
30
  ## @visulima/pagination [5.0.0-alpha.11](https://github.com/visulima/visulima/compare/@visulima/pagination@5.0.0-alpha.10...@visulima/pagination@5.0.0-alpha.11) (2026-04-22)
2
31
 
3
32
  ### 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/dist/index.d.ts CHANGED
@@ -1,5 +1,137 @@
1
- import type { Paginator as PaginatorInterface } from "./types.d.d.ts";
2
- export { default as Paginator } from "./paginator.d.ts";
3
- export { createPaginationMetaSchemaObject, createPaginationSchemaObject } from "./swagger.d.ts";
4
- export declare const paginate: <Result>(page: number, perPage: number, total: number, rows: Result[]) => PaginatorInterface<Result>;
5
- export type { PaginationMeta, PaginationResult, Paginator as PaginatorInterface } from "./types.d.ts";
1
+ import { OpenAPIV3 } from 'openapi-types';
2
+ interface PaginationMeta {
3
+ firstPage: number;
4
+ firstPageUrl: string | null;
5
+ lastPage: number;
6
+ lastPageUrl: string | null;
7
+ nextPageUrl: string | null;
8
+ page: number;
9
+ perPage: number;
10
+ previousPageUrl: string | null;
11
+ total: number;
12
+ }
13
+ interface PaginationResult<Result> {
14
+ data: Result[];
15
+ meta: PaginationMeta;
16
+ }
17
+ interface Paginator$1<Result> extends Array<Result> {
18
+ all: () => Result[];
19
+ baseUrl: (url: string) => this;
20
+ readonly currentPage: number;
21
+ readonly firstPage: number;
22
+ getMeta: () => PaginationMeta;
23
+ getNextPageUrl: () => string | null;
24
+ getPreviousPageUrl: () => string | null;
25
+ getUrl: (page: number) => string;
26
+ getUrlsForRange: (start: number, end: number) => {
27
+ isActive: boolean;
28
+ page: number;
29
+ url: string;
30
+ }[];
31
+ readonly hasMorePages: boolean;
32
+ readonly hasPages: boolean;
33
+ readonly hasTotal: boolean;
34
+ readonly isEmpty: boolean;
35
+ readonly lastPage: number;
36
+ readonly perPage: number;
37
+ queryString: (values: Record<string, unknown>) => this;
38
+ toJSON: () => PaginationResult<Result>;
39
+ readonly total: number;
40
+ }
41
+ type UrlsForRange = {
42
+ isActive: boolean;
43
+ page: number;
44
+ url: string;
45
+ }[];
46
+ /**
47
+ * Simple paginator works with the data set provided by the standard
48
+ * `offset` and `limit` based pagination.
49
+ */
50
+ declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T> {
51
+ private readonly totalNumber;
52
+ readonly perPage: number;
53
+ currentPage: number;
54
+ /**
55
+ * Ensure inherited Array methods (map/filter/slice/...) return plain Arrays
56
+ * instead of partially-constructed Paginator instances.
57
+ */
58
+ static override get [Symbol.species](): ArrayConstructor;
59
+ /**
60
+ * The first page is always 1
61
+ */
62
+ readonly firstPage: number;
63
+ /**
64
+ * Find if results set is empty or not
65
+ */
66
+ readonly isEmpty: boolean;
67
+ private qs;
68
+ private readonly rows;
69
+ private url;
70
+ constructor(totalNumber: number, perPage: number, currentPage: number, ...rows: T[]);
71
+ /**
72
+ * A reference to the result rows.
73
+ */
74
+ all(): T[];
75
+ /**
76
+ * Define base url for making the pagination links.
77
+ */
78
+ baseUrl(url: string): this;
79
+ /**
80
+ * Returns JSON meta data.
81
+ */
82
+ getMeta(): PaginationMeta;
83
+ /**
84
+ * Returns url for the next page.
85
+ */
86
+ getNextPageUrl(): string | null;
87
+ /**
88
+ * Returns URL for the previous page.
89
+ */
90
+ getPreviousPageUrl(): string | null;
91
+ /**
92
+ * Returns url for a given page. Doesn't validate the integrity of the
93
+ * page.
94
+ */
95
+ getUrl(page: number): string;
96
+ /**
97
+ * Returns an array of urls under a given range.
98
+ */
99
+ getUrlsForRange(start: number, end: number): UrlsForRange;
100
+ /**
101
+ * Define query string to be appended to the pagination links.
102
+ */
103
+ queryString(values: Record<string, unknown>): this;
104
+ /**
105
+ * Returns JSON representation of the paginated data.
106
+ */
107
+ toJSON(): PaginationResult<T>;
108
+ /**
109
+ * Find if there are more pages to come.
110
+ */
111
+ get hasMorePages(): boolean;
112
+ /**
113
+ * Find if there are enough results to be paginated or not.
114
+ */
115
+ get hasPages(): boolean;
116
+ /**
117
+ * Find if there are total records or not. This is not same as
118
+ * `isEmpty`.
119
+ *
120
+ * The `isEmpty` reports about the current set of results. However, `hasTotal`
121
+ * reports about the total number of records, regardless of the current.
122
+ */
123
+ get hasTotal(): boolean;
124
+ /**
125
+ * The Last page number.
126
+ */
127
+ get lastPage(): number;
128
+ /**
129
+ * Casting `total` to a number. Later, we can think of situations
130
+ * to cast it to a bigint.
131
+ */
132
+ get total(): number;
133
+ }
134
+ declare const createPaginationMetaSchemaObject: (name?: string) => Record<string, OpenAPIV3.SchemaObject>;
135
+ declare const createPaginationSchemaObject: (name: string, items: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, metaReference?: string) => Record<string, OpenAPIV3.SchemaObject>;
136
+ declare const paginate: <Result>(page: number, perPage: number, total: number, rows: Result[]) => Paginator$1<Result>;
137
+ export { type PaginationMeta, type PaginationResult, Paginator, type Paginator$1 as PaginatorInterface, createPaginationMetaSchemaObject, createPaginationSchemaObject, paginate };
package/dist/index.js CHANGED
@@ -1,6 +1 @@
1
- import Paginator from './packem_shared/Paginator-D40bQfqD.js';
2
- export { createPaginationMetaSchemaObject, createPaginationSchemaObject } from './packem_shared/createPaginationMetaSchemaObject-AoC1C8S-.js';
3
-
4
- const paginate = (page, perPage, total, rows) => new Paginator(total, perPage, page, ...rows);
5
-
6
- export { Paginator, paginate };
1
+ var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});import i from"./packem_shared/Paginator-BVAelAiS.js";import{createPaginationMetaSchemaObject as P,createPaginationSchemaObject as j}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,P as createPaginationMetaSchemaObject,j as createPaginationSchemaObject,b as paginate};
@@ -0,0 +1 @@
1
+ var g=Object.defineProperty;var i=(a,t)=>g(a,"name",{value:t,configurable:!0});var l=Object.defineProperty,h=i((a,t)=>l(a,"name",{value:t,configurable:!0}),"n");class u extends Array{static{i(this,"u")}constructor(t,r,s,...e){super(),this.totalNumber=t,this.perPage=r,this.currentPage=s,this.push(...e),this.totalNumber=t,this.rows=e,this.isEmpty=this.rows.length===0}totalNumber;perPage;currentPage;static{h(this,"Paginator")}static get[Symbol.species](){return Array}firstPage=1;isEmpty;qs={};rows;url="/";all(){return this.rows}baseUrl(t){return this.url=t,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(t){const r=new URLSearchParams;for(const[s,e]of Object.entries(this.qs))e!=null&&r.append(s,String(e));return r.append("page",String(Math.max(t,1))),`${this.url}?${r.toString()}`}getUrlsForRange(t,r){const s=[];for(let e=t;e<=r;e++)s.push({isActive:e===this.currentPage,page:e,url:this.getUrl(e)});return s}queryString(t){return this.qs=t,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(){const t=this.perPage>0?this.perPage:1;return Math.max(Math.ceil(this.total/t),1)}get total(){return this.totalNumber}}export{u as default};
@@ -0,0 +1 @@
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};
package/package.json CHANGED
@@ -1,21 +1,19 @@
1
1
  {
2
2
  "name": "@visulima/pagination",
3
- "version": "5.0.0-alpha.11",
3
+ "version": "5.0.0-alpha.13",
4
4
  "description": "Simple Pagination for Node.",
5
5
  "keywords": [
6
6
  "anolilab",
7
- "visulima",
8
- "pagination",
9
- "paginator",
10
- "offset",
11
7
  "limit",
8
+ "offset",
12
9
  "page",
13
- "paging"
10
+ "pagination",
11
+ "paginator",
12
+ "paging",
13
+ "visulima"
14
14
  ],
15
15
  "homepage": "https://visulima.com/packages/pagination/",
16
- "bugs": {
17
- "url": "https://github.com/visulima/visulima/issues"
18
- },
16
+ "bugs": "https://github.com/visulima/visulima/issues",
19
17
  "repository": {
20
18
  "type": "git",
21
19
  "url": "git+https://github.com/visulima/visulima.git",
@@ -1,442 +0,0 @@
1
- const replace = String.prototype.replace;
2
- const percentTwenties = /%20/g;
3
- const Format = {
4
- RFC1738: "RFC1738",
5
- RFC3986: "RFC3986"
6
- };
7
- const formatters = {
8
- RFC1738: function(value) {
9
- return replace.call(value, percentTwenties, "+");
10
- },
11
- RFC3986: function(value) {
12
- return String(value);
13
- }
14
- };
15
- const RFC1738 = Format.RFC1738;
16
- const formats = Format.RFC3986;
17
-
18
- const isArray$1 = Array.isArray;
19
- const hexTable = (function() {
20
- const array = [];
21
- for (let i = 0; i < 256; ++i) {
22
- array.push("%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase());
23
- }
24
- return array;
25
- })();
26
- const limit = 1024;
27
- const encode = function encode2(str, _defaultEncoder, _kind, format) {
28
- if (str.length === 0) {
29
- return str;
30
- }
31
- let string = str;
32
- if (typeof str === "symbol") {
33
- string = Symbol.prototype.toString.call(str);
34
- } else if (typeof str !== "string") {
35
- string = String(str);
36
- }
37
- let out = "";
38
- for (let j = 0; j < string.length; j += limit) {
39
- const segment = string.length >= limit ? string.slice(j, j + limit) : string;
40
- const arr = [];
41
- for (let i = 0; i < segment.length; ++i) {
42
- let c = segment.charCodeAt(i);
43
- if (c === 45 || // -
44
- c === 46 || // .
45
- c === 95 || // _
46
- c === 126 || // ~
47
- c >= 48 && c <= 57 || // 0-9
48
- c >= 65 && c <= 90 || // a-z
49
- c >= 97 && c <= 122 || // A-Z
50
- format === RFC1738 && (c === 40 || c === 41)) {
51
- arr[arr.length] = segment.charAt(i);
52
- continue;
53
- }
54
- if (c < 128) {
55
- arr[arr.length] = hexTable[c];
56
- continue;
57
- }
58
- if (c < 2048) {
59
- arr[arr.length] = hexTable[192 | c >> 6] + hexTable[128 | c & 63];
60
- continue;
61
- }
62
- if (c < 55296 || c >= 57344) {
63
- arr[arr.length] = hexTable[224 | c >> 12] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
64
- continue;
65
- }
66
- i += 1;
67
- c = 65536 + ((c & 1023) << 10 | segment.charCodeAt(i) & 1023);
68
- arr[arr.length] = hexTable[240 | c >> 18] + hexTable[128 | c >> 12 & 63] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
69
- }
70
- out += arr.join("");
71
- }
72
- return out;
73
- };
74
- const isBuffer = function isBuffer2(obj) {
75
- if (!obj || typeof obj !== "object") {
76
- return false;
77
- }
78
- return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
79
- };
80
- const maybeMap = function maybeMap2(val, fn) {
81
- if (isArray$1(val)) {
82
- const mapped = [];
83
- for (let i = 0; i < val.length; i += 1) {
84
- mapped.push(fn(val[i]));
85
- }
86
- return mapped;
87
- }
88
- return fn(val);
89
- };
90
-
91
- const arrayPrefixGenerators = {
92
- brackets: function brackets(prefix) {
93
- return prefix + "[]";
94
- },
95
- comma: "comma",
96
- indices: function indices(prefix, key) {
97
- return prefix + "[" + key + "]";
98
- },
99
- repeat: function repeat(prefix) {
100
- return prefix;
101
- }
102
- };
103
- const isArray = Array.isArray;
104
- const push = Array.prototype.push;
105
- const pushToArray = function(arr, valueOrArray) {
106
- push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
107
- };
108
- const toISO = Date.prototype.toISOString;
109
- const defaultFormat = formats;
110
- const defaults = {
111
- addQueryPrefix: false,
112
- allowDots: false,
113
- allowEmptyArrays: false,
114
- arrayFormat: "indices",
115
- delimiter: "&",
116
- encode: true,
117
- encodeDotInKeys: false,
118
- encoder: encode,
119
- encodeValuesOnly: false,
120
- format: defaultFormat,
121
- formatter: formatters[defaultFormat],
122
- // deprecated
123
- indices: false,
124
- serializeDate: function serializeDate(date) {
125
- return toISO.call(date);
126
- },
127
- skipNulls: false,
128
- strictNullHandling: false
129
- };
130
- const isNonNullishPrimitive = function isNonNullishPrimitive2(v) {
131
- return typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "bigint";
132
- };
133
- const sentinel = {};
134
- const _stringify = function stringify2(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate2, format, formatter, encodeValuesOnly, sideChannel) {
135
- let obj = object;
136
- let tmpSc = sideChannel;
137
- let step = 0;
138
- let findFlag = false;
139
- while ((tmpSc = tmpSc.get(sentinel)) !== void 0 && !findFlag) {
140
- const pos = tmpSc.get(object);
141
- step += 1;
142
- if (typeof pos !== "undefined") {
143
- if (pos === step) {
144
- throw new RangeError("Cyclic object value");
145
- } else {
146
- findFlag = true;
147
- }
148
- }
149
- if (typeof tmpSc.get(sentinel) === "undefined") {
150
- step = 0;
151
- }
152
- }
153
- if (typeof filter === "function") {
154
- obj = filter(prefix, obj);
155
- } else if (obj instanceof Date) {
156
- obj = serializeDate2(obj);
157
- } else if (generateArrayPrefix === "comma" && isArray(obj)) {
158
- obj = maybeMap(obj, function(value) {
159
- if (value instanceof Date) {
160
- return serializeDate2(value);
161
- }
162
- return value;
163
- });
164
- }
165
- if (obj === null) {
166
- if (strictNullHandling) {
167
- return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, "key", format) : prefix;
168
- }
169
- obj = "";
170
- }
171
- if (isNonNullishPrimitive(obj) || isBuffer(obj)) {
172
- if (encoder) {
173
- const keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, "key", format);
174
- return [
175
- formatter(keyValue) + "=" + formatter(encoder(obj, defaults.encoder, "value", format))
176
- ];
177
- }
178
- return [formatter(prefix) + "=" + formatter(String(obj))];
179
- }
180
- const values = [];
181
- if (typeof obj === "undefined") {
182
- return values;
183
- }
184
- let objKeys;
185
- if (generateArrayPrefix === "comma" && isArray(obj)) {
186
- if (encodeValuesOnly && encoder) {
187
- obj = maybeMap(obj, encoder);
188
- }
189
- objKeys = [{ value: obj.length > 0 ? obj.join(",") || null : void 0 }];
190
- } else if (isArray(filter)) {
191
- objKeys = filter;
192
- } else {
193
- const keys = Object.keys(obj);
194
- objKeys = sort ? keys.sort(sort) : keys;
195
- }
196
- const encodedPrefix = encodeDotInKeys ? prefix.replace(/\./g, "%2E") : prefix;
197
- const adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + "[]" : encodedPrefix;
198
- if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
199
- return adjustedPrefix + "[]";
200
- }
201
- for (let j = 0; j < objKeys.length; ++j) {
202
- const key = objKeys[j];
203
- const value = typeof key === "object" && typeof key.value !== "undefined" ? key.value : obj[key];
204
- if (skipNulls && value === null) {
205
- continue;
206
- }
207
- const encodedKey = allowDots && encodeDotInKeys ? key.replace(/\./g, "%2E") : key;
208
- const keyPrefix = isArray(obj) ? typeof generateArrayPrefix === "function" ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix : adjustedPrefix + (allowDots ? "." + encodedKey : "[" + encodedKey + "]");
209
- sideChannel.set(object, step);
210
- const valueSideChannel = /* @__PURE__ */ new WeakMap();
211
- valueSideChannel.set(sentinel, sideChannel);
212
- pushToArray(
213
- values,
214
- _stringify(
215
- value,
216
- keyPrefix,
217
- generateArrayPrefix,
218
- commaRoundTrip,
219
- allowEmptyArrays,
220
- strictNullHandling,
221
- skipNulls,
222
- encodeDotInKeys,
223
- generateArrayPrefix === "comma" && encodeValuesOnly && isArray(obj) ? null : encoder,
224
- filter,
225
- sort,
226
- allowDots,
227
- serializeDate2,
228
- format,
229
- formatter,
230
- encodeValuesOnly,
231
- valueSideChannel
232
- )
233
- );
234
- }
235
- return values;
236
- };
237
- const normalizeStringifyOptions = function normalizeStringifyOptions2(opts) {
238
- {
239
- return defaults;
240
- }
241
- };
242
- function stringify(object, opts) {
243
- let obj = object;
244
- const options = normalizeStringifyOptions();
245
- let objKeys;
246
- let filter;
247
- if (typeof options.filter === "function") {
248
- filter = options.filter;
249
- obj = filter("", obj);
250
- } else if (isArray(options.filter)) {
251
- filter = options.filter;
252
- objKeys = filter;
253
- }
254
- const keys = [];
255
- if (typeof obj !== "object" || obj === null) {
256
- return "";
257
- }
258
- const generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
259
- const commaRoundTrip = generateArrayPrefix === "comma" && options.commaRoundTrip;
260
- if (!objKeys) {
261
- objKeys = Object.keys(obj);
262
- }
263
- if (options.sort) {
264
- objKeys.sort(options.sort);
265
- }
266
- const sideChannel = /* @__PURE__ */ new WeakMap();
267
- for (let i = 0; i < objKeys.length; ++i) {
268
- const key = objKeys[i];
269
- if (options.skipNulls && obj[key] === null) {
270
- continue;
271
- }
272
- pushToArray(
273
- keys,
274
- _stringify(
275
- obj[key],
276
- key,
277
- generateArrayPrefix,
278
- commaRoundTrip,
279
- options.allowEmptyArrays,
280
- options.strictNullHandling,
281
- options.skipNulls,
282
- options.encodeDotInKeys,
283
- options.encode ? options.encoder : null,
284
- options.filter,
285
- options.sort,
286
- options.allowDots,
287
- options.serializeDate,
288
- options.format,
289
- options.formatter,
290
- options.encodeValuesOnly,
291
- sideChannel
292
- )
293
- );
294
- }
295
- const joined = keys.join(options.delimiter);
296
- const prefix = options.addQueryPrefix === true ? "?" : "";
297
- return joined.length > 0 ? prefix + joined : "";
298
- }
299
-
300
- class Paginator extends Array {
301
- constructor(totalNumber, perPage, currentPage, ...rows) {
302
- super(...rows);
303
- this.totalNumber = totalNumber;
304
- this.perPage = perPage;
305
- this.currentPage = currentPage;
306
- this.totalNumber = totalNumber;
307
- this.rows = rows;
308
- this.isEmpty = this.rows.length === 0;
309
- }
310
- totalNumber;
311
- perPage;
312
- currentPage;
313
- /**
314
- * The first page is always 1
315
- */
316
- firstPage = 1;
317
- /**
318
- * Find if results set is empty or not
319
- */
320
- isEmpty;
321
- qs = {};
322
- rows;
323
- url = "/";
324
- /**
325
- * A reference to the result rows.
326
- */
327
- all() {
328
- return this.rows;
329
- }
330
- /**
331
- * Define base url for making the pagination links.
332
- */
333
- baseUrl(url) {
334
- this.url = url;
335
- return this;
336
- }
337
- /**
338
- * Returns JSON meta data.
339
- */
340
- getMeta() {
341
- return {
342
- firstPage: this.firstPage,
343
- firstPageUrl: this.getUrl(1),
344
- lastPage: this.lastPage,
345
- lastPageUrl: this.getUrl(this.lastPage),
346
- nextPageUrl: this.getNextPageUrl(),
347
- page: this.currentPage,
348
- perPage: this.perPage,
349
- previousPageUrl: this.getPreviousPageUrl(),
350
- total: this.total
351
- };
352
- }
353
- /**
354
- * Returns url for the next page.
355
- */
356
- getNextPageUrl() {
357
- if (this.hasMorePages) {
358
- return this.getUrl(this.currentPage + 1);
359
- }
360
- return null;
361
- }
362
- /**
363
- * Returns URL for the previous page.
364
- */
365
- getPreviousPageUrl() {
366
- if (this.currentPage > 1) {
367
- return this.getUrl(this.currentPage - 1);
368
- }
369
- return null;
370
- }
371
- /**
372
- * Returns url for a given page. Doesn't validate the integrity of the
373
- * page.
374
- */
375
- getUrl(page) {
376
- const qstring = stringify({ ...this.qs, page: Math.max(page, 1) });
377
- return `${this.url}?${qstring}`;
378
- }
379
- /**
380
- * Returns an array of urls under a given range.
381
- */
382
- getUrlsForRange(start, end) {
383
- const urls = [];
384
- for (let index = start; index <= end; index++) {
385
- urls.push({ isActive: index === this.currentPage, page: index, url: this.getUrl(index) });
386
- }
387
- return urls;
388
- }
389
- /**
390
- * Define query string to be appended to the pagination links.
391
- */
392
- queryString(values) {
393
- this.qs = values;
394
- return this;
395
- }
396
- /**
397
- * Returns JSON representation of the paginated data.
398
- */
399
- toJSON() {
400
- return {
401
- data: this.all(),
402
- meta: this.getMeta()
403
- };
404
- }
405
- /**
406
- * Find if there are more pages to come.
407
- */
408
- get hasMorePages() {
409
- return this.lastPage > this.currentPage;
410
- }
411
- /**
412
- * Find if there are enough results to be paginated or not.
413
- */
414
- get hasPages() {
415
- return this.lastPage !== 1;
416
- }
417
- /**
418
- * Find if there are total records or not. This is not same as
419
- * `isEmpty`.
420
- *
421
- * The `isEmpty` reports about the current set of results. However, `hasTotal`
422
- * reports about the total number of records, regardless of the current.
423
- */
424
- get hasTotal() {
425
- return this.total > 0;
426
- }
427
- /**
428
- * The Last page number.
429
- */
430
- get lastPage() {
431
- return Math.max(Math.ceil(this.total / this.perPage), 1);
432
- }
433
- /**
434
- * Casting `total` to a number. Later, we can think of situations
435
- * to cast it to a bigint.
436
- */
437
- get total() {
438
- return this.totalNumber;
439
- }
440
- }
441
-
442
- export { Paginator as default };
@@ -1,78 +0,0 @@
1
- const createPaginationMetaSchemaObject = (name = "PaginationData") => {
2
- return {
3
- [name]: {
4
- properties: {
5
- firstPage: {
6
- description: "Returns the number for the first page. It is always 1",
7
- minimum: 0,
8
- type: "integer"
9
- },
10
- firstPageUrl: {
11
- description: "The URL for the first page",
12
- type: "string"
13
- },
14
- lastPage: {
15
- description: "Returns the value for the last page by taking the total of rows into account",
16
- minimum: 0,
17
- type: "integer"
18
- },
19
- lastPageUrl: {
20
- description: "The URL for the last page",
21
- type: "string"
22
- },
23
- nextPageUrl: {
24
- description: "The URL for the next page",
25
- type: "string"
26
- },
27
- page: {
28
- description: "Current page number",
29
- minimum: 1,
30
- type: "integer"
31
- },
32
- perPage: {
33
- description: "Returns the value for the limit passed to the paginate method",
34
- minimum: 0,
35
- type: "integer"
36
- },
37
- previousPageUrl: {
38
- description: "The URL for the previous page",
39
- type: "string"
40
- },
41
- total: {
42
- description: "Holds the value for the total number of rows in the database",
43
- minimum: 0,
44
- type: "integer"
45
- }
46
- },
47
- type: "object",
48
- xml: {
49
- name
50
- }
51
- }
52
- };
53
- };
54
- const createPaginationSchemaObject = (name, items, metaReference = "#/components/schemas/PaginationData") => {
55
- return {
56
- [name]: {
57
- properties: {
58
- data: {
59
- items,
60
- type: "array",
61
- xml: {
62
- name: "data",
63
- wrapped: true
64
- }
65
- },
66
- meta: {
67
- $ref: metaReference
68
- }
69
- },
70
- type: "object",
71
- xml: {
72
- name
73
- }
74
- }
75
- };
76
- };
77
-
78
- export { createPaginationMetaSchemaObject, createPaginationSchemaObject };
@@ -1,90 +0,0 @@
1
- import type { PaginationMeta, PaginationResult, Paginator as IPaginator } from "./types.d.d.ts";
2
- type UrlsForRange = {
3
- isActive: boolean;
4
- page: number;
5
- url: string;
6
- }[];
7
- /**
8
- * Simple paginator works with the data set provided by the standard
9
- * `offset` and `limit` based pagination.
10
- */
11
- export default class Paginator<T = unknown> extends Array<T> implements IPaginator<T> {
12
- private readonly totalNumber;
13
- readonly perPage: number;
14
- currentPage: number;
15
- /**
16
- * The first page is always 1
17
- */
18
- readonly firstPage: number;
19
- /**
20
- * Find if results set is empty or not
21
- */
22
- readonly isEmpty: boolean;
23
- private qs;
24
- private readonly rows;
25
- private url;
26
- constructor(totalNumber: number, perPage: number, currentPage: number, ...rows: T[]);
27
- /**
28
- * A reference to the result rows.
29
- */
30
- all(): T[];
31
- /**
32
- * Define base url for making the pagination links.
33
- */
34
- baseUrl(url: string): this;
35
- /**
36
- * Returns JSON meta data.
37
- */
38
- getMeta(): PaginationMeta;
39
- /**
40
- * Returns url for the next page.
41
- */
42
- getNextPageUrl(): string | null;
43
- /**
44
- * Returns URL for the previous page.
45
- */
46
- getPreviousPageUrl(): string | null;
47
- /**
48
- * Returns url for a given page. Doesn't validate the integrity of the
49
- * page.
50
- */
51
- getUrl(page: number): string;
52
- /**
53
- * Returns an array of urls under a given range.
54
- */
55
- getUrlsForRange(start: number, end: number): UrlsForRange;
56
- /**
57
- * Define query string to be appended to the pagination links.
58
- */
59
- queryString(values: Record<string, unknown>): this;
60
- /**
61
- * Returns JSON representation of the paginated data.
62
- */
63
- toJSON(): PaginationResult<T>;
64
- /**
65
- * Find if there are more pages to come.
66
- */
67
- get hasMorePages(): boolean;
68
- /**
69
- * Find if there are enough results to be paginated or not.
70
- */
71
- get hasPages(): boolean;
72
- /**
73
- * Find if there are total records or not. This is not same as
74
- * `isEmpty`.
75
- *
76
- * The `isEmpty` reports about the current set of results. However, `hasTotal`
77
- * reports about the total number of records, regardless of the current.
78
- */
79
- get hasTotal(): boolean;
80
- /**
81
- * The Last page number.
82
- */
83
- get lastPage(): number;
84
- /**
85
- * Casting `total` to a number. Later, we can think of situations
86
- * to cast it to a bigint.
87
- */
88
- get total(): number;
89
- }
90
- export {};
package/dist/swagger.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { OpenAPIV3 } from "openapi-types";
2
- export declare const createPaginationMetaSchemaObject: (name?: string) => Record<string, OpenAPIV3.SchemaObject>;
3
- export declare const createPaginationSchemaObject: (name: string, items: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, metaReference?: string) => Record<string, OpenAPIV3.SchemaObject>;