@telperion/nest-pack 1.0.0 → 1.2.0

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.
Files changed (53) hide show
  1. package/.build-manifest.json +61 -1
  2. package/README.md +124 -3
  3. package/access/access-guard-options.d.cts +19 -4
  4. package/access/access-guard-options.d.ts +19 -4
  5. package/access/create-access-guard.cjs +15 -4
  6. package/access/create-access-guard.cjs.map +1 -1
  7. package/access/create-access-guard.d.cts +3 -2
  8. package/access/create-access-guard.d.ts +3 -2
  9. package/access/create-access-guard.js +15 -4
  10. package/access/create-access-guard.js.map +1 -1
  11. package/access/index.d.cts +1 -1
  12. package/access/index.d.ts +1 -1
  13. package/auth/create-jwt-auth-guard.cjs +104 -0
  14. package/auth/create-jwt-auth-guard.cjs.map +1 -0
  15. package/auth/create-jwt-auth-guard.d.cts +52 -0
  16. package/auth/create-jwt-auth-guard.d.ts +52 -0
  17. package/auth/create-jwt-auth-guard.js +102 -0
  18. package/auth/create-jwt-auth-guard.js.map +1 -0
  19. package/auth/index.cjs +8 -0
  20. package/auth/index.cjs.map +1 -0
  21. package/auth/index.d.cts +4 -0
  22. package/auth/index.d.ts +4 -0
  23. package/auth/index.js +2 -0
  24. package/auth/index.js.map +1 -0
  25. package/auth/jwt-auth-guard-options.cjs +3 -0
  26. package/auth/jwt-auth-guard-options.cjs.map +1 -0
  27. package/auth/jwt-auth-guard-options.d.cts +62 -0
  28. package/auth/jwt-auth-guard-options.d.ts +62 -0
  29. package/auth/jwt-auth-guard-options.js +2 -0
  30. package/auth/jwt-auth-guard-options.js.map +1 -0
  31. package/fesm/nest-pack.mjs +15 -4
  32. package/fesm/nest-pack.mjs.map +1 -1
  33. package/index.d.cts +1 -1
  34. package/index.d.ts +1 -1
  35. package/package.json +96 -4
  36. package/pagination/index.cjs +10 -0
  37. package/pagination/index.cjs.map +1 -0
  38. package/pagination/index.d.cts +2 -0
  39. package/pagination/index.d.ts +2 -0
  40. package/pagination/index.js +3 -0
  41. package/pagination/index.js.map +1 -0
  42. package/pagination/page-query.cjs +92 -0
  43. package/pagination/page-query.cjs.map +1 -0
  44. package/pagination/page-query.d.cts +63 -0
  45. package/pagination/page-query.d.ts +63 -0
  46. package/pagination/page-query.js +90 -0
  47. package/pagination/page-query.js.map +1 -0
  48. package/pagination/page.cjs +48 -0
  49. package/pagination/page.cjs.map +1 -0
  50. package/pagination/page.d.cts +40 -0
  51. package/pagination/page.d.ts +40 -0
  52. package/pagination/page.js +46 -0
  53. package/pagination/page.js.map +1 -0
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var classTransformer = require('class-transformer');
5
+ var classValidator = require('class-validator');
6
+
7
+ /**
8
+ * #### Page Query
9
+ *
10
+ * Query DTO of a paged list endpoint: `?page=2&pageSize=50&search=ada`.
11
+ * Query values arrive as strings and are converted to numbers (`@Type(() => Number)`), so use it with
12
+ * `ValidationPipe({ transform: true })`; missing values keep their defaults.
13
+ *
14
+ * - `page`: integer, at least 1, default 1
15
+ * - `pageSize`: integer from 1 to 100, default 25
16
+ * - `search`: optional free text, at most 200 characters
17
+ *
18
+ * Extend it to add filters or to redeclare a property with other limits or Swagger metadata.
19
+ * Requires `class-transformer` and `class-validator` in your project.
20
+ *
21
+ * * * *
22
+ * Example:
23
+ * ```typescript
24
+ * import { Page, PageQuery } from '@telperion/nest-pack/pagination';
25
+ *
26
+ * @Get()
27
+ * async list(@Query() query: PageQuery): Promise<Page<User>> {
28
+ * const [items, total] = await this.users.findAndCount({
29
+ * where: query.search ? { name: ILike(PageQuery.likePattern(query.search)) } : {},
30
+ * ...PageQuery.skipTake(query),
31
+ * });
32
+ *
33
+ * return Page.of(items, total, query);
34
+ * }
35
+ * ```
36
+ * * * *
37
+ */
38
+ class PageQuery {
39
+ /**
40
+ * The page, from 1
41
+ */
42
+ page = 1;
43
+ /**
44
+ * The items per page, from 1 to 100
45
+ */
46
+ pageSize = 25;
47
+ /**
48
+ * Free-text search, at most 200 characters
49
+ */
50
+ search;
51
+ /**
52
+ * The rows to skip and to take for a page, as TypeORM's and Prisma's `skip` and `take` options
53
+ *
54
+ * @param query The page and page size
55
+ */
56
+ static skipTake(query) {
57
+ return { skip: (query.page - 1) * query.pageSize, take: query.pageSize };
58
+ }
59
+ /**
60
+ * A `LIKE`/`ILIKE` pattern matching values that contain the search text literally:
61
+ * `\`, `%` and `_` are escaped with `\` (the default escape character of PostgreSQL and MySQL), and the text is wrapped in `%`
62
+ *
63
+ * @param search The search text
64
+ */
65
+ static likePattern(search) {
66
+ return `%${search.replace(/[\\%_]/g, character => `\\${character}`)}%`;
67
+ }
68
+ }
69
+ tslib.__decorate([
70
+ classValidator.IsOptional(),
71
+ classTransformer.Type(() => Number),
72
+ classValidator.IsInt(),
73
+ classValidator.Min(1),
74
+ tslib.__metadata("design:type", Number)
75
+ ], PageQuery.prototype, "page", void 0);
76
+ tslib.__decorate([
77
+ classValidator.IsOptional(),
78
+ classTransformer.Type(() => Number),
79
+ classValidator.IsInt(),
80
+ classValidator.Min(1),
81
+ classValidator.Max(100),
82
+ tslib.__metadata("design:type", Number)
83
+ ], PageQuery.prototype, "pageSize", void 0);
84
+ tslib.__decorate([
85
+ classValidator.IsOptional(),
86
+ classValidator.IsString(),
87
+ classValidator.MaxLength(200),
88
+ tslib.__metadata("design:type", String)
89
+ ], PageQuery.prototype, "search", void 0);
90
+
91
+ exports.PageQuery = PageQuery;
92
+ //# sourceMappingURL=page-query.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query.cjs","sources":["../../../../libs/nest-pack/src/pagination/page-query.ts"],"sourcesContent":[null],"names":["__decorate","IsOptional","Type","IsInt","Min","Max","IsString","MaxLength"],"mappings":";;;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;MACU,SAAS,CAAA;AACpB;;AAEG;IAKH,IAAI,GAAW,CAAC;AAEhB;;AAEG;IAMH,QAAQ,GAAW,EAAE;AAErB;;AAEG;AAIH,IAAA,MAAM;AAEN;;;;AAIG;IACH,OAAO,QAAQ,CAAC,KAA2C,EAAA;QACzD,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE;IAC1E;AAEA;;;;;AAKG;IACH,OAAO,WAAW,CAAC,MAAc,EAAA;AAC/B,QAAA,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,IAAI,CAAA,EAAA,EAAK,SAAS,CAAA,CAAE,CAAC,GAAG;IACxE;AACD;AAtCCA,gBAAA,CAAA;AAJC,IAAAC,yBAAU,EAAE;AACZ,IAAAC,qBAAI,CAAC,MAAM,MAAM,CAAC;AAClB,IAAAC,oBAAK,EAAE;IACPC,kBAAG,CAAC,CAAC,CAAC;;AACU,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAUjBJ,gBAAA,CAAA;AALC,IAAAC,yBAAU,EAAE;AACZ,IAAAC,qBAAI,CAAC,MAAM,MAAM,CAAC;AAClB,IAAAC,oBAAK,EAAE;IACPC,kBAAG,CAAC,CAAC,CAAC;IACNC,kBAAG,CAAC,GAAG,CAAC;;AACa,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAQtBL,gBAAA,CAAA;AAHC,IAAAC,yBAAU,EAAE;AACZ,IAAAK,uBAAQ,EAAE;IACVC,wBAAS,CAAC,GAAG,CAAC;;AACC,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;;;;"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * #### Page Query
3
+ *
4
+ * Query DTO of a paged list endpoint: `?page=2&pageSize=50&search=ada`.
5
+ * Query values arrive as strings and are converted to numbers (`@Type(() => Number)`), so use it with
6
+ * `ValidationPipe({ transform: true })`; missing values keep their defaults.
7
+ *
8
+ * - `page`: integer, at least 1, default 1
9
+ * - `pageSize`: integer from 1 to 100, default 25
10
+ * - `search`: optional free text, at most 200 characters
11
+ *
12
+ * Extend it to add filters or to redeclare a property with other limits or Swagger metadata.
13
+ * Requires `class-transformer` and `class-validator` in your project.
14
+ *
15
+ * * * *
16
+ * Example:
17
+ * ```typescript
18
+ * import { Page, PageQuery } from '@telperion/nest-pack/pagination';
19
+ *
20
+ * @Get()
21
+ * async list(@Query() query: PageQuery): Promise<Page<User>> {
22
+ * const [items, total] = await this.users.findAndCount({
23
+ * where: query.search ? { name: ILike(PageQuery.likePattern(query.search)) } : {},
24
+ * ...PageQuery.skipTake(query),
25
+ * });
26
+ *
27
+ * return Page.of(items, total, query);
28
+ * }
29
+ * ```
30
+ * * * *
31
+ */
32
+ declare class PageQuery {
33
+ /**
34
+ * The page, from 1
35
+ */
36
+ page: number;
37
+ /**
38
+ * The items per page, from 1 to 100
39
+ */
40
+ pageSize: number;
41
+ /**
42
+ * Free-text search, at most 200 characters
43
+ */
44
+ search?: string;
45
+ /**
46
+ * The rows to skip and to take for a page, as TypeORM's and Prisma's `skip` and `take` options
47
+ *
48
+ * @param query The page and page size
49
+ */
50
+ static skipTake(query: Pick<PageQuery, 'page' | 'pageSize'>): {
51
+ skip: number;
52
+ take: number;
53
+ };
54
+ /**
55
+ * A `LIKE`/`ILIKE` pattern matching values that contain the search text literally:
56
+ * `\`, `%` and `_` are escaped with `\` (the default escape character of PostgreSQL and MySQL), and the text is wrapped in `%`
57
+ *
58
+ * @param search The search text
59
+ */
60
+ static likePattern(search: string): string;
61
+ }
62
+
63
+ export { PageQuery };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * #### Page Query
3
+ *
4
+ * Query DTO of a paged list endpoint: `?page=2&pageSize=50&search=ada`.
5
+ * Query values arrive as strings and are converted to numbers (`@Type(() => Number)`), so use it with
6
+ * `ValidationPipe({ transform: true })`; missing values keep their defaults.
7
+ *
8
+ * - `page`: integer, at least 1, default 1
9
+ * - `pageSize`: integer from 1 to 100, default 25
10
+ * - `search`: optional free text, at most 200 characters
11
+ *
12
+ * Extend it to add filters or to redeclare a property with other limits or Swagger metadata.
13
+ * Requires `class-transformer` and `class-validator` in your project.
14
+ *
15
+ * * * *
16
+ * Example:
17
+ * ```typescript
18
+ * import { Page, PageQuery } from '@telperion/nest-pack/pagination';
19
+ *
20
+ * @Get()
21
+ * async list(@Query() query: PageQuery): Promise<Page<User>> {
22
+ * const [items, total] = await this.users.findAndCount({
23
+ * where: query.search ? { name: ILike(PageQuery.likePattern(query.search)) } : {},
24
+ * ...PageQuery.skipTake(query),
25
+ * });
26
+ *
27
+ * return Page.of(items, total, query);
28
+ * }
29
+ * ```
30
+ * * * *
31
+ */
32
+ declare class PageQuery {
33
+ /**
34
+ * The page, from 1
35
+ */
36
+ page: number;
37
+ /**
38
+ * The items per page, from 1 to 100
39
+ */
40
+ pageSize: number;
41
+ /**
42
+ * Free-text search, at most 200 characters
43
+ */
44
+ search?: string;
45
+ /**
46
+ * The rows to skip and to take for a page, as TypeORM's and Prisma's `skip` and `take` options
47
+ *
48
+ * @param query The page and page size
49
+ */
50
+ static skipTake(query: Pick<PageQuery, 'page' | 'pageSize'>): {
51
+ skip: number;
52
+ take: number;
53
+ };
54
+ /**
55
+ * A `LIKE`/`ILIKE` pattern matching values that contain the search text literally:
56
+ * `\`, `%` and `_` are escaped with `\` (the default escape character of PostgreSQL and MySQL), and the text is wrapped in `%`
57
+ *
58
+ * @param search The search text
59
+ */
60
+ static likePattern(search: string): string;
61
+ }
62
+
63
+ export { PageQuery };
@@ -0,0 +1,90 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Type } from 'class-transformer';
3
+ import { IsOptional, IsInt, Min, Max, IsString, MaxLength } from 'class-validator';
4
+
5
+ /**
6
+ * #### Page Query
7
+ *
8
+ * Query DTO of a paged list endpoint: `?page=2&pageSize=50&search=ada`.
9
+ * Query values arrive as strings and are converted to numbers (`@Type(() => Number)`), so use it with
10
+ * `ValidationPipe({ transform: true })`; missing values keep their defaults.
11
+ *
12
+ * - `page`: integer, at least 1, default 1
13
+ * - `pageSize`: integer from 1 to 100, default 25
14
+ * - `search`: optional free text, at most 200 characters
15
+ *
16
+ * Extend it to add filters or to redeclare a property with other limits or Swagger metadata.
17
+ * Requires `class-transformer` and `class-validator` in your project.
18
+ *
19
+ * * * *
20
+ * Example:
21
+ * ```typescript
22
+ * import { Page, PageQuery } from '@telperion/nest-pack/pagination';
23
+ *
24
+ * @Get()
25
+ * async list(@Query() query: PageQuery): Promise<Page<User>> {
26
+ * const [items, total] = await this.users.findAndCount({
27
+ * where: query.search ? { name: ILike(PageQuery.likePattern(query.search)) } : {},
28
+ * ...PageQuery.skipTake(query),
29
+ * });
30
+ *
31
+ * return Page.of(items, total, query);
32
+ * }
33
+ * ```
34
+ * * * *
35
+ */
36
+ class PageQuery {
37
+ /**
38
+ * The page, from 1
39
+ */
40
+ page = 1;
41
+ /**
42
+ * The items per page, from 1 to 100
43
+ */
44
+ pageSize = 25;
45
+ /**
46
+ * Free-text search, at most 200 characters
47
+ */
48
+ search;
49
+ /**
50
+ * The rows to skip and to take for a page, as TypeORM's and Prisma's `skip` and `take` options
51
+ *
52
+ * @param query The page and page size
53
+ */
54
+ static skipTake(query) {
55
+ return { skip: (query.page - 1) * query.pageSize, take: query.pageSize };
56
+ }
57
+ /**
58
+ * A `LIKE`/`ILIKE` pattern matching values that contain the search text literally:
59
+ * `\`, `%` and `_` are escaped with `\` (the default escape character of PostgreSQL and MySQL), and the text is wrapped in `%`
60
+ *
61
+ * @param search The search text
62
+ */
63
+ static likePattern(search) {
64
+ return `%${search.replace(/[\\%_]/g, character => `\\${character}`)}%`;
65
+ }
66
+ }
67
+ __decorate([
68
+ IsOptional(),
69
+ Type(() => Number),
70
+ IsInt(),
71
+ Min(1),
72
+ __metadata("design:type", Number)
73
+ ], PageQuery.prototype, "page", void 0);
74
+ __decorate([
75
+ IsOptional(),
76
+ Type(() => Number),
77
+ IsInt(),
78
+ Min(1),
79
+ Max(100),
80
+ __metadata("design:type", Number)
81
+ ], PageQuery.prototype, "pageSize", void 0);
82
+ __decorate([
83
+ IsOptional(),
84
+ IsString(),
85
+ MaxLength(200),
86
+ __metadata("design:type", String)
87
+ ], PageQuery.prototype, "search", void 0);
88
+
89
+ export { PageQuery };
90
+ //# sourceMappingURL=page-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-query.js","sources":["../../../../libs/nest-pack/src/pagination/page-query.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;MACU,SAAS,CAAA;AACpB;;AAEG;IAKH,IAAI,GAAW,CAAC;AAEhB;;AAEG;IAMH,QAAQ,GAAW,EAAE;AAErB;;AAEG;AAIH,IAAA,MAAM;AAEN;;;;AAIG;IACH,OAAO,QAAQ,CAAC,KAA2C,EAAA;QACzD,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE;IAC1E;AAEA;;;;;AAKG;IACH,OAAO,WAAW,CAAC,MAAc,EAAA;AAC/B,QAAA,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,IAAI,CAAA,EAAA,EAAK,SAAS,CAAA,CAAE,CAAC,GAAG;IACxE;AACD;AAtCC,UAAA,CAAA;AAJC,IAAA,UAAU,EAAE;AACZ,IAAA,IAAI,CAAC,MAAM,MAAM,CAAC;AAClB,IAAA,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;;AACU,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAUjB,UAAA,CAAA;AALC,IAAA,UAAU,EAAE;AACZ,IAAA,IAAI,CAAC,MAAM,MAAM,CAAC;AAClB,IAAA,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;IACN,GAAG,CAAC,GAAG,CAAC;;AACa,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAQtB,UAAA,CAAA;AAHC,IAAA,UAAU,EAAE;AACZ,IAAA,QAAQ,EAAE;IACV,SAAS,CAAC,GAAG,CAAC;;AACC,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;;;;"}
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * #### Page
5
+ *
6
+ * Response of a paged list endpoint: the items of one page, the total count of matching items,
7
+ * and the page and page size of the request. Create it with {@link Page.of}.
8
+ *
9
+ * * * *
10
+ * Example:
11
+ * ```typescript
12
+ * const [items, total] = await this.users.findAndCount(PageQuery.skipTake(query));
13
+ *
14
+ * return Page.of(items, total, query); // { items, total, page: 2, pageSize: 25 }
15
+ * ```
16
+ * * * *
17
+ */
18
+ class Page {
19
+ items;
20
+ total;
21
+ page;
22
+ pageSize;
23
+ /**
24
+ * @param items The items of this page
25
+ * @param total The count of all matching items, on every page
26
+ * @param page The page, from 1
27
+ * @param pageSize The items per page
28
+ */
29
+ constructor(items, total, page, pageSize) {
30
+ this.items = items;
31
+ this.total = total;
32
+ this.page = page;
33
+ this.pageSize = pageSize;
34
+ }
35
+ /**
36
+ * The page of `items` for a query
37
+ *
38
+ * @param items The items of this page
39
+ * @param total The count of all matching items, on every page
40
+ * @param query The query the page answers
41
+ */
42
+ static of(items, total, query) {
43
+ return new Page(items, total, query.page, query.pageSize);
44
+ }
45
+ }
46
+
47
+ exports.Page = Page;
48
+ //# sourceMappingURL=page.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.cjs","sources":["../../../../libs/nest-pack/src/pagination/page.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;AAcG;MACU,IAAI,CAAA;AAQJ,IAAA,KAAA;AACA,IAAA,KAAA;AACA,IAAA,IAAA;AACA,IAAA,QAAA;AAVX;;;;;AAKG;AACH,IAAA,WAAA,CACW,KAAU,EACV,KAAa,EACb,IAAY,EACZ,QAAgB,EAAA;QAHhB,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,QAAQ,GAAR,QAAQ;IAChB;AAEH;;;;;;AAMG;AACH,IAAA,OAAO,EAAE,CAAI,KAAU,EAAE,KAAa,EAAE,KAA2C,EAAA;AACjF,QAAA,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC3D;AACD;;;;"}
@@ -0,0 +1,40 @@
1
+ import { PageQuery } from './page-query.cjs';
2
+
3
+ /**
4
+ * #### Page
5
+ *
6
+ * Response of a paged list endpoint: the items of one page, the total count of matching items,
7
+ * and the page and page size of the request. Create it with {@link Page.of}.
8
+ *
9
+ * * * *
10
+ * Example:
11
+ * ```typescript
12
+ * const [items, total] = await this.users.findAndCount(PageQuery.skipTake(query));
13
+ *
14
+ * return Page.of(items, total, query); // { items, total, page: 2, pageSize: 25 }
15
+ * ```
16
+ * * * *
17
+ */
18
+ declare class Page<T> {
19
+ readonly items: T[];
20
+ readonly total: number;
21
+ readonly page: number;
22
+ readonly pageSize: number;
23
+ /**
24
+ * @param items The items of this page
25
+ * @param total The count of all matching items, on every page
26
+ * @param page The page, from 1
27
+ * @param pageSize The items per page
28
+ */
29
+ constructor(items: T[], total: number, page: number, pageSize: number);
30
+ /**
31
+ * The page of `items` for a query
32
+ *
33
+ * @param items The items of this page
34
+ * @param total The count of all matching items, on every page
35
+ * @param query The query the page answers
36
+ */
37
+ static of<T>(items: T[], total: number, query: Pick<PageQuery, 'page' | 'pageSize'>): Page<T>;
38
+ }
39
+
40
+ export { Page };
@@ -0,0 +1,40 @@
1
+ import { PageQuery } from './page-query.js';
2
+
3
+ /**
4
+ * #### Page
5
+ *
6
+ * Response of a paged list endpoint: the items of one page, the total count of matching items,
7
+ * and the page and page size of the request. Create it with {@link Page.of}.
8
+ *
9
+ * * * *
10
+ * Example:
11
+ * ```typescript
12
+ * const [items, total] = await this.users.findAndCount(PageQuery.skipTake(query));
13
+ *
14
+ * return Page.of(items, total, query); // { items, total, page: 2, pageSize: 25 }
15
+ * ```
16
+ * * * *
17
+ */
18
+ declare class Page<T> {
19
+ readonly items: T[];
20
+ readonly total: number;
21
+ readonly page: number;
22
+ readonly pageSize: number;
23
+ /**
24
+ * @param items The items of this page
25
+ * @param total The count of all matching items, on every page
26
+ * @param page The page, from 1
27
+ * @param pageSize The items per page
28
+ */
29
+ constructor(items: T[], total: number, page: number, pageSize: number);
30
+ /**
31
+ * The page of `items` for a query
32
+ *
33
+ * @param items The items of this page
34
+ * @param total The count of all matching items, on every page
35
+ * @param query The query the page answers
36
+ */
37
+ static of<T>(items: T[], total: number, query: Pick<PageQuery, 'page' | 'pageSize'>): Page<T>;
38
+ }
39
+
40
+ export { Page };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * #### Page
3
+ *
4
+ * Response of a paged list endpoint: the items of one page, the total count of matching items,
5
+ * and the page and page size of the request. Create it with {@link Page.of}.
6
+ *
7
+ * * * *
8
+ * Example:
9
+ * ```typescript
10
+ * const [items, total] = await this.users.findAndCount(PageQuery.skipTake(query));
11
+ *
12
+ * return Page.of(items, total, query); // { items, total, page: 2, pageSize: 25 }
13
+ * ```
14
+ * * * *
15
+ */
16
+ class Page {
17
+ items;
18
+ total;
19
+ page;
20
+ pageSize;
21
+ /**
22
+ * @param items The items of this page
23
+ * @param total The count of all matching items, on every page
24
+ * @param page The page, from 1
25
+ * @param pageSize The items per page
26
+ */
27
+ constructor(items, total, page, pageSize) {
28
+ this.items = items;
29
+ this.total = total;
30
+ this.page = page;
31
+ this.pageSize = pageSize;
32
+ }
33
+ /**
34
+ * The page of `items` for a query
35
+ *
36
+ * @param items The items of this page
37
+ * @param total The count of all matching items, on every page
38
+ * @param query The query the page answers
39
+ */
40
+ static of(items, total, query) {
41
+ return new Page(items, total, query.page, query.pageSize);
42
+ }
43
+ }
44
+
45
+ export { Page };
46
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sources":["../../../../libs/nest-pack/src/pagination/page.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;AAcG;MACU,IAAI,CAAA;AAQJ,IAAA,KAAA;AACA,IAAA,KAAA;AACA,IAAA,IAAA;AACA,IAAA,QAAA;AAVX;;;;;AAKG;AACH,IAAA,WAAA,CACW,KAAU,EACV,KAAa,EACb,IAAY,EACZ,QAAgB,EAAA;QAHhB,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,QAAQ,GAAR,QAAQ;IAChB;AAEH;;;;;;AAMG;AACH,IAAA,OAAO,EAAE,CAAI,KAAU,EAAE,KAAa,EAAE,KAA2C,EAAA;AACjF,QAAA,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC3D;AACD;;;;"}