glasswork 0.13.3 → 1.0.1
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 +80 -0
- package/README.md +6 -2
- package/dist/auth/abilities.d.ts +9 -6
- package/dist/auth/abilities.d.ts.map +1 -1
- package/dist/auth/abilities.js +15 -19
- package/dist/auth/abilities.js.map +1 -1
- package/dist/auth/assert.d.ts +3 -3
- package/dist/auth/assert.d.ts.map +1 -1
- package/dist/auth/casl-bridge.d.ts +19 -0
- package/dist/auth/casl-bridge.d.ts.map +1 -0
- package/dist/auth/casl-bridge.js +29 -0
- package/dist/auth/casl-bridge.js.map +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/middleware.d.ts +3 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +2 -2
- package/dist/auth/middleware.js.map +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/core/bootstrap.d.ts +0 -17
- package/dist/core/bootstrap.d.ts.map +1 -1
- package/dist/core/bootstrap.js +4 -240
- package/dist/core/bootstrap.js.map +1 -1
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lifecycle.d.ts +7 -0
- package/dist/core/lifecycle.d.ts.map +1 -0
- package/dist/core/lifecycle.js +28 -0
- package/dist/core/lifecycle.js.map +1 -0
- package/dist/core/module-graph.d.ts +21 -0
- package/dist/core/module-graph.d.ts.map +1 -0
- package/dist/core/module-graph.js +169 -0
- package/dist/core/module-graph.js.map +1 -0
- package/dist/core/route-factory.d.ts +20 -0
- package/dist/core/route-factory.d.ts.map +1 -0
- package/dist/core/route-factory.js +2 -0
- package/dist/core/route-factory.js.map +1 -0
- package/dist/core/types.d.ts +4 -14
- package/dist/core/types.d.ts.map +1 -1
- package/dist/email/compiler/compile-templates.d.ts +3 -8
- package/dist/email/compiler/compile-templates.d.ts.map +1 -1
- package/dist/email/compiler/compile-templates.js +3 -3
- package/dist/email/compiler/compile-templates.js.map +1 -1
- package/dist/email/compiler/compiler.d.ts +5 -2
- package/dist/email/compiler/compiler.d.ts.map +1 -1
- package/dist/email/compiler/compiler.js +2 -21
- package/dist/email/compiler/compiler.js.map +1 -1
- package/dist/email/transports/ses-transport.d.ts.map +1 -1
- package/dist/email/transports/ses-transport.js +11 -18
- package/dist/email/transports/ses-transport.js.map +1 -1
- package/dist/email/webhooks/handler-factory.d.ts +1 -1
- package/dist/email/webhooks/handler-factory.js +1 -1
- package/dist/email/webhooks/notification-parser.d.ts +1 -1
- package/dist/email/webhooks/notification-parser.js +1 -1
- package/dist/email/webhooks/signature-verification.d.ts +1 -1
- package/dist/email/webhooks/signature-verification.js +1 -1
- package/dist/email/webhooks/subscription-handler.d.ts +1 -1
- package/dist/email/webhooks/subscription-handler.js +1 -1
- package/dist/hono-context.d.ts +13 -0
- package/dist/hono-context.d.ts.map +1 -0
- package/dist/hono-context.js +2 -0
- package/dist/hono-context.js.map +1 -0
- package/dist/http/index.d.ts +18 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +15 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/route-authorization.d.ts +9 -0
- package/dist/http/route-authorization.d.ts.map +1 -0
- package/dist/http/route-authorization.js +19 -0
- package/dist/http/route-authorization.js.map +1 -0
- package/dist/http/route-context.d.ts +8 -0
- package/dist/http/route-context.d.ts.map +1 -0
- package/dist/http/route-context.js +26 -0
- package/dist/http/route-context.js.map +1 -0
- package/dist/http/route-helpers.d.ts +6 -419
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +7 -462
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/http/route-openapi-context.d.ts +27 -0
- package/dist/http/route-openapi-context.d.ts.map +1 -0
- package/dist/http/route-openapi-context.js +16 -0
- package/dist/http/route-openapi-context.js.map +1 -0
- package/dist/http/route-openapi.d.ts +5 -0
- package/dist/http/route-openapi.d.ts.map +1 -0
- package/dist/http/route-openapi.js +112 -0
- package/dist/http/route-openapi.js.map +1 -0
- package/dist/http/route-response.d.ts +5 -0
- package/dist/http/route-response.d.ts.map +1 -0
- package/dist/http/route-response.js +78 -0
- package/dist/http/route-response.js.map +1 -0
- package/dist/http/route-types.d.ts +93 -0
- package/dist/http/route-types.d.ts.map +1 -0
- package/dist/http/route-types.js +22 -0
- package/dist/http/route-types.js.map +1 -0
- package/dist/http/route-validation.d.ts +11 -0
- package/dist/http/route-validation.d.ts.map +1 -0
- package/dist/http/route-validation.js +24 -0
- package/dist/http/route-validation.js.map +1 -0
- package/dist/index.d.ts +7 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -65
- package/dist/index.js.map +1 -1
- package/dist/jobs/drivers/eventbridge-scheduler-driver.d.ts.map +1 -1
- package/dist/jobs/drivers/eventbridge-scheduler-driver.js +1 -3
- package/dist/jobs/drivers/eventbridge-scheduler-driver.js.map +1 -1
- package/dist/jobs/drivers/sqs-driver.d.ts +1 -1
- package/dist/jobs/drivers/sqs-driver.d.ts.map +1 -1
- package/dist/jobs/drivers/sqs-driver.js +1 -3
- package/dist/jobs/drivers/sqs-driver.js.map +1 -1
- package/dist/jobs/worker.d.ts.map +1 -1
- package/dist/jobs/worker.js +3 -14
- package/dist/jobs/worker.js.map +1 -1
- package/dist/list-query/builder.d.ts +26 -5
- package/dist/list-query/builder.d.ts.map +1 -1
- package/dist/list-query/builder.js +18 -10
- package/dist/list-query/builder.js.map +1 -1
- package/dist/list-query/casl.d.ts +20 -4
- package/dist/list-query/casl.d.ts.map +1 -1
- package/dist/list-query/casl.js +3 -12
- package/dist/list-query/casl.js.map +1 -1
- package/dist/list-query/filter-value-schemas.d.ts +16 -0
- package/dist/list-query/filter-value-schemas.d.ts.map +1 -0
- package/dist/list-query/filter-value-schemas.js +46 -0
- package/dist/list-query/filter-value-schemas.js.map +1 -0
- package/dist/list-query/index.d.ts +7 -1
- package/dist/list-query/index.d.ts.map +1 -1
- package/dist/list-query/index.js +6 -2
- package/dist/list-query/index.js.map +1 -1
- package/dist/list-query/list-params.d.ts +17 -0
- package/dist/list-query/list-params.d.ts.map +1 -0
- package/dist/list-query/list-params.js +2 -0
- package/dist/list-query/list-params.js.map +1 -0
- package/dist/list-query/parse-filter-values.d.ts +21 -0
- package/dist/list-query/parse-filter-values.d.ts.map +1 -0
- package/dist/list-query/parse-filter-values.js +177 -0
- package/dist/list-query/parse-filter-values.js.map +1 -0
- package/dist/list-query/prisma-builder.d.ts.map +1 -1
- package/dist/list-query/prisma-builder.js +3 -50
- package/dist/list-query/prisma-builder.js.map +1 -1
- package/dist/list-query/prisma-executor.d.ts +63 -0
- package/dist/list-query/prisma-executor.d.ts.map +1 -0
- package/dist/list-query/prisma-executor.js +88 -0
- package/dist/list-query/prisma-executor.js.map +1 -0
- package/dist/list-query/schema-helpers.d.ts +37 -17
- package/dist/list-query/schema-helpers.d.ts.map +1 -1
- package/dist/list-query/schema-helpers.js +87 -24
- package/dist/list-query/schema-helpers.js.map +1 -1
- package/dist/list-query/sort-field-types.d.ts +21 -0
- package/dist/list-query/sort-field-types.d.ts.map +1 -0
- package/dist/list-query/sort-field-types.js +2 -0
- package/dist/list-query/sort-field-types.js.map +1 -0
- package/dist/list-query/unrestricted-schemas.d.ts +13 -0
- package/dist/list-query/unrestricted-schemas.d.ts.map +1 -0
- package/dist/list-query/unrestricted-schemas.js +9 -0
- package/dist/list-query/unrestricted-schemas.js.map +1 -0
- package/dist/list-query/validator.d.ts +2 -2
- package/dist/list-query/validator.d.ts.map +1 -1
- package/dist/observability/exception-tracking.d.ts +5 -4
- package/dist/observability/exception-tracking.d.ts.map +1 -1
- package/dist/observability/exception-tracking.js +4 -3
- package/dist/observability/exception-tracking.js.map +1 -1
- package/dist/observability/index.d.ts +8 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +8 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/pino-logger.d.ts +3 -3
- package/dist/observability/pino-logger.js +3 -3
- package/dist/observability/request-context.d.ts +4 -4
- package/dist/observability/request-context.js +4 -4
- package/package.json +93 -53
- package/dist/authorization/ability-middleware.d.ts +0 -61
- package/dist/authorization/ability-middleware.d.ts.map +0 -1
- package/dist/authorization/ability-middleware.js +0 -74
- package/dist/authorization/ability-middleware.js.map +0 -1
- package/dist/authorization/index.d.ts +0 -46
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js +0 -46
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/route-helpers.d.ts +0 -106
- package/dist/authorization/route-helpers.d.ts.map +0 -1
- package/dist/authorization/route-helpers.js +0 -136
- package/dist/authorization/route-helpers.js.map +0 -1
- package/dist/authorization/service-proxy.d.ts +0 -59
- package/dist/authorization/service-proxy.d.ts.map +0 -1
- package/dist/authorization/service-proxy.js +0 -110
- package/dist/authorization/service-proxy.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -58
- package/dist/authorization/types.d.ts.map +0 -1
- package/dist/authorization/types.js +0 -7
- package/dist/authorization/types.js.map +0 -1
- package/dist/hooks/authorization-hook.d.ts +0 -100
- package/dist/hooks/authorization-hook.d.ts.map +0 -1
- package/dist/hooks/authorization-hook.js +0 -93
- package/dist/hooks/authorization-hook.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -54
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -55
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/service-hooks.d.ts +0 -82
- package/dist/hooks/service-hooks.d.ts.map +0 -1
- package/dist/hooks/service-hooks.js +0 -158
- package/dist/hooks/service-hooks.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -151
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -2
- package/dist/hooks/types.js.map +0 -1
- package/dist/openapi/hooks.d.ts +0 -14
- package/dist/openapi/hooks.d.ts.map +0 -1
- package/dist/openapi/hooks.js +0 -83
- package/dist/openapi/hooks.js.map +0 -1
- package/dist/openapi/openapi-transformer.d.ts +0 -13
- package/dist/openapi/openapi-transformer.d.ts.map +0 -1
- package/dist/openapi/openapi-transformer.js +0 -87
- package/dist/openapi/openapi-transformer.js.map +0 -1
- package/dist/utils/pagination.d.ts +0 -48
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -42
- package/dist/utils/pagination.js.map +0 -1
- package/dist/utils/serialize-dates.d.ts +0 -27
- package/dist/utils/serialize-dates.d.ts.map +0 -1
- package/dist/utils/serialize-dates.js +0 -39
- package/dist/utils/serialize-dates.js.map +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { OpenAPIContext } from './route-openapi-context.js';
|
|
3
|
+
import type { RouteConfig, RouteContext, STATUS_DESCRIPTIONS, ValibotSchema } from './route-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Build the route context for a handler.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildRouteContext<TBody extends ValibotSchema | undefined, TQuery extends ValibotSchema | undefined, TParams extends ValibotSchema | undefined, TResponses extends Partial<Record<keyof typeof STATUS_DESCRIPTIONS, ValibotSchema | undefined>>, TPublic extends boolean, TStrictTypes extends boolean>(c: Context, config: RouteConfig<TBody, TQuery, TParams, TResponses, TPublic, TStrictTypes>, openAPIContext: OpenAPIContext): RouteContext<unknown, unknown, unknown, false>;
|
|
8
|
+
//# sourceMappingURL=route-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-context.d.ts","sourceRoot":"","sources":["../../src/http/route-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,SAAS,aAAa,GAAG,SAAS,EACvC,MAAM,SAAS,aAAa,GAAG,SAAS,EACxC,OAAO,SAAS,aAAa,GAAG,SAAS,EACzC,UAAU,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,mBAAmB,EAAE,aAAa,GAAG,SAAS,CAAC,CAAC,EAC/F,OAAO,SAAS,OAAO,EACvB,YAAY,SAAS,OAAO,EAE5B,CAAC,EAAE,OAAO,EACV,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,EAC9E,cAAc,EAAE,cAAc,GAC7B,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAuBhD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContextAwarePinoLogger } from '../observability/pino-logger.js';
|
|
2
|
+
import { getClientIp } from '../utils/get-client-ip.js';
|
|
3
|
+
import { createLogger } from '../utils/logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Build the route context for a handler.
|
|
6
|
+
*/
|
|
7
|
+
export function buildRouteContext(c, config, openAPIContext) {
|
|
8
|
+
const req = c.req;
|
|
9
|
+
const serviceName = config.tags?.[0] || config.operationId || 'Route';
|
|
10
|
+
const routeLogger = openAPIContext.pino
|
|
11
|
+
? createContextAwarePinoLogger({ pino: openAPIContext.pino, service: serviceName })
|
|
12
|
+
: createLogger(serviceName);
|
|
13
|
+
return {
|
|
14
|
+
...c.var,
|
|
15
|
+
body: req.valid(config.bodyType || 'json'),
|
|
16
|
+
query: req.valid('query'),
|
|
17
|
+
params: req.valid('param'),
|
|
18
|
+
services: c.get('services') || {},
|
|
19
|
+
session: c.get('session'),
|
|
20
|
+
ip: getClientIp(c),
|
|
21
|
+
userAgent: c.req.header('user-agent'),
|
|
22
|
+
logger: routeLogger,
|
|
23
|
+
context: c,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=route-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-context.js","sourceRoot":"","sources":["../../src/http/route-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAC;AAS/D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAQ/B,CAAU,EACV,MAA8E,EAC9E,cAA8B;IAM9B,MAAM,GAAG,GAAG,CAAC,CAAC,GAAkC,CAAC;IACjD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,IAAI,OAAO,CAAC;IACtE,MAAM,WAAW,GAAW,cAAc,CAAC,IAAI;QAC7C,CAAC,CAAC,4BAA4B,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QACnF,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAE9B,OAAO;QACL,GAAG,CAAC,CAAC,GAAG;QACR,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC;QAC1C,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAA2B;QACnD,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAA2B;QACpD,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE;QACjC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;QACzB,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;QAClB,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC;QACrC,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,CAAC;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -1,428 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { type AcceptPrismaTypes, type SerializationConfig } from '../utils/serialize-prisma-types.js';
|
|
8
|
-
/**
|
|
9
|
-
* OpenAPI context stored in Hono app context.
|
|
10
|
-
* Set during bootstrap and used when defining routes.
|
|
11
|
-
*/
|
|
12
|
-
export interface OpenAPIContext {
|
|
13
|
-
processors: OpenAPIResponseProcessor[];
|
|
14
|
-
securitySchemes: string[];
|
|
15
|
-
/**
|
|
16
|
-
* Pino logger instance for creating context-aware loggers in route handlers.
|
|
17
|
-
* When set, enables `logger` property in RouteContext.
|
|
18
|
-
*/
|
|
19
|
-
pino?: PinoLogger;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Set the OpenAPI context for a Hono app instance.
|
|
23
|
-
* This is called during bootstrap and makes processors/schemes available to route definitions.
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export declare function setOpenAPIContext(app: Hono, context: OpenAPIContext): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get the OpenAPI context for a Hono app instance.
|
|
30
|
-
*
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export declare function getOpenAPIContext(app: Hono): OpenAPIContext;
|
|
34
|
-
/**
|
|
35
|
-
* Valibot schema type (compatible with both sync and async schemas)
|
|
36
|
-
*/
|
|
37
|
-
export type ValibotSchema = BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
|
|
38
|
-
/**
|
|
39
|
-
* Helper type to infer the output type from a Valibot schema
|
|
40
|
-
*/
|
|
41
|
-
type InferSchemaType<T> = T extends ValibotSchema ? InferOutput<T> : never;
|
|
42
|
-
/**
|
|
43
|
-
* Helper type to extract and create a union of all 2xx and 3xx response types
|
|
44
|
-
*/
|
|
45
|
-
type InferResponseUnion<TResponses> = {
|
|
46
|
-
[K in keyof TResponses]: K extends 200 | 201 | 202 | 204 | 301 | 302 | 307 | 308 ? TResponses[K] extends ValibotSchema ? InferOutput<TResponses[K]> : never : never;
|
|
47
|
-
}[keyof TResponses];
|
|
48
|
-
/**
|
|
49
|
-
* Helper type to infer the response type from all 2xx and 3xx status code schemas
|
|
50
|
-
* Returns a union type of all defined success/redirect responses (200, 201, 202, 204, 301, 302, 307, 308)
|
|
51
|
-
* Falls back to unknown if no success/redirect responses are defined
|
|
52
|
-
*/
|
|
53
|
-
type InferResponseType<TResponses> = InferResponseUnion<TResponses> extends never ? unknown : InferResponseUnion<TResponses>;
|
|
54
|
-
/**
|
|
55
|
-
* HTTP status codes with descriptions
|
|
56
|
-
*/
|
|
57
|
-
declare const STATUS_DESCRIPTIONS: {
|
|
58
|
-
readonly 200: "Success";
|
|
59
|
-
readonly 201: "Created";
|
|
60
|
-
readonly 202: "Accepted";
|
|
61
|
-
readonly 204: "No Content";
|
|
62
|
-
readonly 301: "Moved Permanently";
|
|
63
|
-
readonly 302: "Found";
|
|
64
|
-
readonly 307: "Temporary Redirect";
|
|
65
|
-
readonly 308: "Permanent Redirect";
|
|
66
|
-
readonly 400: "Bad Request";
|
|
67
|
-
readonly 401: "Unauthorized";
|
|
68
|
-
readonly 403: "Forbidden";
|
|
69
|
-
readonly 404: "Not Found";
|
|
70
|
-
readonly 409: "Conflict";
|
|
71
|
-
readonly 422: "Unprocessable Entity";
|
|
72
|
-
readonly 429: "Too Many Requests";
|
|
73
|
-
readonly 500: "Internal Server Error";
|
|
74
|
-
};
|
|
75
|
-
export type { RouteFactory };
|
|
76
|
-
/**
|
|
77
|
-
* Bound route function type - route() pre-bound to a router's OpenAPI context.
|
|
78
|
-
*/
|
|
79
|
-
export type BoundRouteFunction = <TBody extends ValibotSchema | undefined = undefined, TQuery extends ValibotSchema | undefined = undefined, TParams extends ValibotSchema | undefined = undefined, TResponses extends Partial<Record<keyof typeof STATUS_DESCRIPTIONS, ValibotSchema | undefined>> = Record<never, never>, TPublic extends boolean = false, TStrictTypes extends boolean = false>(config: RouteConfig<TBody, TQuery, TParams, TResponses, TPublic, TStrictTypes>) => RouteHandlers;
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import type { RouteFactory, RouteHandlers } from '../core/types.js';
|
|
3
|
+
import type { BoundRouteFunction, RouteConfig, STATUS_DESCRIPTIONS, ValibotSchema } from './route-types.js';
|
|
4
|
+
export type { OpenAPIContext } from './route-openapi-context.js';
|
|
5
|
+
export { getOpenAPIContext, setOpenAPIContext } from './route-openapi-context.js';
|
|
6
|
+
export type { BoundRouteFunction, RouteConfig, RouteContext, RouteFactory, RouteOpenAPIOptions, ValibotSchema, } from './route-types.js';
|
|
80
7
|
/**
|
|
81
8
|
* Create routes with typed service injection and pre-bound route function.
|
|
82
|
-
*
|
|
83
|
-
* The `route` function passed to your factory is pre-bound to the router's
|
|
84
|
-
* OpenAPI context, so you don't need to pass the router to every route call.
|
|
85
|
-
*
|
|
86
|
-
* @template TServices - The shape of services required by these routes
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* interface AuthRoutesServices {
|
|
91
|
-
* authService: AuthService;
|
|
92
|
-
* userService: UserService;
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* export const authRoutes = createRoutes<AuthRoutesServices>((router, services, route) => {
|
|
96
|
-
* // services.authService is typed as AuthService!
|
|
97
|
-
* // route is pre-bound to this router's OpenAPI context
|
|
98
|
-
* router.post('/login', ...route({
|
|
99
|
-
* body: LoginDto,
|
|
100
|
-
* responses: { 200: SessionDto },
|
|
101
|
-
* handler: async ({ body }) => {
|
|
102
|
-
* return services.authService.login(body);
|
|
103
|
-
* }
|
|
104
|
-
* }));
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
9
|
*/
|
|
108
10
|
export declare function createRoutes<TServices = Record<string, unknown>>(factory: (router: Hono, services: TServices, route: BoundRouteFunction) => void): RouteFactory;
|
|
109
|
-
/**
|
|
110
|
-
* OpenAPI extensions for route configuration
|
|
111
|
-
*/
|
|
112
|
-
export interface RouteOpenAPIOptions extends Partial<Omit<DescribeRouteOptions, 'responses' | 'operationId' | 'tags' | 'summary' | 'description'>> {
|
|
113
|
-
/**
|
|
114
|
-
* Response headers to document in OpenAPI spec.
|
|
115
|
-
*
|
|
116
|
-
* Headers reference components defined in your OpenAPI documentation.
|
|
117
|
-
* Use array format for headers on all responses, or object format for status-specific headers.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* // Simple: applies to all responses
|
|
122
|
-
* responseHeaders: ['Api-Version', 'Server-Timing']
|
|
123
|
-
*
|
|
124
|
-
* // Flexible: status-code specific
|
|
125
|
-
* responseHeaders: {
|
|
126
|
-
* '200': ['X-Total-Count', 'X-Total-Pages'],
|
|
127
|
-
* 'default': ['Api-Version']
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
responseHeaders?: string[] | Record<string, string[]>;
|
|
132
|
-
/**
|
|
133
|
-
* Exclude this route from the OpenAPI specification.
|
|
134
|
-
* Useful for internal or hidden endpoints.
|
|
135
|
-
*/
|
|
136
|
-
exclude?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Mark this route as deprecated.
|
|
139
|
-
*/
|
|
140
|
-
deprecated?: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* External documentation for this route.
|
|
143
|
-
*/
|
|
144
|
-
docs?: {
|
|
145
|
-
description?: string;
|
|
146
|
-
url: string;
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Binary response content type for file download endpoints.
|
|
150
|
-
* When set, documents the success response as binary content instead of JSON.
|
|
151
|
-
* Handler should return a raw Response object.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* router.get('/files/:id', ...route({
|
|
156
|
-
* params: v.object({ id: v.string() }),
|
|
157
|
-
* openapi: {
|
|
158
|
-
* binaryResponse: {
|
|
159
|
-
* contentType: 'application/pdf',
|
|
160
|
-
* description: 'PDF document download',
|
|
161
|
-
* },
|
|
162
|
-
* },
|
|
163
|
-
* handler: async ({ params }) => {
|
|
164
|
-
* const stream = await getFileStream(params.id);
|
|
165
|
-
* return new Response(stream, {
|
|
166
|
-
* headers: { 'Content-Type': 'application/pdf' }
|
|
167
|
-
* });
|
|
168
|
-
* },
|
|
169
|
-
* }));
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
binaryResponse?: {
|
|
173
|
-
/** MIME type (e.g., 'application/octet-stream', 'application/pdf', 'image/png') */
|
|
174
|
-
contentType: string;
|
|
175
|
-
/** Optional description for the response */
|
|
176
|
-
description?: string;
|
|
177
|
-
/** HTTP status code (default: 200) */
|
|
178
|
-
statusCode?: number;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Route configuration with automatic type inference from Valibot schemas.
|
|
183
|
-
*
|
|
184
|
-
* Extends `RouteConfigExtensions` which can be augmented by framework users
|
|
185
|
-
* to add custom properties processed by custom OpenAPI response processors.
|
|
186
|
-
*
|
|
187
|
-
* @template TBody - The body schema (automatically inferred)
|
|
188
|
-
* @template TResponses - The responses object (automatically inferred)
|
|
189
|
-
* @template TPublic - Whether the route is public (affects session typing)
|
|
190
|
-
* @template TStrictTypes - Whether to enforce strict return types (no automatic Prisma type acceptance)
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```typescript
|
|
194
|
-
* // Extend RouteConfigExtensions for custom properties
|
|
195
|
-
* declare module 'glasswork' {
|
|
196
|
-
* interface RouteConfigExtensions {
|
|
197
|
-
* serverTiming?: boolean;
|
|
198
|
-
* }
|
|
199
|
-
* }
|
|
200
|
-
*
|
|
201
|
-
* // Use in routes
|
|
202
|
-
* route({
|
|
203
|
-
* serverTiming: true,
|
|
204
|
-
* handler: ...
|
|
205
|
-
* });
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
export interface RouteConfig<TBody extends ValibotSchema | undefined = undefined, TQuery extends ValibotSchema | undefined = undefined, TParams extends ValibotSchema | undefined = undefined, TResponses extends Partial<Record<keyof typeof STATUS_DESCRIPTIONS, ValibotSchema | undefined>> = Record<never, never>, TPublic extends boolean = false, TStrictTypes extends boolean = false> extends RouteConfigExtensions {
|
|
209
|
-
tags?: string[];
|
|
210
|
-
summary?: string;
|
|
211
|
-
description?: string;
|
|
212
|
-
operationId?: string;
|
|
213
|
-
/**
|
|
214
|
-
* Whether this is a public route (no authentication required)
|
|
215
|
-
* - false (default): Session is required and typed as non-nullable
|
|
216
|
-
* - true: Session is optional and typed as nullable
|
|
217
|
-
*/
|
|
218
|
-
public?: TPublic;
|
|
219
|
-
body?: TBody;
|
|
220
|
-
/**
|
|
221
|
-
* Content type for request body validation.
|
|
222
|
-
* - 'json': application/json (default)
|
|
223
|
-
* - 'form': application/x-www-form-urlencoded or multipart/form-data
|
|
224
|
-
*/
|
|
225
|
-
bodyType?: 'json' | 'form';
|
|
226
|
-
query?: TQuery;
|
|
227
|
-
params?: TParams;
|
|
228
|
-
responses?: TResponses;
|
|
229
|
-
/**
|
|
230
|
-
* OpenAPI documentation options for this route
|
|
231
|
-
*/
|
|
232
|
-
openapi?: RouteOpenAPIOptions;
|
|
233
|
-
/**
|
|
234
|
-
* Custom middleware to apply before validation and handler
|
|
235
|
-
*/
|
|
236
|
-
middleware?: MiddlewareHandler[];
|
|
237
|
-
/**
|
|
238
|
-
* Enforce strict return types (requires explicit type assertions for Prisma objects)
|
|
239
|
-
*
|
|
240
|
-
* - false (default): Handler can return Prisma types (Date/Decimal) which are auto-serialized
|
|
241
|
-
* - true: Handler must return exact schema types (requires explicit casting)
|
|
242
|
-
*
|
|
243
|
-
* @default false
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```typescript
|
|
247
|
-
* // strictTypes: false (default) - Prisma types accepted
|
|
248
|
-
* handler: async () => {
|
|
249
|
-
* const user = await prisma.user.findUnique({ where: { id } });
|
|
250
|
-
* return user; // ✅ Works - Date/Decimal auto-serialized
|
|
251
|
-
* }
|
|
252
|
-
*
|
|
253
|
-
* // strictTypes: true - Exact types required
|
|
254
|
-
* handler: async () => {
|
|
255
|
-
* const user = await prisma.user.findUnique({ where: { id } });
|
|
256
|
-
* return user as UserResponse; // Type assertion needed
|
|
257
|
-
* }
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
strictTypes?: TStrictTypes;
|
|
261
|
-
/**
|
|
262
|
-
* Custom serialization configuration for response data
|
|
263
|
-
*
|
|
264
|
-
* Allows you to add custom type transformers in addition to the default Date/Decimal handling.
|
|
265
|
-
* Your custom transformers are prepended to the default transformers, so they take precedence.
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```typescript
|
|
269
|
-
* // Define custom transformer for Money class
|
|
270
|
-
* const moneyTransformer = (value: unknown) => {
|
|
271
|
-
* if (value instanceof Money) {
|
|
272
|
-
* return { amount: value.amount, currency: value.currency };
|
|
273
|
-
* }
|
|
274
|
-
* return undefined;
|
|
275
|
-
* };
|
|
276
|
-
*
|
|
277
|
-
* route({
|
|
278
|
-
* responses: { 200: ProductSchema },
|
|
279
|
-
* serialization: {
|
|
280
|
-
* transformers: [moneyTransformer]
|
|
281
|
-
* },
|
|
282
|
-
* handler: async () => {
|
|
283
|
-
* return {
|
|
284
|
-
* price: new Money(99.99, 'USD'), // Auto-serialized
|
|
285
|
-
* createdAt: new Date(), // Still handled by default transformer
|
|
286
|
-
* };
|
|
287
|
-
* }
|
|
288
|
-
* })
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
serialization?: Partial<SerializationConfig>;
|
|
292
|
-
/**
|
|
293
|
-
* Authorization check applied before the handler runs.
|
|
294
|
-
* Requires `ability` to be set on the Hono context (e.g., via auth middleware).
|
|
295
|
-
*/
|
|
296
|
-
authorize?: {
|
|
297
|
-
action: string;
|
|
298
|
-
subject: string | {
|
|
299
|
-
__caslSubjectType__?: string;
|
|
300
|
-
};
|
|
301
|
-
allowGuest?: boolean;
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Route handler - body and return types are automatically inferred from schemas
|
|
305
|
-
* Session is required by default (unless public: true)
|
|
306
|
-
*
|
|
307
|
-
* **Return type behavior (controlled by strictTypes option):**
|
|
308
|
-
*
|
|
309
|
-
* When strictTypes is false (default):
|
|
310
|
-
* - Uses `AcceptPrismaTypes<T>` which allows Date/Decimal objects
|
|
311
|
-
* - Date objects are automatically converted to ISO strings
|
|
312
|
-
* - Decimal objects are automatically converted to numbers
|
|
313
|
-
* - ALL string fields accept Date, ALL number fields accept Decimal
|
|
314
|
-
* - Pragmatic for Prisma integration, but permissive typing
|
|
315
|
-
*
|
|
316
|
-
* When strictTypes is true:
|
|
317
|
-
* - Requires exact schema types (no automatic Prisma type acceptance)
|
|
318
|
-
* - Provides stricter type safety
|
|
319
|
-
* - Requires explicit type assertions when returning Prisma objects
|
|
320
|
-
* - Serialization still works at runtime, but types are enforced
|
|
321
|
-
*/
|
|
322
|
-
handler: (context: RouteContext<TBody extends ValibotSchema ? InferSchemaType<TBody> : never, TQuery extends ValibotSchema ? InferSchemaType<TQuery> : Record<string, string>, TParams extends ValibotSchema ? InferSchemaType<TParams> : Record<string, string>, TPublic extends true ? false : true>) => TStrictTypes extends true ? Promise<InferResponseType<TResponses>> | InferResponseType<TResponses> : Promise<AcceptPrismaTypes<InferResponseType<TResponses>>> | AcceptPrismaTypes<InferResponseType<TResponses>>;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Route handler context with typed body
|
|
326
|
-
*
|
|
327
|
-
* Automatically includes all context variables from Hono's ContextVariableMap.
|
|
328
|
-
* If your middleware extends ContextVariableMap (e.g., auth middleware adding ability/role),
|
|
329
|
-
* those variables will be automatically typed and available for destructuring.
|
|
330
|
-
*
|
|
331
|
-
* @template TBody - The typed body (inferred from schema)
|
|
332
|
-
* @template TSessionRequired - Whether session is guaranteed to exist (true by default, false for public routes)
|
|
333
|
-
*/
|
|
334
|
-
export interface RouteContext<TBody = never, TQuery = Record<string, string>, TParams = Record<string, string>, TSessionRequired extends boolean = true> extends Omit<Context['var'], 'session'> {
|
|
335
|
-
body: TBody;
|
|
336
|
-
query: TQuery;
|
|
337
|
-
params: TParams;
|
|
338
|
-
services: Record<string, unknown>;
|
|
339
|
-
/**
|
|
340
|
-
* Session from context variables (typed via Hono's ContextVariableMap)
|
|
341
|
-
* - Required by default (for authenticated routes)
|
|
342
|
-
* - Optional only for public routes (public: true)
|
|
343
|
-
*/
|
|
344
|
-
session: TSessionRequired extends true ? NonNullable<Context['var']['session']> : Context['var']['session'];
|
|
345
|
-
/**
|
|
346
|
-
* Client IP address (extracted from headers and connection info)
|
|
347
|
-
*/
|
|
348
|
-
ip: string;
|
|
349
|
-
/**
|
|
350
|
-
* User agent string from request headers
|
|
351
|
-
*/
|
|
352
|
-
userAgent: string | undefined;
|
|
353
|
-
/**
|
|
354
|
-
* Context-aware logger with automatic requestId correlation.
|
|
355
|
-
* Uses the route's first tag as the service name.
|
|
356
|
-
* Requires pino logger configured in bootstrap options.
|
|
357
|
-
*/
|
|
358
|
-
logger: Logger;
|
|
359
|
-
/**
|
|
360
|
-
* Original Hono context (for advanced use cases)
|
|
361
|
-
*/
|
|
362
|
-
context: Context;
|
|
363
|
-
}
|
|
364
11
|
/**
|
|
365
12
|
* Create a route handler with validation and OpenAPI metadata.
|
|
366
|
-
*
|
|
367
|
-
* Type inference works automatically:
|
|
368
|
-
* - Body type is inferred from the `body` schema
|
|
369
|
-
* - Return type is inferred as a union of all 2xx response schemas (200, 201, etc.)
|
|
370
|
-
* - Response data is automatically validated and extra keys are stripped
|
|
371
|
-
* - HTTP status code is automatically set based on which schema matches
|
|
372
|
-
*
|
|
373
|
-
* Response Validation & Status Code:
|
|
374
|
-
* - Responses are parsed through their corresponding 2xx schema
|
|
375
|
-
* - Extra keys not defined in the schema are automatically stripped
|
|
376
|
-
* - The HTTP status code is automatically set based on which schema validates
|
|
377
|
-
* - If multiple 2xx schemas are defined, each is tried in order (200, 201)
|
|
378
|
-
* - The first schema that successfully validates determines the status code
|
|
379
|
-
*
|
|
380
|
-
* @param router - The Hono router instance (needed for OpenAPI context)
|
|
381
|
-
* @param config - Route configuration
|
|
382
|
-
*
|
|
383
|
-
* @example
|
|
384
|
-
* ```typescript
|
|
385
|
-
* // Single response type
|
|
386
|
-
* router.post('/session', ...route(router, {
|
|
387
|
-
* body: StartSessionDto,
|
|
388
|
-
* responses: { 200: StartSessionResponseDto },
|
|
389
|
-
* handler: async ({ body }) => {
|
|
390
|
-
* // body is typed as InferOutput<typeof StartSessionDto>
|
|
391
|
-
* return { email: body.email }; // Must match StartSessionResponseDto
|
|
392
|
-
* }
|
|
393
|
-
* }))
|
|
394
|
-
*
|
|
395
|
-
* // Union response type (multiple 2xx responses with automatic status)
|
|
396
|
-
* router.post('/login', ...route(router, {
|
|
397
|
-
* body: LoginDto,
|
|
398
|
-
* responses: {
|
|
399
|
-
* 200: MfaRequiredDto, // Returns 200 if data matches this
|
|
400
|
-
* 201: SessionDto // Returns 201 if data matches this
|
|
401
|
-
* },
|
|
402
|
-
* handler: async ({ body }) => {
|
|
403
|
-
* // Return type is: MfaRequiredDto | SessionDto
|
|
404
|
-
* // Status code is set automatically based on which schema matches!
|
|
405
|
-
* if (needsMfa) return { mfaRequired: true, methods: ['totp'] }; // 200
|
|
406
|
-
* return { sessionId: '123', token: 'abc' }; // 201
|
|
407
|
-
* }
|
|
408
|
-
* }))
|
|
409
|
-
*
|
|
410
|
-
* // With pagination (auto-detected from ListQuerySchema)
|
|
411
|
-
* router.get('/users', ...route(router, {
|
|
412
|
-
* query: ListQuerySchema, // Contains page, pageSize - pagination headers auto-added
|
|
413
|
-
* responses: { 200: UsersResponseDto },
|
|
414
|
-
* handler: async ({ query }) => { ... }
|
|
415
|
-
* }))
|
|
416
|
-
*
|
|
417
|
-
* // With custom response headers
|
|
418
|
-
* router.get('/data', ...route(router, {
|
|
419
|
-
* openapi: {
|
|
420
|
-
* responseHeaders: ['Api-Version', 'Server-Timing']
|
|
421
|
-
* },
|
|
422
|
-
* responses: { 200: DataDto },
|
|
423
|
-
* handler: async () => { ... }
|
|
424
|
-
* }))
|
|
425
|
-
* ```
|
|
426
13
|
*/
|
|
427
14
|
export declare function route<TBody extends ValibotSchema | undefined = undefined, TQuery extends ValibotSchema | undefined = undefined, TParams extends ValibotSchema | undefined = undefined, TResponses extends Partial<Record<keyof typeof STATUS_DESCRIPTIONS, ValibotSchema | undefined>> = Record<never, never>, TPublic extends boolean = false, TStrictTypes extends boolean = false>(router: Hono, config: RouteConfig<TBody, TQuery, TParams, TResponses, TPublic, TStrictTypes>): RouteHandlers;
|
|
428
15
|
//# sourceMappingURL=route-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/http/route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/http/route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAqB,MAAM,MAAM,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMpE,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EAEX,mBAAmB,EACnB,aAAa,EACd,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAClF,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,OAAO,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9E,YAAY,CAKd;AAID;;GAEG;AACH,wBAAgB,KAAK,CACnB,KAAK,SAAS,aAAa,GAAG,SAAS,GAAG,SAAS,EACnD,MAAM,SAAS,aAAa,GAAG,SAAS,GAAG,SAAS,EACpD,OAAO,SAAS,aAAa,GAAG,SAAS,GAAG,SAAS,EACrD,UAAU,SAAS,OAAO,CACxB,MAAM,CAAC,MAAM,OAAO,mBAAmB,EAAE,aAAa,GAAG,SAAS,CAAC,CACpE,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxB,OAAO,SAAS,OAAO,GAAG,KAAK,EAC/B,YAAY,SAAS,OAAO,GAAG,KAAK,EAEpC,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,GAC7E,aAAa,CAgDf"}
|