@visulima/pagination 4.0.2 → 4.0.4
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 +21 -0
- package/LICENSE.md +3 -0
- package/dist/index.d.ts +5 -400
- package/dist/index.js +6 -1
- package/dist/packem_shared/Paginator-B3QHCcfB.js +455 -0
- package/dist/packem_shared/createPaginationMetaSchemaObject-AoC1C8S-.js +78 -0
- package/dist/paginator.d.ts +90 -0
- package/dist/swagger.d.ts +3 -0
- package/package.json +1 -1
- package/dist/packem_shared/Paginator-qLvq_0YE.js +0 -1
- package/dist/packem_shared/createPaginationMetaSchemaObject-DGZPqai2.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## @visulima/pagination [4.0.4](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.3...@visulima/pagination@4.0.4) (2025-11-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update package configurations and TypeScript definitions ([b59aa59](https://github.com/visulima/visulima/commit/b59aa59dac1508216b944f4b917fb4a7ab1f70a4))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* Add jsr file to all packages for release ([#565](https://github.com/visulima/visulima/issues/565)) ([ec91652](https://github.com/visulima/visulima/commit/ec91652b4e4112adf14ba152c1239a7703ba425a))
|
|
10
|
+
* update license files and clean up TypeScript definitions ([fe668cc](https://github.com/visulima/visulima/commit/fe668cc26de23591d4df54a0954455ebbe31b22d))
|
|
11
|
+
|
|
12
|
+
## @visulima/pagination [4.0.3](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.2...@visulima/pagination@4.0.3) (2025-11-07)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
17
|
+
|
|
18
|
+
### Miscellaneous Chores
|
|
19
|
+
|
|
20
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
21
|
+
|
|
1
22
|
## @visulima/pagination [4.0.2](https://github.com/visulima/visulima/compare/@visulima/pagination@4.0.1...@visulima/pagination@4.0.2) (2025-11-05)
|
|
2
23
|
|
|
3
24
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -67,11 +67,14 @@ Repository: https://github.com/payloadcms/qs-esm.git
|
|
|
67
67
|
<!-- TYPE_DEPENDENCIES -->
|
|
68
68
|
|
|
69
69
|
# Licenses of bundled types
|
|
70
|
+
|
|
70
71
|
The published @visulima/pagination artifact additionally contains code with the following licenses:
|
|
71
72
|
MIT
|
|
72
73
|
|
|
73
74
|
# Bundled types:
|
|
75
|
+
|
|
74
76
|
## openapi-types
|
|
77
|
+
|
|
75
78
|
License: MIT
|
|
76
79
|
By: Joseph Spencer
|
|
77
80
|
Repository: https://github.com/kogosoftwarellc/open-api/tree/master/packages/openapi-types
|
package/dist/index.d.ts
CHANGED
|
@@ -1,400 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
nextPageUrl: string | null;
|
|
7
|
-
page: number;
|
|
8
|
-
perPage: number;
|
|
9
|
-
previousPageUrl: string | null;
|
|
10
|
-
total: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface PaginationResult<Result> {
|
|
14
|
-
data: Result[];
|
|
15
|
-
meta: PaginationMeta;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface Paginator$1<Result> extends Array<Result> {
|
|
19
|
-
all: () => Result[];
|
|
20
|
-
|
|
21
|
-
baseUrl: (url: string) => this;
|
|
22
|
-
readonly currentPage: number;
|
|
23
|
-
readonly firstPage: number;
|
|
24
|
-
getMeta: () => PaginationMeta;
|
|
25
|
-
getNextPageUrl: () => string | null;
|
|
26
|
-
getPreviousPageUrl: () => string | null;
|
|
27
|
-
getUrl: (page: number) => string;
|
|
28
|
-
getUrlsForRange: (start: number, end: number) => { isActive: boolean; page: number; url: string }[];
|
|
29
|
-
readonly hasMorePages: boolean;
|
|
30
|
-
|
|
31
|
-
readonly hasPages: boolean;
|
|
32
|
-
readonly hasTotal: boolean;
|
|
33
|
-
readonly isEmpty: boolean;
|
|
34
|
-
readonly lastPage: number;
|
|
35
|
-
readonly perPage: number;
|
|
36
|
-
queryString: (values: Record<string, unknown>) => this;
|
|
37
|
-
toJSON: () => PaginationResult<Result>;
|
|
38
|
-
readonly total: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type UrlsForRange = {
|
|
42
|
-
isActive: boolean;
|
|
43
|
-
page: number;
|
|
44
|
-
url: string;
|
|
45
|
-
}[];
|
|
46
|
-
declare class Paginator<T = unknown> extends Array<T> implements Paginator$1<T> {
|
|
47
|
-
private readonly totalNumber;
|
|
48
|
-
readonly perPage: number;
|
|
49
|
-
currentPage: number;
|
|
50
|
-
readonly firstPage: number;
|
|
51
|
-
readonly isEmpty: boolean;
|
|
52
|
-
private qs;
|
|
53
|
-
private readonly rows;
|
|
54
|
-
private url;
|
|
55
|
-
constructor(totalNumber: number, perPage: number, currentPage: number, ...rows: T[]);
|
|
56
|
-
all(): T[];
|
|
57
|
-
baseUrl(url: string): this;
|
|
58
|
-
getMeta(): PaginationMeta;
|
|
59
|
-
getNextPageUrl(): string | null;
|
|
60
|
-
getPreviousPageUrl(): string | null;
|
|
61
|
-
getUrl(page: number): string;
|
|
62
|
-
getUrlsForRange(start: number, end: number): UrlsForRange;
|
|
63
|
-
queryString(values: Record<string, unknown>): this;
|
|
64
|
-
toJSON(): PaginationResult<T>;
|
|
65
|
-
get hasMorePages(): boolean;
|
|
66
|
-
get hasPages(): boolean;
|
|
67
|
-
get hasTotal(): boolean;
|
|
68
|
-
get lastPage(): number;
|
|
69
|
-
get total(): number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare namespace OpenAPIV3 {
|
|
73
|
-
interface Document<T extends {} = {}> {
|
|
74
|
-
openapi: string;
|
|
75
|
-
info: InfoObject;
|
|
76
|
-
servers?: ServerObject[];
|
|
77
|
-
paths: PathsObject<T>;
|
|
78
|
-
components?: ComponentsObject;
|
|
79
|
-
security?: SecurityRequirementObject[];
|
|
80
|
-
tags?: TagObject[];
|
|
81
|
-
externalDocs?: ExternalDocumentationObject;
|
|
82
|
-
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
83
|
-
'x-express-openapi-validation-strict'?: boolean;
|
|
84
|
-
}
|
|
85
|
-
interface InfoObject {
|
|
86
|
-
title: string;
|
|
87
|
-
description?: string;
|
|
88
|
-
termsOfService?: string;
|
|
89
|
-
contact?: ContactObject;
|
|
90
|
-
license?: LicenseObject;
|
|
91
|
-
version: string;
|
|
92
|
-
}
|
|
93
|
-
interface ContactObject {
|
|
94
|
-
name?: string;
|
|
95
|
-
url?: string;
|
|
96
|
-
email?: string;
|
|
97
|
-
}
|
|
98
|
-
interface LicenseObject {
|
|
99
|
-
name: string;
|
|
100
|
-
url?: string;
|
|
101
|
-
}
|
|
102
|
-
interface ServerObject {
|
|
103
|
-
url: string;
|
|
104
|
-
description?: string;
|
|
105
|
-
variables?: {
|
|
106
|
-
[variable: string]: ServerVariableObject;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
interface ServerVariableObject {
|
|
110
|
-
enum?: string[];
|
|
111
|
-
default: string;
|
|
112
|
-
description?: string;
|
|
113
|
-
}
|
|
114
|
-
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
115
|
-
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
116
|
-
}
|
|
117
|
-
enum HttpMethods {
|
|
118
|
-
GET = "get",
|
|
119
|
-
PUT = "put",
|
|
120
|
-
POST = "post",
|
|
121
|
-
DELETE = "delete",
|
|
122
|
-
OPTIONS = "options",
|
|
123
|
-
HEAD = "head",
|
|
124
|
-
PATCH = "patch",
|
|
125
|
-
TRACE = "trace"
|
|
126
|
-
}
|
|
127
|
-
type PathItemObject<T extends {} = {}> = {
|
|
128
|
-
$ref?: string;
|
|
129
|
-
summary?: string;
|
|
130
|
-
description?: string;
|
|
131
|
-
servers?: ServerObject[];
|
|
132
|
-
parameters?: (ReferenceObject | ParameterObject)[];
|
|
133
|
-
} & {
|
|
134
|
-
[method in HttpMethods]?: OperationObject<T>;
|
|
135
|
-
};
|
|
136
|
-
type OperationObject<T extends {} = {}> = {
|
|
137
|
-
tags?: string[];
|
|
138
|
-
summary?: string;
|
|
139
|
-
description?: string;
|
|
140
|
-
externalDocs?: ExternalDocumentationObject;
|
|
141
|
-
operationId?: string;
|
|
142
|
-
parameters?: (ReferenceObject | ParameterObject)[];
|
|
143
|
-
requestBody?: ReferenceObject | RequestBodyObject;
|
|
144
|
-
responses: ResponsesObject;
|
|
145
|
-
callbacks?: {
|
|
146
|
-
[callback: string]: ReferenceObject | CallbackObject;
|
|
147
|
-
};
|
|
148
|
-
deprecated?: boolean;
|
|
149
|
-
security?: SecurityRequirementObject[];
|
|
150
|
-
servers?: ServerObject[];
|
|
151
|
-
} & T;
|
|
152
|
-
interface ExternalDocumentationObject {
|
|
153
|
-
description?: string;
|
|
154
|
-
url: string;
|
|
155
|
-
}
|
|
156
|
-
interface ParameterObject extends ParameterBaseObject {
|
|
157
|
-
name: string;
|
|
158
|
-
in: string;
|
|
159
|
-
}
|
|
160
|
-
interface HeaderObject extends ParameterBaseObject {
|
|
161
|
-
}
|
|
162
|
-
interface ParameterBaseObject {
|
|
163
|
-
description?: string;
|
|
164
|
-
required?: boolean;
|
|
165
|
-
deprecated?: boolean;
|
|
166
|
-
allowEmptyValue?: boolean;
|
|
167
|
-
style?: string;
|
|
168
|
-
explode?: boolean;
|
|
169
|
-
allowReserved?: boolean;
|
|
170
|
-
schema?: ReferenceObject | SchemaObject;
|
|
171
|
-
example?: any;
|
|
172
|
-
examples?: {
|
|
173
|
-
[media: string]: ReferenceObject | ExampleObject;
|
|
174
|
-
};
|
|
175
|
-
content?: {
|
|
176
|
-
[media: string]: MediaTypeObject;
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
180
|
-
type ArraySchemaObjectType = 'array';
|
|
181
|
-
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
182
|
-
interface ArraySchemaObject extends BaseSchemaObject {
|
|
183
|
-
type: ArraySchemaObjectType;
|
|
184
|
-
items: ReferenceObject | SchemaObject;
|
|
185
|
-
}
|
|
186
|
-
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
187
|
-
type?: NonArraySchemaObjectType;
|
|
188
|
-
}
|
|
189
|
-
interface BaseSchemaObject {
|
|
190
|
-
title?: string;
|
|
191
|
-
description?: string;
|
|
192
|
-
format?: string;
|
|
193
|
-
default?: any;
|
|
194
|
-
multipleOf?: number;
|
|
195
|
-
maximum?: number;
|
|
196
|
-
exclusiveMaximum?: boolean;
|
|
197
|
-
minimum?: number;
|
|
198
|
-
exclusiveMinimum?: boolean;
|
|
199
|
-
maxLength?: number;
|
|
200
|
-
minLength?: number;
|
|
201
|
-
pattern?: string;
|
|
202
|
-
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
203
|
-
maxItems?: number;
|
|
204
|
-
minItems?: number;
|
|
205
|
-
uniqueItems?: boolean;
|
|
206
|
-
maxProperties?: number;
|
|
207
|
-
minProperties?: number;
|
|
208
|
-
required?: string[];
|
|
209
|
-
enum?: any[];
|
|
210
|
-
properties?: {
|
|
211
|
-
[name: string]: ReferenceObject | SchemaObject;
|
|
212
|
-
};
|
|
213
|
-
allOf?: (ReferenceObject | SchemaObject)[];
|
|
214
|
-
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
215
|
-
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
216
|
-
not?: ReferenceObject | SchemaObject;
|
|
217
|
-
nullable?: boolean;
|
|
218
|
-
discriminator?: DiscriminatorObject;
|
|
219
|
-
readOnly?: boolean;
|
|
220
|
-
writeOnly?: boolean;
|
|
221
|
-
xml?: XMLObject;
|
|
222
|
-
externalDocs?: ExternalDocumentationObject;
|
|
223
|
-
example?: any;
|
|
224
|
-
deprecated?: boolean;
|
|
225
|
-
}
|
|
226
|
-
interface DiscriminatorObject {
|
|
227
|
-
propertyName: string;
|
|
228
|
-
mapping?: {
|
|
229
|
-
[value: string]: string;
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
interface XMLObject {
|
|
233
|
-
name?: string;
|
|
234
|
-
namespace?: string;
|
|
235
|
-
prefix?: string;
|
|
236
|
-
attribute?: boolean;
|
|
237
|
-
wrapped?: boolean;
|
|
238
|
-
}
|
|
239
|
-
interface ReferenceObject {
|
|
240
|
-
$ref: string;
|
|
241
|
-
}
|
|
242
|
-
interface ExampleObject {
|
|
243
|
-
summary?: string;
|
|
244
|
-
description?: string;
|
|
245
|
-
value?: any;
|
|
246
|
-
externalValue?: string;
|
|
247
|
-
}
|
|
248
|
-
interface MediaTypeObject {
|
|
249
|
-
schema?: ReferenceObject | SchemaObject;
|
|
250
|
-
example?: any;
|
|
251
|
-
examples?: {
|
|
252
|
-
[media: string]: ReferenceObject | ExampleObject;
|
|
253
|
-
};
|
|
254
|
-
encoding?: {
|
|
255
|
-
[media: string]: EncodingObject;
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
interface EncodingObject {
|
|
259
|
-
contentType?: string;
|
|
260
|
-
headers?: {
|
|
261
|
-
[header: string]: ReferenceObject | HeaderObject;
|
|
262
|
-
};
|
|
263
|
-
style?: string;
|
|
264
|
-
explode?: boolean;
|
|
265
|
-
allowReserved?: boolean;
|
|
266
|
-
}
|
|
267
|
-
interface RequestBodyObject {
|
|
268
|
-
description?: string;
|
|
269
|
-
content: {
|
|
270
|
-
[media: string]: MediaTypeObject;
|
|
271
|
-
};
|
|
272
|
-
required?: boolean;
|
|
273
|
-
}
|
|
274
|
-
interface ResponsesObject {
|
|
275
|
-
[code: string]: ReferenceObject | ResponseObject;
|
|
276
|
-
}
|
|
277
|
-
interface ResponseObject {
|
|
278
|
-
description: string;
|
|
279
|
-
headers?: {
|
|
280
|
-
[header: string]: ReferenceObject | HeaderObject;
|
|
281
|
-
};
|
|
282
|
-
content?: {
|
|
283
|
-
[media: string]: MediaTypeObject;
|
|
284
|
-
};
|
|
285
|
-
links?: {
|
|
286
|
-
[link: string]: ReferenceObject | LinkObject;
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
interface LinkObject {
|
|
290
|
-
operationRef?: string;
|
|
291
|
-
operationId?: string;
|
|
292
|
-
parameters?: {
|
|
293
|
-
[parameter: string]: any;
|
|
294
|
-
};
|
|
295
|
-
requestBody?: any;
|
|
296
|
-
description?: string;
|
|
297
|
-
server?: ServerObject;
|
|
298
|
-
}
|
|
299
|
-
interface CallbackObject {
|
|
300
|
-
[url: string]: PathItemObject;
|
|
301
|
-
}
|
|
302
|
-
interface SecurityRequirementObject {
|
|
303
|
-
[name: string]: string[];
|
|
304
|
-
}
|
|
305
|
-
interface ComponentsObject {
|
|
306
|
-
schemas?: {
|
|
307
|
-
[key: string]: ReferenceObject | SchemaObject;
|
|
308
|
-
};
|
|
309
|
-
responses?: {
|
|
310
|
-
[key: string]: ReferenceObject | ResponseObject;
|
|
311
|
-
};
|
|
312
|
-
parameters?: {
|
|
313
|
-
[key: string]: ReferenceObject | ParameterObject;
|
|
314
|
-
};
|
|
315
|
-
examples?: {
|
|
316
|
-
[key: string]: ReferenceObject | ExampleObject;
|
|
317
|
-
};
|
|
318
|
-
requestBodies?: {
|
|
319
|
-
[key: string]: ReferenceObject | RequestBodyObject;
|
|
320
|
-
};
|
|
321
|
-
headers?: {
|
|
322
|
-
[key: string]: ReferenceObject | HeaderObject;
|
|
323
|
-
};
|
|
324
|
-
securitySchemes?: {
|
|
325
|
-
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
326
|
-
};
|
|
327
|
-
links?: {
|
|
328
|
-
[key: string]: ReferenceObject | LinkObject;
|
|
329
|
-
};
|
|
330
|
-
callbacks?: {
|
|
331
|
-
[key: string]: ReferenceObject | CallbackObject;
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
335
|
-
interface HttpSecurityScheme {
|
|
336
|
-
type: 'http';
|
|
337
|
-
description?: string;
|
|
338
|
-
scheme: string;
|
|
339
|
-
bearerFormat?: string;
|
|
340
|
-
}
|
|
341
|
-
interface ApiKeySecurityScheme {
|
|
342
|
-
type: 'apiKey';
|
|
343
|
-
description?: string;
|
|
344
|
-
name: string;
|
|
345
|
-
in: string;
|
|
346
|
-
}
|
|
347
|
-
interface OAuth2SecurityScheme {
|
|
348
|
-
type: 'oauth2';
|
|
349
|
-
description?: string;
|
|
350
|
-
flows: {
|
|
351
|
-
implicit?: {
|
|
352
|
-
authorizationUrl: string;
|
|
353
|
-
refreshUrl?: string;
|
|
354
|
-
scopes: {
|
|
355
|
-
[scope: string]: string;
|
|
356
|
-
};
|
|
357
|
-
};
|
|
358
|
-
password?: {
|
|
359
|
-
tokenUrl: string;
|
|
360
|
-
refreshUrl?: string;
|
|
361
|
-
scopes: {
|
|
362
|
-
[scope: string]: string;
|
|
363
|
-
};
|
|
364
|
-
};
|
|
365
|
-
clientCredentials?: {
|
|
366
|
-
tokenUrl: string;
|
|
367
|
-
refreshUrl?: string;
|
|
368
|
-
scopes: {
|
|
369
|
-
[scope: string]: string;
|
|
370
|
-
};
|
|
371
|
-
};
|
|
372
|
-
authorizationCode?: {
|
|
373
|
-
authorizationUrl: string;
|
|
374
|
-
tokenUrl: string;
|
|
375
|
-
refreshUrl?: string;
|
|
376
|
-
scopes: {
|
|
377
|
-
[scope: string]: string;
|
|
378
|
-
};
|
|
379
|
-
};
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
interface OpenIdSecurityScheme {
|
|
383
|
-
type: 'openIdConnect';
|
|
384
|
-
description?: string;
|
|
385
|
-
openIdConnectUrl: string;
|
|
386
|
-
}
|
|
387
|
-
interface TagObject {
|
|
388
|
-
name: string;
|
|
389
|
-
description?: string;
|
|
390
|
-
externalDocs?: ExternalDocumentationObject;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
declare const createPaginationMetaSchemaObject: (name?: string) => Record<string, OpenAPIV3.SchemaObject>;
|
|
395
|
-
declare const createPaginationSchemaObject: (name: string, items: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, metaReference?: string) => Record<string, OpenAPIV3.SchemaObject>;
|
|
396
|
-
|
|
397
|
-
declare const paginate: <Result>(page: number, perPage: number, total: number, rows: Result[]) => Paginator$1<Result>;
|
|
398
|
-
|
|
399
|
-
export { Paginator, createPaginationMetaSchemaObject, createPaginationSchemaObject, paginate };
|
|
400
|
-
export type { PaginationMeta, PaginationResult, Paginator$1 as PaginatorInterface };
|
|
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";
|
package/dist/index.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
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 };
|
|
@@ -0,0 +1,90 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
package/package.json
CHANGED
|
@@ -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};
|