@web-ts-toolkit/express-response-handler 0.5.0 → 0.6.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/README.md CHANGED
@@ -50,12 +50,49 @@ app.post(
50
50
 
51
51
  ## Main Exports
52
52
 
53
+ Root entrypoint (`@web-ts-toolkit/express-response-handler`):
54
+
53
55
  - default handler instance
54
56
  - `handleResponse(...)`
55
57
  - `HttpResponse`
56
58
  - `createHandler(...)`
57
59
  - `ErrorFormats`
58
60
 
61
+ Subpath entrypoints:
62
+
63
+ - `@web-ts-toolkit/express-response-handler/types` — public type exports
64
+ - `@web-ts-toolkit/express-response-handler/responses` — response wrappers
65
+ - `@web-ts-toolkit/express-response-handler/responses/csv` — `CSVResponse`
66
+ - `@web-ts-toolkit/express-response-handler/responses/success` — `Created`, `Accepted`, `NoContent`, etc.
67
+
68
+ ### Subpath import example
69
+
70
+ ```ts
71
+ import { Created, NoContent } from '@web-ts-toolkit/express-response-handler/responses/success';
72
+
73
+ app.post(
74
+ '/users',
75
+ handleResponse(async () => Created(await createUser())),
76
+ );
77
+ app.delete(
78
+ '/users/:id',
79
+ handleResponse(async () => NoContent()),
80
+ );
81
+ ```
82
+
83
+ ### Import styles
84
+
85
+ The package ships both a default handler instance and named exports:
86
+
87
+ ```ts
88
+ // default export
89
+ import apiHandler from '@web-ts-toolkit/express-response-handler';
90
+ const { handleResponse, HttpResponse } = apiHandler;
91
+
92
+ // named exports
93
+ import { handleResponse, HttpResponse } from '@web-ts-toolkit/express-response-handler';
94
+ ```
95
+
59
96
  ## Documentation
60
97
 
61
98
  Full package documentation lives in `website/docs/packages/express-response-handler.md`.
@@ -6,6 +6,14 @@ import './responses/index.mjs';
6
6
  import './responses/csv.mjs';
7
7
  import './error-formats.mjs';
8
8
 
9
+ /**
10
+ * Creates an Express response handler that wraps route handlers and serializes
11
+ * return values, thrown `HttpError`s, and explicit `HttpResponse` wrappers.
12
+ *
13
+ * @example
14
+ * const { handleResponse, HttpResponse } = createHandler();
15
+ * app.get('/health', handleResponse(() => ({ ok: true })));
16
+ */
9
17
  declare function createHandler(options?: ExpressResponseHandlerOptions): ExpressResponseHandler;
10
18
 
11
19
  export { createHandler };
@@ -6,6 +6,14 @@ import './responses/index.js';
6
6
  import './responses/csv.js';
7
7
  import './error-formats.js';
8
8
 
9
+ /**
10
+ * Creates an Express response handler that wraps route handlers and serializes
11
+ * return values, thrown `HttpError`s, and explicit `HttpResponse` wrappers.
12
+ *
13
+ * @example
14
+ * const { handleResponse, HttpResponse } = createHandler();
15
+ * app.get('/health', handleResponse(() => ({ ok: true })));
16
+ */
9
17
  declare function createHandler(options?: ExpressResponseHandlerOptions): ExpressResponseHandler;
10
18
 
11
19
  export { createHandler };
@@ -9,7 +9,7 @@ declare const HttpResponse: {
9
9
  created: (data: unknown) => Created<unknown>;
10
10
  accepted: (data: unknown) => Accepted<unknown>;
11
11
  nonAuthoritativeInfo: (data: unknown) => NonAuthoritativeInfo<unknown>;
12
- noContent: (data: unknown) => NoContent<unknown>;
12
+ noContent: () => NoContent;
13
13
  resetContent: (data: unknown) => ResetContent<unknown>;
14
14
  partialContent: (data: unknown) => PartialContent<unknown>;
15
15
  multiStatus: (data: unknown) => MultiStatus<unknown>;
@@ -9,7 +9,7 @@ declare const HttpResponse: {
9
9
  created: (data: unknown) => Created<unknown>;
10
10
  accepted: (data: unknown) => Accepted<unknown>;
11
11
  nonAuthoritativeInfo: (data: unknown) => NonAuthoritativeInfo<unknown>;
12
- noContent: (data: unknown) => NoContent<unknown>;
12
+ noContent: () => NoContent;
13
13
  resetContent: (data: unknown) => ResetContent<unknown>;
14
14
  partialContent: (data: unknown) => PartialContent<unknown>;
15
15
  multiStatus: (data: unknown) => MultiStatus<unknown>;
package/llms.txt ADDED
@@ -0,0 +1,52 @@
1
+ # @web-ts-toolkit/express-response-handler
2
+
3
+ FastAPI-style return-value response handling for Express: route handlers return plain values, `HttpResponse` wrappers, or throw typed HTTP errors.
4
+
5
+ ## Main Patterns
6
+
7
+ ```ts
8
+ import express from 'express';
9
+ import apiHandler from '@web-ts-toolkit/express-response-handler';
10
+ import { NotFoundError } from '@web-ts-toolkit/http-errors';
11
+
12
+ const { handleResponse, HttpResponse } = apiHandler;
13
+ const app = express();
14
+
15
+ app.get('/health', handleResponse(() => ({ ok: true })));
16
+
17
+ app.get('/users/:id', handleResponse(async (req) => {
18
+ const user = await getUser(req.params.id);
19
+ if (!user) throw new NotFoundError('user not found');
20
+ return user;
21
+ }));
22
+
23
+ app.post('/jobs', handleResponse(async () => HttpResponse.created(await createJob())));
24
+ ```
25
+
26
+ Custom handler instance and error format:
27
+
28
+ ```ts
29
+ import { createHandler, ErrorFormats } from '@web-ts-toolkit/express-response-handler';
30
+
31
+ const { handleResponse } = createHandler({ errorFormat: ErrorFormats.rfc9457 });
32
+ ```
33
+
34
+ Subpath response wrappers:
35
+
36
+ ```ts
37
+ import { CSVResponse } from '@web-ts-toolkit/express-response-handler/responses/csv';
38
+ import { Created, NoContent } from '@web-ts-toolkit/express-response-handler/responses/success';
39
+ ```
40
+
41
+ ## Gotchas
42
+
43
+ - depends on `@web-ts-toolkit/http-errors` for typed thrown errors
44
+ - default export is the handler instance; named exports (`handleResponse`, `HttpResponse`, `createHandler`, `ErrorFormats`) are also available
45
+ - return plain values for `200 OK`; use `HttpResponse.*` wrappers for other status codes
46
+ - `ErrorFormats` selects between `simple`, `aip193`, and `rfc9457` error payload shapes
47
+ - response wrappers (`Created`, `NoContent`, `CSVResponse`, etc.) are also exported from the root entrypoint, but the subpaths give tree-shakeable access
48
+
49
+ ## Pointers
50
+
51
+ - README: installation, quickstart, main exports, subpath list, import styles
52
+ - website/docs/packages/express-response-handler.md: full documentation
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/express-response-handler",
3
3
  "description": "FastAPI-style return-value response handling for Express",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/express-response-handler",
5
- "version": "0.5.0",
5
+ "version": "0.6.1",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "express",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@fast-csv/format": "^5.0.5",
54
- "@web-ts-toolkit/http-errors": "0.5.0",
55
- "@web-ts-toolkit/utils": "0.5.0"
54
+ "@web-ts-toolkit/http-errors": "0.6.1",
55
+ "@web-ts-toolkit/utils": "0.6.1"
56
56
  },
57
57
  "author": "Junmin Ahn",
58
58
  "bugs": {
@@ -12,8 +12,8 @@ declare class Accepted<T = unknown> extends Response<T> {
12
12
  declare class NonAuthoritativeInfo<T = unknown> extends Response<T> {
13
13
  constructor(data: T);
14
14
  }
15
- declare class NoContent<T = unknown> extends Response<T> {
16
- constructor(data: T);
15
+ declare class NoContent extends Response<undefined> {
16
+ constructor();
17
17
  }
18
18
  declare class ResetContent<T = unknown> extends Response<T> {
19
19
  constructor(data: T);
@@ -12,8 +12,8 @@ declare class Accepted<T = unknown> extends Response<T> {
12
12
  declare class NonAuthoritativeInfo<T = unknown> extends Response<T> {
13
13
  constructor(data: T);
14
14
  }
15
- declare class NoContent<T = unknown> extends Response<T> {
16
- constructor(data: T);
15
+ declare class NoContent extends Response<undefined> {
16
+ constructor();
17
17
  }
18
18
  declare class ResetContent<T = unknown> extends Response<T> {
19
19
  constructor(data: T);
@@ -52,8 +52,8 @@ class NonAuthoritativeInfo extends import_index.Response {
52
52
  }
53
53
  }
54
54
  class NoContent extends import_index.Response {
55
- constructor(data) {
56
- super(204, data);
55
+ constructor() {
56
+ super(204, void 0);
57
57
  }
58
58
  }
59
59
  class ResetContent extends import_index.Response {
@@ -20,8 +20,8 @@ class NonAuthoritativeInfo extends Response {
20
20
  }
21
21
  }
22
22
  class NoContent extends Response {
23
- constructor(data) {
24
- super(204, data);
23
+ constructor() {
24
+ super(204, void 0);
25
25
  }
26
26
  }
27
27
  class ResetContent extends Response {