shokupan 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/README.md +9 -8
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/context.d.ts +27 -5
- package/dist/index.cjs +662 -429
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +605 -394
- package/dist/index.js.map +1 -1
- package/dist/json-parser-B3dnQmCC.js +35 -0
- package/dist/json-parser-B3dnQmCC.js.map +1 -0
- package/dist/json-parser-COdZ0fqY.cjs +35 -0
- package/dist/json-parser-COdZ0fqY.cjs.map +1 -0
- package/dist/{openapi-analyzer-z-7AoFRC.cjs → openapi-analyzer-Bei1sVWp.cjs} +33 -16
- package/dist/openapi-analyzer-Bei1sVWp.cjs.map +1 -0
- package/dist/{openapi-analyzer-D7y6Qa38.js → openapi-analyzer-Ce_7JxZh.js} +33 -16
- package/dist/openapi-analyzer-Ce_7JxZh.js.map +1 -0
- package/dist/plugins/scalar.d.ts +1 -1
- package/dist/router.d.ts +33 -22
- package/dist/{server-adapter-BWrEJbKL.js → server-adapter-0xH174zz.js} +4 -2
- package/dist/server-adapter-0xH174zz.js.map +1 -0
- package/dist/{server-adapter-fVKP60e0.cjs → server-adapter-DFhwlK8e.cjs} +4 -2
- package/dist/server-adapter-DFhwlK8e.cjs.map +1 -0
- package/dist/shokupan.d.ts +2 -7
- package/dist/types.d.ts +30 -2
- package/dist/util/datastore.d.ts +6 -0
- package/dist/util/json-parser.d.ts +12 -0
- package/dist/util/plugin-deps.d.ts +25 -0
- package/package.json +74 -14
- package/dist/buntest.d.ts +0 -1
- package/dist/openapi-analyzer-D7y6Qa38.js.map +0 -1
- package/dist/openapi-analyzer-z-7AoFRC.cjs.map +0 -1
- package/dist/server-adapter-BWrEJbKL.js.map +0 -1
- package/dist/server-adapter-fVKP60e0.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ That's it! Your server is running at `http://localhost:3000` 🎉
|
|
|
75
75
|
- [Using Express Middleware](#using-express-middleware)
|
|
76
76
|
- [Testing](#testing)
|
|
77
77
|
- [Deployment](#deployment)
|
|
78
|
+
- [Production Best Practices](https://knackstedt.github.io/shokupan/guides/production/) 📚
|
|
78
79
|
- [CLI Tools](#cli-tools)
|
|
79
80
|
- [API Reference](#api-reference)
|
|
80
81
|
- [Roadmap](#-roadmap)
|
|
@@ -929,7 +930,7 @@ This works great when combined with the Debug Dashboard.
|
|
|
929
930
|
A visual dashboard to inspect your application, view metrics, analyze the middleware graph, and replay failed requests.
|
|
930
931
|
|
|
931
932
|
```typescript
|
|
932
|
-
import { DebugDashboard } from 'shokupan
|
|
933
|
+
import { DebugDashboard } from 'shokupan';
|
|
933
934
|
|
|
934
935
|
// Mount the dashboard
|
|
935
936
|
app.mount('/debug', new DebugDashboard({
|
|
@@ -1057,8 +1058,8 @@ router.get('/wines/white', async (ctx) => {
|
|
|
1057
1058
|
router.get('/wines/all', async (ctx) => {
|
|
1058
1059
|
// Make parallel sub-requests
|
|
1059
1060
|
const [redResponse, whiteResponse] = await Promise.all([
|
|
1060
|
-
router.
|
|
1061
|
-
router.
|
|
1061
|
+
router.internalRequest('/wines/red'),
|
|
1062
|
+
router.internalRequest('/wines/white')
|
|
1062
1063
|
]);
|
|
1063
1064
|
|
|
1064
1065
|
const red = await redResponse.json();
|
|
@@ -1559,7 +1560,7 @@ describe('My App', () => {
|
|
|
1559
1560
|
app.get('/', () => ({ message: 'Hello' }));
|
|
1560
1561
|
|
|
1561
1562
|
// Process a request without starting the server
|
|
1562
|
-
const res = await app.
|
|
1563
|
+
const res = await app.testRequest({
|
|
1563
1564
|
method: 'GET',
|
|
1564
1565
|
path: '/'
|
|
1565
1566
|
});
|
|
@@ -1703,8 +1704,8 @@ const app = new Shokupan(config?: ShokupanConfig);
|
|
|
1703
1704
|
- `mount(path, controller)` - Mount controller or router
|
|
1704
1705
|
- `static(path, options)` - Serve static files
|
|
1705
1706
|
- `listen(port?)` - Start server
|
|
1706
|
-
- `
|
|
1707
|
-
- `
|
|
1707
|
+
- `testRequest(options)` - Process request (for testing purposes)
|
|
1708
|
+
- `internalRequest(options)` - Make sub-request
|
|
1708
1709
|
- `computeOpenAPISpec(base)` - Generate OpenAPI spec
|
|
1709
1710
|
|
|
1710
1711
|
### ShokupanRouter Class
|
|
@@ -1737,8 +1738,8 @@ const router = new ShokupanRouter(config?: ShokupanRouteConfig);
|
|
|
1737
1738
|
- `head(path, spec?, ...handlers)` - Add HEAD route
|
|
1738
1739
|
- `mount(path, controller)` - Mount controller or router
|
|
1739
1740
|
- `static(path, options)` - Serve static files
|
|
1740
|
-
- `
|
|
1741
|
-
- `
|
|
1741
|
+
- `testRequest(options)` - Process request (for testing purposes)
|
|
1742
|
+
- `internalRequest(options)` - Make sub-request
|
|
1742
1743
|
|
|
1743
1744
|
|
|
1744
1745
|
### ShokupanContext
|
package/dist/cli.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const p = require("@clack/prompts");
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
const promises = require("node:timers/promises");
|
|
7
|
-
const openapiAnalyzer = require("./openapi-analyzer-
|
|
7
|
+
const openapiAnalyzer = require("./openapi-analyzer-Bei1sVWp.cjs");
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
10
|
if (e) {
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as p from "@clack/prompts";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { setTimeout } from "node:timers/promises";
|
|
6
|
-
import { analyzeDirectory } from "./openapi-analyzer-
|
|
6
|
+
import { analyzeDirectory } from "./openapi-analyzer-Ce_7JxZh.js";
|
|
7
7
|
const templates = {
|
|
8
8
|
controller: (name) => `import { Controller, Get, Ctx } from 'shokupan';
|
|
9
9
|
import { ShokupanContext } from 'shokupan';
|
package/dist/context.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export declare class ShokupanContext<State extends Record<string, any> = Record<
|
|
|
23
23
|
readonly server?: Server;
|
|
24
24
|
readonly app?: Shokupan;
|
|
25
25
|
readonly signal?: AbortSignal;
|
|
26
|
-
private _url;
|
|
27
26
|
params: Record<string, string>;
|
|
28
27
|
state: State;
|
|
29
28
|
handlerStack: HandlerStackItem[];
|
|
@@ -31,6 +30,16 @@ export declare class ShokupanContext<State extends Record<string, any> = Record<
|
|
|
31
30
|
_debug?: DebugCollector;
|
|
32
31
|
_finalResponse?: Response;
|
|
33
32
|
_rawBody?: string | ArrayBuffer | Uint8Array;
|
|
33
|
+
private _url?;
|
|
34
|
+
private _cachedBody?;
|
|
35
|
+
private _bodyType?;
|
|
36
|
+
private _bodyParsed;
|
|
37
|
+
_bodyParseError?: Error;
|
|
38
|
+
private _cachedHostname?;
|
|
39
|
+
private _cachedProtocol?;
|
|
40
|
+
private _cachedHost?;
|
|
41
|
+
private _cachedOrigin?;
|
|
42
|
+
private _cachedQuery?;
|
|
34
43
|
constructor(request: ShokupanRequest<any>, server?: Server, state?: State, app?: Shokupan, signal?: AbortSignal, // Optional as it might not be provided in tests or simple creates
|
|
35
44
|
enableMiddlewareTracking?: boolean);
|
|
36
45
|
get url(): URL;
|
|
@@ -101,6 +110,23 @@ export declare class ShokupanContext<State extends Record<string, any> = Record<
|
|
|
101
110
|
*/
|
|
102
111
|
setCookie(name: string, value: string, options?: CookieOptions): this;
|
|
103
112
|
private mergeHeaders;
|
|
113
|
+
/**
|
|
114
|
+
* Read request body with caching to avoid double parsing.
|
|
115
|
+
* The body is only parsed once and cached for subsequent reads.
|
|
116
|
+
*/
|
|
117
|
+
body<T = any>(): Promise<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Pre-parse the request body before handler execution.
|
|
120
|
+
* This improves performance and enables Node.js compatibility for large payloads.
|
|
121
|
+
* Errors are deferred until the body is actually accessed in the handler.
|
|
122
|
+
*/
|
|
123
|
+
parseBody(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Read raw body from ReadableStream efficiently.
|
|
126
|
+
* This is much faster than request.text() for large payloads.
|
|
127
|
+
* Also handles the case where body is already a string (e.g., in tests).
|
|
128
|
+
*/
|
|
129
|
+
private readRawBody;
|
|
104
130
|
/**
|
|
105
131
|
* Send a response
|
|
106
132
|
* @param body Response body
|
|
@@ -108,10 +134,6 @@ export declare class ShokupanContext<State extends Record<string, any> = Record<
|
|
|
108
134
|
* @returns Response
|
|
109
135
|
*/
|
|
110
136
|
send(body?: BodyInit, options?: ResponseInit): Response;
|
|
111
|
-
/**
|
|
112
|
-
* Read request body
|
|
113
|
-
*/
|
|
114
|
-
body<T = any>(): Promise<T>;
|
|
115
137
|
/**
|
|
116
138
|
* Respond with a JSON object
|
|
117
139
|
*/
|