glasswork 0.5.0 → 0.6.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.
- package/dist/authorization/ability-middleware.d.ts +61 -0
- package/dist/authorization/ability-middleware.d.ts.map +1 -0
- package/dist/authorization/ability-middleware.js +74 -0
- package/dist/authorization/ability-middleware.js.map +1 -0
- package/dist/authorization/index.d.ts +46 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +46 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/route-helpers.d.ts +106 -0
- package/dist/authorization/route-helpers.d.ts.map +1 -0
- package/dist/authorization/route-helpers.js +136 -0
- package/dist/authorization/route-helpers.js.map +1 -0
- package/dist/authorization/service-proxy.d.ts +59 -0
- package/dist/authorization/service-proxy.d.ts.map +1 -0
- package/dist/authorization/service-proxy.js +110 -0
- package/dist/authorization/service-proxy.js.map +1 -0
- package/dist/authorization/types.d.ts +58 -0
- package/dist/authorization/types.d.ts.map +1 -0
- package/dist/authorization/types.js +7 -0
- package/dist/authorization/types.js.map +1 -0
- package/dist/hooks/authorization-hook.d.ts +100 -0
- package/dist/hooks/authorization-hook.d.ts.map +1 -0
- package/dist/hooks/authorization-hook.js +93 -0
- package/dist/hooks/authorization-hook.js.map +1 -0
- package/dist/hooks/index.d.ts +54 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +55 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/service-hooks.d.ts +82 -0
- package/dist/hooks/service-hooks.d.ts.map +1 -0
- package/dist/hooks/service-hooks.js +158 -0
- package/dist/hooks/service-hooks.js.map +1 -0
- package/dist/hooks/types.d.ts +151 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +2 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/list-query/builder.d.ts +9 -2
- package/dist/list-query/builder.d.ts.map +1 -1
- package/dist/list-query/builder.js +86 -5
- package/dist/list-query/builder.js.map +1 -1
- package/dist/list-query/index.d.ts +1 -1
- package/dist/list-query/index.d.ts.map +1 -1
- package/dist/list-query/types.d.ts +26 -0
- package/dist/list-query/types.d.ts.map +1 -1
- package/dist/list-query/validator.d.ts +2 -0
- package/dist/list-query/validator.d.ts.map +1 -1
- package/dist/list-query/validator.js.map +1 -1
- package/dist/openapi/openapi-transformer.d.ts +0 -5
- package/dist/openapi/openapi-transformer.d.ts.map +1 -1
- package/dist/openapi/openapi-transformer.js +0 -5
- package/dist/openapi/openapi-transformer.js.map +1 -1
- package/dist/utils/pagination.d.ts +48 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +42 -0
- package/dist/utils/pagination.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination input parameters
|
|
4
|
+
*/
|
|
5
|
+
export interface PaginationInput {
|
|
6
|
+
page: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Paginated output structure
|
|
11
|
+
*/
|
|
12
|
+
export interface PaginatedOutput<T> {
|
|
13
|
+
data: T[];
|
|
14
|
+
total: number;
|
|
15
|
+
page: number;
|
|
16
|
+
limit: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Execute a paginated query and set response headers.
|
|
20
|
+
*
|
|
21
|
+
* This helper extracts pagination parameters from the query string,
|
|
22
|
+
* executes the provided function, and sets the appropriate response headers.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of items in the result
|
|
25
|
+
* @param c - Hono context
|
|
26
|
+
* @param fn - Function that executes the paginated query
|
|
27
|
+
* @returns Array of items (headers are set as side effect)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* router.get('/users', route({
|
|
32
|
+
* paginate: true,
|
|
33
|
+
* handler: async ({ context }) => {
|
|
34
|
+
* return await paginate(context, (p) => userService.getUsers(p));
|
|
35
|
+
* }
|
|
36
|
+
* }));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function paginate<T>(c: Context, fn: (p: PaginationInput) => Promise<PaginatedOutput<T>>): Promise<T[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Extract pagination parameters from Hono context.
|
|
42
|
+
*
|
|
43
|
+
* @param c - Hono context
|
|
44
|
+
* @param defaultLimit - Default limit if not provided (default: 100)
|
|
45
|
+
* @returns Pagination input with page and limit
|
|
46
|
+
*/
|
|
47
|
+
export declare function paginationInput(c: Context, defaultLimit?: number): PaginationInput;
|
|
48
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/utils/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,CAAC,EAAE,OAAO,EACV,EAAE,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GACtD,OAAO,CAAC,CAAC,EAAE,CAAC,CASd;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,SAAM,GAAG,eAAe,CAI/E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a paginated query and set response headers.
|
|
3
|
+
*
|
|
4
|
+
* This helper extracts pagination parameters from the query string,
|
|
5
|
+
* executes the provided function, and sets the appropriate response headers.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of items in the result
|
|
8
|
+
* @param c - Hono context
|
|
9
|
+
* @param fn - Function that executes the paginated query
|
|
10
|
+
* @returns Array of items (headers are set as side effect)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* router.get('/users', route({
|
|
15
|
+
* paginate: true,
|
|
16
|
+
* handler: async ({ context }) => {
|
|
17
|
+
* return await paginate(context, (p) => userService.getUsers(p));
|
|
18
|
+
* }
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export async function paginate(c, fn) {
|
|
23
|
+
const pagination = paginationInput(c);
|
|
24
|
+
const result = await fn(pagination);
|
|
25
|
+
c.header('X-Total-Count', result.total.toString());
|
|
26
|
+
c.header('X-Page', result.page.toString());
|
|
27
|
+
c.header('X-Limit', result.limit.toString());
|
|
28
|
+
return result.data;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extract pagination parameters from Hono context.
|
|
32
|
+
*
|
|
33
|
+
* @param c - Hono context
|
|
34
|
+
* @param defaultLimit - Default limit if not provided (default: 100)
|
|
35
|
+
* @returns Pagination input with page and limit
|
|
36
|
+
*/
|
|
37
|
+
export function paginationInput(c, defaultLimit = 100) {
|
|
38
|
+
const page = Number.parseInt(c.req.query('page') ?? '1', 10);
|
|
39
|
+
const limit = Number.parseInt(c.req.query('limit') ?? defaultLimit.toString(), 10);
|
|
40
|
+
return { page, limit };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/utils/pagination.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,CAAU,EACV,EAAuD;IAEvD,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC;IAEpC,CAAC,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE7C,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,CAAU,EAAE,YAAY,GAAG,GAAG;IAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IACnF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC"}
|