@visulima/pagination 4.0.1 → 4.0.3

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,24 @@
1
+ ## @visulima/pagination [4.0.3](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.2...@visulima/pagination@4.0.3) (2025-11-07)
2
+
3
+ ### Bug Fixes
4
+
5
+ * update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
10
+
11
+ ## @visulima/pagination [4.0.2](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.1...@visulima/pagination@4.0.2) (2025-11-05)
12
+
13
+ ### Bug Fixes
14
+
15
+ * update dependencies across multiple packages ([36a47f2](https://github.com/visulima/visulima/commit/36a47f26d65d25a7b4d8371186710e7d0ab61a2b))
16
+
17
+ ### Miscellaneous Chores
18
+
19
+ * update dependencies across multiple packages ([c526462](https://github.com/visulima/visulima/commit/c52646260c2ae8bbf85692e642f305f47a158d4e))
20
+ * update package dependencies and configurations ([7bfe7e7](https://github.com/visulima/visulima/commit/7bfe7e71869580900aab50efb064b4293994ed9a))
21
+
1
22
  ## @visulima/pagination [4.0.1](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.0...@visulima/pagination@4.0.1) (2025-10-21)
2
23
 
3
24
  ### Bug Fixes
@@ -22,7 +43,7 @@
22
43
 
23
44
  ### Bug Fixes
24
45
 
25
- * update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
46
+ * update @visulima/packem to 2.0.0-alpha.32 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
26
47
 
27
48
  ### Styles
28
49
 
package/dist/index.js CHANGED
@@ -1 +1,6 @@
1
- var o=Object.defineProperty;var t=(e,a)=>o(e,"name",{value:a,configurable:!0});import i from"./packem_shared/Paginator-qLvq_0YE.js";import{createPaginationMetaSchemaObject as P,createPaginationSchemaObject as j}from"./packem_shared/createPaginationMetaSchemaObject-DGZPqai2.js";var c=Object.defineProperty,m=t((e,a)=>c(e,"name",{value:a,configurable:!0}),"e");const p=m((e,a,r,n)=>new i(r,Number(a),Number(e),...n),"paginate");export{i as Paginator,P as createPaginationMetaSchemaObject,j as createPaginationSchemaObject,p as paginate};
1
+ import Paginator from './packem_shared/Paginator-B3QHCcfB.js';
2
+ export { createPaginationMetaSchemaObject, createPaginationSchemaObject } from './packem_shared/createPaginationMetaSchemaObject-AoC1C8S-.js';
3
+
4
+ const paginate = (page, perPage, total, rows) => new Paginator(total, Number(perPage), Number(page), ...rows);
5
+
6
+ export { Paginator, paginate };
@@ -0,0 +1,455 @@
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, charset, 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
+ if (charset === "iso-8859-1") {
38
+ return escape(string).replace(/%u[0-9a-f]{4}/gi, function($0) {
39
+ return "%26%23" + parseInt($0.slice(2), 16) + "%3B";
40
+ });
41
+ }
42
+ let out = "";
43
+ for (let j = 0; j < string.length; j += limit) {
44
+ const segment = string.length >= limit ? string.slice(j, j + limit) : string;
45
+ const arr = [];
46
+ for (let i = 0; i < segment.length; ++i) {
47
+ let c = segment.charCodeAt(i);
48
+ if (c === 45 || // -
49
+ c === 46 || // .
50
+ c === 95 || // _
51
+ c === 126 || // ~
52
+ c >= 48 && c <= 57 || // 0-9
53
+ c >= 65 && c <= 90 || // a-z
54
+ c >= 97 && c <= 122 || // A-Z
55
+ format === RFC1738 && (c === 40 || c === 41)) {
56
+ arr[arr.length] = segment.charAt(i);
57
+ continue;
58
+ }
59
+ if (c < 128) {
60
+ arr[arr.length] = hexTable[c];
61
+ continue;
62
+ }
63
+ if (c < 2048) {
64
+ arr[arr.length] = hexTable[192 | c >> 6] + hexTable[128 | c & 63];
65
+ continue;
66
+ }
67
+ if (c < 55296 || c >= 57344) {
68
+ arr[arr.length] = hexTable[224 | c >> 12] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
69
+ continue;
70
+ }
71
+ i += 1;
72
+ c = 65536 + ((c & 1023) << 10 | segment.charCodeAt(i) & 1023);
73
+ arr[arr.length] = hexTable[240 | c >> 18] + hexTable[128 | c >> 12 & 63] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63];
74
+ }
75
+ out += arr.join("");
76
+ }
77
+ return out;
78
+ };
79
+ const isBuffer = function isBuffer2(obj) {
80
+ if (!obj || typeof obj !== "object") {
81
+ return false;
82
+ }
83
+ return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
84
+ };
85
+ const maybeMap = function maybeMap2(val, fn) {
86
+ if (isArray$1(val)) {
87
+ const mapped = [];
88
+ for (let i = 0; i < val.length; i += 1) {
89
+ mapped.push(fn(val[i]));
90
+ }
91
+ return mapped;
92
+ }
93
+ return fn(val);
94
+ };
95
+
96
+ const arrayPrefixGenerators = {
97
+ brackets: function brackets(prefix) {
98
+ return prefix + "[]";
99
+ },
100
+ comma: "comma",
101
+ indices: function indices(prefix, key) {
102
+ return prefix + "[" + key + "]";
103
+ },
104
+ repeat: function repeat(prefix) {
105
+ return prefix;
106
+ }
107
+ };
108
+ const isArray = Array.isArray;
109
+ const push = Array.prototype.push;
110
+ const pushToArray = function(arr, valueOrArray) {
111
+ push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
112
+ };
113
+ const toISO = Date.prototype.toISOString;
114
+ const defaultFormat = formats;
115
+ const defaults = {
116
+ addQueryPrefix: false,
117
+ allowDots: false,
118
+ allowEmptyArrays: false,
119
+ arrayFormat: "indices",
120
+ charset: "utf-8",
121
+ charsetSentinel: false,
122
+ delimiter: "&",
123
+ encode: true,
124
+ encodeDotInKeys: false,
125
+ encoder: encode,
126
+ encodeValuesOnly: false,
127
+ format: defaultFormat,
128
+ formatter: formatters[defaultFormat],
129
+ // deprecated
130
+ indices: false,
131
+ serializeDate: function serializeDate(date) {
132
+ return toISO.call(date);
133
+ },
134
+ skipNulls: false,
135
+ strictNullHandling: false
136
+ };
137
+ const isNonNullishPrimitive = function isNonNullishPrimitive2(v) {
138
+ return typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "bigint";
139
+ };
140
+ const sentinel = {};
141
+ const _stringify = function stringify2(object, prefix, generateArrayPrefix, commaRoundTrip, allowEmptyArrays, strictNullHandling, skipNulls, encodeDotInKeys, encoder, filter, sort, allowDots, serializeDate2, format, formatter, encodeValuesOnly, charset, sideChannel) {
142
+ let obj = object;
143
+ let tmpSc = sideChannel;
144
+ let step = 0;
145
+ let findFlag = false;
146
+ while ((tmpSc = tmpSc.get(sentinel)) !== void 0 && !findFlag) {
147
+ const pos = tmpSc.get(object);
148
+ step += 1;
149
+ if (typeof pos !== "undefined") {
150
+ if (pos === step) {
151
+ throw new RangeError("Cyclic object value");
152
+ } else {
153
+ findFlag = true;
154
+ }
155
+ }
156
+ if (typeof tmpSc.get(sentinel) === "undefined") {
157
+ step = 0;
158
+ }
159
+ }
160
+ if (typeof filter === "function") {
161
+ obj = filter(prefix, obj);
162
+ } else if (obj instanceof Date) {
163
+ obj = serializeDate2(obj);
164
+ } else if (generateArrayPrefix === "comma" && isArray(obj)) {
165
+ obj = maybeMap(obj, function(value) {
166
+ if (value instanceof Date) {
167
+ return serializeDate2(value);
168
+ }
169
+ return value;
170
+ });
171
+ }
172
+ if (obj === null) {
173
+ if (strictNullHandling) {
174
+ return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, "key", format) : prefix;
175
+ }
176
+ obj = "";
177
+ }
178
+ if (isNonNullishPrimitive(obj) || isBuffer(obj)) {
179
+ if (encoder) {
180
+ const keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, "key", format);
181
+ return [
182
+ formatter(keyValue) + "=" + formatter(encoder(obj, defaults.encoder, charset, "value", format))
183
+ ];
184
+ }
185
+ return [formatter(prefix) + "=" + formatter(String(obj))];
186
+ }
187
+ const values = [];
188
+ if (typeof obj === "undefined") {
189
+ return values;
190
+ }
191
+ let objKeys;
192
+ if (generateArrayPrefix === "comma" && isArray(obj)) {
193
+ if (encodeValuesOnly && encoder) {
194
+ obj = maybeMap(obj, encoder);
195
+ }
196
+ objKeys = [{ value: obj.length > 0 ? obj.join(",") || null : void 0 }];
197
+ } else if (isArray(filter)) {
198
+ objKeys = filter;
199
+ } else {
200
+ const keys = Object.keys(obj);
201
+ objKeys = sort ? keys.sort(sort) : keys;
202
+ }
203
+ const encodedPrefix = encodeDotInKeys ? prefix.replace(/\./g, "%2E") : prefix;
204
+ const adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + "[]" : encodedPrefix;
205
+ if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
206
+ return adjustedPrefix + "[]";
207
+ }
208
+ for (let j = 0; j < objKeys.length; ++j) {
209
+ const key = objKeys[j];
210
+ const value = typeof key === "object" && typeof key.value !== "undefined" ? key.value : obj[key];
211
+ if (skipNulls && value === null) {
212
+ continue;
213
+ }
214
+ const encodedKey = allowDots && encodeDotInKeys ? key.replace(/\./g, "%2E") : key;
215
+ const keyPrefix = isArray(obj) ? typeof generateArrayPrefix === "function" ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix : adjustedPrefix + (allowDots ? "." + encodedKey : "[" + encodedKey + "]");
216
+ sideChannel.set(object, step);
217
+ const valueSideChannel = /* @__PURE__ */ new WeakMap();
218
+ valueSideChannel.set(sentinel, sideChannel);
219
+ pushToArray(
220
+ values,
221
+ _stringify(
222
+ value,
223
+ keyPrefix,
224
+ generateArrayPrefix,
225
+ commaRoundTrip,
226
+ allowEmptyArrays,
227
+ strictNullHandling,
228
+ skipNulls,
229
+ encodeDotInKeys,
230
+ generateArrayPrefix === "comma" && encodeValuesOnly && isArray(obj) ? null : encoder,
231
+ filter,
232
+ sort,
233
+ allowDots,
234
+ serializeDate2,
235
+ format,
236
+ formatter,
237
+ encodeValuesOnly,
238
+ charset,
239
+ valueSideChannel
240
+ )
241
+ );
242
+ }
243
+ return values;
244
+ };
245
+ const normalizeStringifyOptions = function normalizeStringifyOptions2(opts) {
246
+ {
247
+ return defaults;
248
+ }
249
+ };
250
+ function stringify(object, opts) {
251
+ let obj = object;
252
+ const options = normalizeStringifyOptions();
253
+ let objKeys;
254
+ let filter;
255
+ if (typeof options.filter === "function") {
256
+ filter = options.filter;
257
+ obj = filter("", obj);
258
+ } else if (isArray(options.filter)) {
259
+ filter = options.filter;
260
+ objKeys = filter;
261
+ }
262
+ const keys = [];
263
+ if (typeof obj !== "object" || obj === null) {
264
+ return "";
265
+ }
266
+ const generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
267
+ const commaRoundTrip = generateArrayPrefix === "comma" && options.commaRoundTrip;
268
+ if (!objKeys) {
269
+ objKeys = Object.keys(obj);
270
+ }
271
+ if (options.sort) {
272
+ objKeys.sort(options.sort);
273
+ }
274
+ const sideChannel = /* @__PURE__ */ new WeakMap();
275
+ for (let i = 0; i < objKeys.length; ++i) {
276
+ const key = objKeys[i];
277
+ if (options.skipNulls && obj[key] === null) {
278
+ continue;
279
+ }
280
+ pushToArray(
281
+ keys,
282
+ _stringify(
283
+ obj[key],
284
+ key,
285
+ generateArrayPrefix,
286
+ commaRoundTrip,
287
+ options.allowEmptyArrays,
288
+ options.strictNullHandling,
289
+ options.skipNulls,
290
+ options.encodeDotInKeys,
291
+ options.encode ? options.encoder : null,
292
+ options.filter,
293
+ options.sort,
294
+ options.allowDots,
295
+ options.serializeDate,
296
+ options.format,
297
+ options.formatter,
298
+ options.encodeValuesOnly,
299
+ options.charset,
300
+ sideChannel
301
+ )
302
+ );
303
+ }
304
+ const joined = keys.join(options.delimiter);
305
+ let prefix = options.addQueryPrefix === true ? "?" : "";
306
+ if (options.charsetSentinel) {
307
+ if (options.charset === "iso-8859-1") {
308
+ prefix += "utf8=%26%2310003%3B&";
309
+ } else {
310
+ prefix += "utf8=%E2%9C%93&";
311
+ }
312
+ }
313
+ return joined.length > 0 ? prefix + joined : "";
314
+ }
315
+
316
+ class Paginator extends Array {
317
+ constructor(totalNumber, perPage, currentPage, ...rows) {
318
+ super(...rows);
319
+ this.totalNumber = totalNumber;
320
+ this.perPage = perPage;
321
+ this.currentPage = currentPage;
322
+ this.totalNumber = Number(totalNumber);
323
+ this.rows = rows;
324
+ this.isEmpty = this.rows.length === 0;
325
+ }
326
+ /**
327
+ * The first page is always 1
328
+ */
329
+ firstPage = 1;
330
+ /**
331
+ * Find if results set is empty or not
332
+ */
333
+ isEmpty;
334
+ qs = {};
335
+ rows;
336
+ url = "/";
337
+ /**
338
+ * A reference to the result rows.
339
+ */
340
+ all() {
341
+ return this.rows;
342
+ }
343
+ /**
344
+ * Define base url for making the pagination links.
345
+ */
346
+ baseUrl(url) {
347
+ this.url = url;
348
+ return this;
349
+ }
350
+ /**
351
+ * Returns JSON meta data.
352
+ */
353
+ getMeta() {
354
+ return {
355
+ firstPage: this.firstPage,
356
+ firstPageUrl: this.getUrl(1),
357
+ lastPage: this.lastPage,
358
+ lastPageUrl: this.getUrl(this.lastPage),
359
+ nextPageUrl: this.getNextPageUrl(),
360
+ page: this.currentPage,
361
+ perPage: this.perPage,
362
+ previousPageUrl: this.getPreviousPageUrl(),
363
+ total: this.total
364
+ };
365
+ }
366
+ /**
367
+ * Returns url for the next page.
368
+ */
369
+ getNextPageUrl() {
370
+ if (this.hasMorePages) {
371
+ return this.getUrl(this.currentPage + 1);
372
+ }
373
+ return null;
374
+ }
375
+ /**
376
+ * Returns URL for the previous page.
377
+ */
378
+ getPreviousPageUrl() {
379
+ if (this.currentPage > 1) {
380
+ return this.getUrl(this.currentPage - 1);
381
+ }
382
+ return null;
383
+ }
384
+ /**
385
+ * Returns url for a given page. Doesn't validate the integrity of the
386
+ * page.
387
+ */
388
+ getUrl(page) {
389
+ const qstring = stringify({ ...this.qs, page: Math.max(page, 1) });
390
+ return `${this.url}?${qstring}`;
391
+ }
392
+ /**
393
+ * Returns an array of urls under a given range.
394
+ */
395
+ getUrlsForRange(start, end) {
396
+ const urls = [];
397
+ for (let index = start; index <= end; index++) {
398
+ urls.push({ isActive: index === this.currentPage, page: index, url: this.getUrl(index) });
399
+ }
400
+ return urls;
401
+ }
402
+ /**
403
+ * Define query string to be appended to the pagination links.
404
+ */
405
+ queryString(values) {
406
+ this.qs = values;
407
+ return this;
408
+ }
409
+ /**
410
+ * Returns JSON representation of the paginated data.
411
+ */
412
+ toJSON() {
413
+ return {
414
+ data: this.all(),
415
+ meta: this.getMeta()
416
+ };
417
+ }
418
+ /**
419
+ * Find if there are more pages to come.
420
+ */
421
+ get hasMorePages() {
422
+ return this.lastPage > this.currentPage;
423
+ }
424
+ /**
425
+ * Find if there are enough results to be paginated or not.
426
+ */
427
+ get hasPages() {
428
+ return this.lastPage !== 1;
429
+ }
430
+ /**
431
+ * Find if there are total records or not. This is not same as
432
+ * `isEmpty`.
433
+ *
434
+ * The `isEmpty` reports about the current set of results. However, `hasTotal`
435
+ * reports about the total number of records, regardless of the current.
436
+ */
437
+ get hasTotal() {
438
+ return this.total > 0;
439
+ }
440
+ /**
441
+ * The Last page number.
442
+ */
443
+ get lastPage() {
444
+ return Math.max(Math.ceil(this.total / this.perPage), 1);
445
+ }
446
+ /**
447
+ * Casting `total` to a number. Later, we can think of situations
448
+ * to cast it to a bigint.
449
+ */
450
+ get total() {
451
+ return Number(this.totalNumber);
452
+ }
453
+ }
454
+
455
+ export { Paginator as default };
@@ -0,0 +1,78 @@
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/pagination",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Simple Pagination for Node.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -1 +0,0 @@
1
- var Y=Object.defineProperty;var w=(t,e)=>Y(t,"name",{value:e,configurable:!0});var Z=Object.defineProperty,H=w((t,e)=>Z(t,"name",{value:e,configurable:!0}),"e");const tt=String.prototype.replace,et=/%20/g,q={RFC1738:"RFC1738",RFC3986:"RFC3986"},M={RFC1738:H(function(t){return tt.call(t,et,"+")},"RFC1738"),RFC3986:H(function(t){return String(t)},"RFC3986")},rt=q.RFC1738,W=q.RFC3986;var ot=Object.defineProperty,h=w((t,e)=>ot(t,"name",{value:e,configurable:!0}),"u$1");const k=Object.prototype.hasOwnProperty,O=Array.isArray,d=(function(){const t=[];for(let e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t})(),nt=h(function(t){for(;t.length>1;){const e=t.pop(),o=e.obj[e.prop];if(O(o)){const r=[];for(let l=0;l<o.length;++l)typeof o[l]<"u"&&r.push(o[l]);e.obj[e.prop]=r}}},"compactQueue"),at=h(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");h(w(function t(e,o,r){if(!o)return e;if(typeof o!="object"){if(O(e))e.push(o);else if(e&&typeof e=="object")(r&&(r.plainObjects||r.allowPrototypes)||!k.call(Object.prototype,o))&&(e[o]=!0);else return[e,o];return e}if(!e||typeof e!="object")return[e].concat(o);let l=e;return O(e)&&!O(o)&&(l=at(e,r)),O(e)&&O(o)?(o.forEach(function(n,s){if(k.call(e,s)){const c=e[s];c&&typeof c=="object"&&n&&typeof n=="object"?e[s]=t(c,n,r):e.push(n)}else e[s]=n}),e):Object.keys(o).reduce(function(n,s){const c=o[s];return k.call(n,s)?n[s]=t(n[s],c,r):n[s]=c,n},l)},"i"),"merge");h(function(t,e){return Object.keys(e).reduce(function(o,r){return o[r]=e[r],o},t)},"assignSingleSource");h(function(t,e,o){const r=t.replace(/\+/g," ");if(o==="iso-8859-1")return r.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(r)}catch{return r}},"decode");const I=1024,lt=h(function(t,e,o,r,l){if(t.length===0)return t;let n=t;if(typeof t=="symbol"?n=Symbol.prototype.toString.call(t):typeof t!="string"&&(n=String(t)),o==="iso-8859-1")return escape(n).replace(/%u[0-9a-f]{4}/gi,function(c){return"%26%23"+parseInt(c.slice(2),16)+"%3B"});let s="";for(let c=0;c<n.length;c+=I){const p=n.length>=I?n.slice(c,c+I):n,u=[];for(let g=0;g<p.length;++g){let a=p.charCodeAt(g);if(a===45||a===46||a===95||a===126||a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||l===rt&&(a===40||a===41)){u[u.length]=p.charAt(g);continue}if(a<128){u[u.length]=d[a];continue}if(a<2048){u[u.length]=d[192|a>>6]+d[128|a&63];continue}if(a<55296||a>=57344){u[u.length]=d[224|a>>12]+d[128|a>>6&63]+d[128|a&63];continue}g+=1,a=65536+((a&1023)<<10|p.charCodeAt(g)&1023),u[u.length]=d[240|a>>18]+d[128|a>>12&63]+d[128|a>>6&63]+d[128|a&63]}s+=u.join("")}return s},"encode");h(function(t){const e=[{obj:{o:t},prop:"o"}],o=[];for(let r=0;r<e.length;++r){const l=e[r],n=l.obj[l.prop],s=Object.keys(n);for(let c=0;c<s.length;++c){const p=s[c],u=n[p];typeof u=="object"&&u!==null&&o.indexOf(u)===-1&&(e.push({obj:n,prop:p}),o.push(u))}}return nt(e),t},"compact");h(function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},"isRegExp");const it=h(function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},"isBuffer");h(function(t,e){return[].concat(t,e)},"combine");const V=h(function(t,e){if(O(t)){const o=[];for(let r=0;r<t.length;r+=1)o.push(e(t[r]));return o}return e(t)},"maybeMap");var st=Object.defineProperty,b=w((t,e)=>st(t,"name",{value:e,configurable:!0}),"u");const ct=Object.prototype.hasOwnProperty,J={brackets:b(function(t){return t+"[]"},"brackets"),comma:"comma",indices:b(function(t,e){return t+"["+e+"]"},"indices"),repeat:b(function(t){return t},"repeat")},m=Array.isArray,ut=Array.prototype.push,G=b(function(t,e){ut.apply(t,m(e)?e:[e])},"pushToArray"),ft=Date.prototype.toISOString,$=W,f={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:lt,encodeValuesOnly:!1,format:$,formatter:M[$],indices:!1,serializeDate:b(function(t){return ft.call(t)},"serializeDate"),skipNulls:!1,strictNullHandling:!1},pt=b(function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},"isNonNullishPrimitive"),T={},_=b(function(t,e,o,r,l,n,s,c,p,u,g,a,j,P,E,N,D,x){let i=t,A=x,U=0,K=!1;for(;(A=A.get(T))!==void 0&&!K;){const y=A.get(t);if(U+=1,typeof y<"u"){if(y===U)throw new RangeError("Cyclic object value");K=!0}typeof A.get(T)>"u"&&(U=0)}if(typeof u=="function"?i=u(e,i):i instanceof Date?i=j(i):o==="comma"&&m(i)&&(i=V(i,function(y){return y instanceof Date?j(y):y})),i===null){if(n)return p&&!N?p(e,f.encoder,D,"key",P):e;i=""}if(pt(i)||it(i)){if(p){const y=N?e:p(e,f.encoder,D,"key",P);return[E(y)+"="+E(p(i,f.encoder,D,"value",P))]}return[E(e)+"="+E(String(i))]}const C=[];if(typeof i>"u")return C;let R;if(o==="comma"&&m(i))N&&p&&(i=V(i,p)),R=[{value:i.length>0?i.join(",")||null:void 0}];else if(m(u))R=u;else{const y=Object.keys(i);R=g?y.sort(g):y}const z=c?e.replace(/\./g,"%2E"):e,F=r&&m(i)&&i.length===1?z+"[]":z;if(l&&m(i)&&i.length===0)return F+"[]";for(let y=0;y<R.length;++y){const v=R[y],Q=typeof v=="object"&&typeof v.value<"u"?v.value:i[v];if(s&&Q===null)continue;const S=a&&c?v.replace(/\./g,"%2E"):v,X=m(i)?typeof o=="function"?o(F,S):F:F+(a?"."+S:"["+S+"]");x.set(t,U);const B=new WeakMap;B.set(T,x),G(C,_(Q,X,o,r,l,n,s,c,o==="comma"&&N&&m(i)?null:p,u,g,a,j,P,E,N,D,B))}return C},"stringify"),yt=b(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.");const e=t.charset||f.charset;if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let o=W;if(typeof t.format<"u"){if(!ct.call(M,t.format))throw new TypeError("Unknown format option provided.");o=t.format}const r=M[o];let l=f.filter;(typeof t.filter=="function"||m(t.filter))&&(l=t.filter);let n;if(t.arrayFormat in J?n=t.arrayFormat:"indices"in t?n=t.indices?"indices":"repeat":n=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:n,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:f.charsetSentinel,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:l,format:o,formatter:r,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 L(t,e){let o=t;const r=yt(e);let l,n;typeof r.filter=="function"?(n=r.filter,o=n("",o)):m(r.filter)&&(n=r.filter,l=n);const s=[];if(typeof o!="object"||o===null)return"";const c=J[r.arrayFormat],p=c==="comma"&&r.commaRoundTrip;l||(l=Object.keys(o)),r.sort&&l.sort(r.sort);const u=new WeakMap;for(let j=0;j<l.length;++j){const P=l[j];r.skipNulls&&o[P]===null||G(s,_(o[P],P,c,p,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,r.charset,u))}const g=s.join(r.delimiter);let a=r.addQueryPrefix===!0?"?":"";return r.charsetSentinel&&(r.charset==="iso-8859-1"?a+="utf8=%26%2310003%3B&":a+="utf8=%E2%9C%93&"),g.length>0?a+g:""}w(L,"stringify");b(L,"stringify");var gt=Object.defineProperty,ht=w((t,e)=>gt(t,"name",{value:e,configurable:!0}),"n");class mt extends Array{static{w(this,"g")}constructor(e,o,r,...l){super(...l),this.totalNumber=e,this.perPage=o,this.currentPage=r,this.totalNumber=Number(e),this.rows=l,this.isEmpty=this.rows.length===0}static{ht(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=L({...this.qs,page:Math.max(e,1)});return`${this.url}?${o}`}getUrlsForRange(e,o){const r=[];for(let l=e;l<=o;l++)r.push({isActive:l===this.currentPage,page:l,url:this.getUrl(l)});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 Number(this.totalNumber)}}export{mt 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};