@visulima/pagination 5.0.0-alpha.10 → 5.0.0-alpha.12
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 +30 -0
- package/dist/index.d.ts +132 -5
- package/dist/index.js +1 -6
- package/dist/packem_shared/Paginator-Dj-l47Lc.js +1 -0
- package/dist/packem_shared/createPaginationMetaSchemaObject-DGZPqai2.js +1 -0
- package/package.json +8 -10
- package/dist/packem_shared/Paginator-D40bQfqD.js +0 -442
- package/dist/packem_shared/createPaginationMetaSchemaObject-AoC1C8S-.js +0 -78
- package/dist/paginator.d.ts +0 -90
- package/dist/swagger.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## @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
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **storage-client:** percent-encode user fields in defaultFingerprint ([7c78a0f](https://github.com/visulima/visulima/commit/7c78a0f9512e2a673b941d80839e9f1e86b7b5d0))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* **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))
|
|
10
|
+
* **pagination:** housekeeping cleanup ([bfd1f8f](https://github.com/visulima/visulima/commit/bfd1f8fb9263481b7bda22f5000c8b5aed49e62e))
|
|
11
|
+
* **pagination:** upgrade packem to 2.0.0-alpha.76 ([443e12d](https://github.com/visulima/visulima/commit/443e12d4f90977f1d807d5d4d73f0bc17c2bd044))
|
|
12
|
+
* re-sort workspace package.json files via vis sort-package-json ([f625696](https://github.com/visulima/visulima/commit/f625696cfac974325774b3243e1a83c3d23acbd7))
|
|
13
|
+
* **repo:** sort package.json keys across all packages ([e1fd9ab](https://github.com/visulima/visulima/commit/e1fd9ab467ef96a98c777da1572ff6a50fcf7e71))
|
|
14
|
+
* sorted package.json ([b47c545](https://github.com/visulima/visulima/commit/b47c545591600fdab17d5cd3a3fbc68b61e199da))
|
|
15
|
+
|
|
16
|
+
### Tests
|
|
17
|
+
|
|
18
|
+
* **repo:** add dist runtime + types integration tests ([32ee300](https://github.com/visulima/visulima/commit/32ee300b7184117a0ddf9f9d390f75f8932d5ed9))
|
|
19
|
+
|
|
20
|
+
## @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)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* Remove JSR configuration generation script and generated jsr.json files ([#616](https://github.com/visulima/visulima/issues/616)) ([533744b](https://github.com/visulima/visulima/commit/533744b103b74896941db5b727173e617a27a63b))
|
|
25
|
+
|
|
26
|
+
### Miscellaneous Chores
|
|
27
|
+
|
|
28
|
+
* bump engines.node to ^22.14.0 || >=24.10.0 ([c3d0931](https://github.com/visulima/visulima/commit/c3d0931d1504e4f21ebf50ea680cfa7ce4ba15ce))
|
|
29
|
+
* fixed jsr.json ([5d85e51](https://github.com/visulima/visulima/commit/5d85e5179de38e284ec433b14d77c71a1619c8d6))
|
|
30
|
+
|
|
1
31
|
## @visulima/pagination [5.0.0-alpha.10](https://github.com/visulima/visulima/compare/@visulima/pagination@5.0.0-alpha.9...@visulima/pagination@5.0.0-alpha.10) (2026-04-15)
|
|
2
32
|
|
|
3
33
|
### Bug Fixes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,132 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
* The first page is always 1
|
|
56
|
+
*/
|
|
57
|
+
readonly firstPage: number;
|
|
58
|
+
/**
|
|
59
|
+
* Find if results set is empty or not
|
|
60
|
+
*/
|
|
61
|
+
readonly isEmpty: boolean;
|
|
62
|
+
private qs;
|
|
63
|
+
private readonly rows;
|
|
64
|
+
private url;
|
|
65
|
+
constructor(totalNumber: number, perPage: number, currentPage: number, ...rows: T[]);
|
|
66
|
+
/**
|
|
67
|
+
* A reference to the result rows.
|
|
68
|
+
*/
|
|
69
|
+
all(): T[];
|
|
70
|
+
/**
|
|
71
|
+
* Define base url for making the pagination links.
|
|
72
|
+
*/
|
|
73
|
+
baseUrl(url: string): this;
|
|
74
|
+
/**
|
|
75
|
+
* Returns JSON meta data.
|
|
76
|
+
*/
|
|
77
|
+
getMeta(): PaginationMeta;
|
|
78
|
+
/**
|
|
79
|
+
* Returns url for the next page.
|
|
80
|
+
*/
|
|
81
|
+
getNextPageUrl(): string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Returns URL for the previous page.
|
|
84
|
+
*/
|
|
85
|
+
getPreviousPageUrl(): string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Returns url for a given page. Doesn't validate the integrity of the
|
|
88
|
+
* page.
|
|
89
|
+
*/
|
|
90
|
+
getUrl(page: number): string;
|
|
91
|
+
/**
|
|
92
|
+
* Returns an array of urls under a given range.
|
|
93
|
+
*/
|
|
94
|
+
getUrlsForRange(start: number, end: number): UrlsForRange;
|
|
95
|
+
/**
|
|
96
|
+
* Define query string to be appended to the pagination links.
|
|
97
|
+
*/
|
|
98
|
+
queryString(values: Record<string, unknown>): this;
|
|
99
|
+
/**
|
|
100
|
+
* Returns JSON representation of the paginated data.
|
|
101
|
+
*/
|
|
102
|
+
toJSON(): PaginationResult<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Find if there are more pages to come.
|
|
105
|
+
*/
|
|
106
|
+
get hasMorePages(): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Find if there are enough results to be paginated or not.
|
|
109
|
+
*/
|
|
110
|
+
get hasPages(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Find if there are total records or not. This is not same as
|
|
113
|
+
* `isEmpty`.
|
|
114
|
+
*
|
|
115
|
+
* The `isEmpty` reports about the current set of results. However, `hasTotal`
|
|
116
|
+
* reports about the total number of records, regardless of the current.
|
|
117
|
+
*/
|
|
118
|
+
get hasTotal(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The Last page number.
|
|
121
|
+
*/
|
|
122
|
+
get lastPage(): number;
|
|
123
|
+
/**
|
|
124
|
+
* Casting `total` to a number. Later, we can think of situations
|
|
125
|
+
* to cast it to a bigint.
|
|
126
|
+
*/
|
|
127
|
+
get total(): number;
|
|
128
|
+
}
|
|
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>;
|
|
131
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
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-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};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -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.
|
|
3
|
+
"version": "5.0.0-alpha.12",
|
|
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
|
-
"
|
|
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",
|
|
@@ -52,7 +50,7 @@
|
|
|
52
50
|
"LICENSE.md"
|
|
53
51
|
],
|
|
54
52
|
"engines": {
|
|
55
|
-
"node": "
|
|
53
|
+
"node": "^22.14.0 || >=24.10.0"
|
|
56
54
|
},
|
|
57
55
|
"os": [
|
|
58
56
|
"darwin",
|
|
@@ -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 };
|
package/dist/paginator.d.ts
DELETED
|
@@ -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>;
|