@kizunajs/next 2.0.0-beta.34 → 2.0.0-beta.36
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/index.cjs +40 -8
- package/dist/index.mjs +42 -10
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,23 @@ const jsonResponse = (status, body, headers, raw = false) => new next_server_js.
|
|
|
6
6
|
status,
|
|
7
7
|
headers
|
|
8
8
|
});
|
|
9
|
+
/**
|
|
10
|
+
* The GET a method-override POST stands in for: its form body appended to the
|
|
11
|
+
* URL's query, so the GET route reads it as it reads any query.
|
|
12
|
+
*/
|
|
13
|
+
const asGetRequest = async (request) => {
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
for (const [key, value] of new URLSearchParams(await request.text())) url.searchParams.append(key, value);
|
|
16
|
+
const headers = new Headers(request.headers);
|
|
17
|
+
headers.delete("content-type");
|
|
18
|
+
headers.delete("content-length");
|
|
19
|
+
headers.delete(kizunajs_adapter.METHOD_OVERRIDE_HEADER);
|
|
20
|
+
return new next_server_js.NextRequest(url, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
headers,
|
|
23
|
+
signal: request.signal
|
|
24
|
+
});
|
|
25
|
+
};
|
|
9
26
|
const handleNextRequest = async (request, routes, router, options, guards, schemes, requestContext, pluginExports, jobs) => {
|
|
10
27
|
const url = new URL(request.url);
|
|
11
28
|
const adapter = (0, kizunajs_adapter.defineAdapter)({
|
|
@@ -163,7 +180,8 @@ function mountNext(api, options) {
|
|
|
163
180
|
const pluginRoutes = (0, kizunajs_adapter.pluginRoutesOf)(api);
|
|
164
181
|
const pluginRouter = (0, kizunajs_adapter.pluginRouterOf)(api);
|
|
165
182
|
const hasPluginRoutes = Object.keys(pluginRoutes).length > 0;
|
|
166
|
-
const handler = async (
|
|
183
|
+
const handler = async (incoming) => {
|
|
184
|
+
const request = (0, kizunajs_adapter.isMethodOverride)(incoming.method, incoming.headers.get(kizunajs_adapter.METHOD_OVERRIDE_HEADER), incoming.headers.get("content-type")) ? await asGetRequest(incoming) : incoming;
|
|
167
185
|
if (hasPluginRoutes) {
|
|
168
186
|
const pathname = new URL(request.url).pathname;
|
|
169
187
|
if (!((0, kizunajs_adapter.matchRoute)(request.method, pathname, api.routes, options?.basePath).kind === "matched") && (0, kizunajs_adapter.matchRoute)(request.method, pathname, pluginRoutes, options?.basePath).kind === "matched") return handleNextRequest(request, pluginRoutes, pluginRouter, handlerOptions, guards, schemes, requestContext, pluginExports, void 0);
|
|
@@ -197,13 +215,27 @@ function mountNext(api, options) {
|
|
|
197
215
|
* basePath: '/api',
|
|
198
216
|
* });
|
|
199
217
|
*/
|
|
200
|
-
const nextAdapter = (defaults) =>
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
218
|
+
const nextAdapter = (defaults) => {
|
|
219
|
+
const inProcess = /* @__PURE__ */ new WeakMap();
|
|
220
|
+
return {
|
|
221
|
+
name: "next",
|
|
222
|
+
mount: (api, options) => mountNext(api, {
|
|
223
|
+
...defaults,
|
|
224
|
+
...options
|
|
225
|
+
}),
|
|
226
|
+
fetch: (api, request) => {
|
|
227
|
+
let handler = inProcess.get(api);
|
|
228
|
+
if (handler === void 0) {
|
|
229
|
+
handler = mountNext(api, {
|
|
230
|
+
...defaults,
|
|
231
|
+
basePath: void 0
|
|
232
|
+
}).GET;
|
|
233
|
+
inProcess.set(api, handler);
|
|
234
|
+
}
|
|
235
|
+
return handler(new next_server_js.NextRequest(request));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
};
|
|
207
239
|
//#endregion
|
|
208
240
|
Object.defineProperty(exports, "NextRequest", {
|
|
209
241
|
enumerable: true,
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import { GUARDS_META, JOBS_META, REQUEST_CONTEXT_META, ROUTER_META, SCHEMES_META, defineAdapter, entriesToObject, headersToObject, jobRouter, jobRoutes, jobRunnerFrom, matchRoute, parseFetchBody, pluginExportsOf, pluginRouterOf, pluginRoutesOf, renderJsonResult } from "kizunajs/adapter";
|
|
2
|
-
import { NextRequest, NextResponse, NextResponse as NextResponse$1 } from "next/server.js";
|
|
1
|
+
import { GUARDS_META, JOBS_META, METHOD_OVERRIDE_HEADER, REQUEST_CONTEXT_META, ROUTER_META, SCHEMES_META, defineAdapter, entriesToObject, headersToObject, isMethodOverride, jobRouter, jobRoutes, jobRunnerFrom, matchRoute, parseFetchBody, pluginExportsOf, pluginRouterOf, pluginRoutesOf, renderJsonResult } from "kizunajs/adapter";
|
|
2
|
+
import { NextRequest, NextRequest as NextRequest$1, NextResponse, NextResponse as NextResponse$1 } from "next/server.js";
|
|
3
3
|
//#region src/server.ts
|
|
4
4
|
const jsonResponse = (status, body, headers, raw = false) => new NextResponse$1(body === null || body === void 0 ? null : raw ? body : JSON.stringify(body), {
|
|
5
5
|
status,
|
|
6
6
|
headers
|
|
7
7
|
});
|
|
8
|
+
/**
|
|
9
|
+
* The GET a method-override POST stands in for: its form body appended to the
|
|
10
|
+
* URL's query, so the GET route reads it as it reads any query.
|
|
11
|
+
*/
|
|
12
|
+
const asGetRequest = async (request) => {
|
|
13
|
+
const url = new URL(request.url);
|
|
14
|
+
for (const [key, value] of new URLSearchParams(await request.text())) url.searchParams.append(key, value);
|
|
15
|
+
const headers = new Headers(request.headers);
|
|
16
|
+
headers.delete("content-type");
|
|
17
|
+
headers.delete("content-length");
|
|
18
|
+
headers.delete(METHOD_OVERRIDE_HEADER);
|
|
19
|
+
return new NextRequest$1(url, {
|
|
20
|
+
method: "GET",
|
|
21
|
+
headers,
|
|
22
|
+
signal: request.signal
|
|
23
|
+
});
|
|
24
|
+
};
|
|
8
25
|
const handleNextRequest = async (request, routes, router, options, guards, schemes, requestContext, pluginExports, jobs) => {
|
|
9
26
|
const url = new URL(request.url);
|
|
10
27
|
const adapter = defineAdapter({
|
|
@@ -162,7 +179,8 @@ function mountNext(api, options) {
|
|
|
162
179
|
const pluginRoutes = pluginRoutesOf(api);
|
|
163
180
|
const pluginRouter = pluginRouterOf(api);
|
|
164
181
|
const hasPluginRoutes = Object.keys(pluginRoutes).length > 0;
|
|
165
|
-
const handler = async (
|
|
182
|
+
const handler = async (incoming) => {
|
|
183
|
+
const request = isMethodOverride(incoming.method, incoming.headers.get(METHOD_OVERRIDE_HEADER), incoming.headers.get("content-type")) ? await asGetRequest(incoming) : incoming;
|
|
166
184
|
if (hasPluginRoutes) {
|
|
167
185
|
const pathname = new URL(request.url).pathname;
|
|
168
186
|
if (!(matchRoute(request.method, pathname, api.routes, options?.basePath).kind === "matched") && matchRoute(request.method, pathname, pluginRoutes, options?.basePath).kind === "matched") return handleNextRequest(request, pluginRoutes, pluginRouter, handlerOptions, guards, schemes, requestContext, pluginExports, void 0);
|
|
@@ -196,12 +214,26 @@ function mountNext(api, options) {
|
|
|
196
214
|
* basePath: '/api',
|
|
197
215
|
* });
|
|
198
216
|
*/
|
|
199
|
-
const nextAdapter = (defaults) =>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
217
|
+
const nextAdapter = (defaults) => {
|
|
218
|
+
const inProcess = /* @__PURE__ */ new WeakMap();
|
|
219
|
+
return {
|
|
220
|
+
name: "next",
|
|
221
|
+
mount: (api, options) => mountNext(api, {
|
|
222
|
+
...defaults,
|
|
223
|
+
...options
|
|
224
|
+
}),
|
|
225
|
+
fetch: (api, request) => {
|
|
226
|
+
let handler = inProcess.get(api);
|
|
227
|
+
if (handler === void 0) {
|
|
228
|
+
handler = mountNext(api, {
|
|
229
|
+
...defaults,
|
|
230
|
+
basePath: void 0
|
|
231
|
+
}).GET;
|
|
232
|
+
inProcess.set(api, handler);
|
|
233
|
+
}
|
|
234
|
+
return handler(new NextRequest$1(request));
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
};
|
|
206
238
|
//#endregion
|
|
207
239
|
export { NextRequest, NextResponse, handleNextRequest, mountNext, nextAdapter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/next",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.36",
|
|
4
4
|
"description": "Next.js App Router adapter for Kizuna.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"kizunajs": "2.0.0-beta.
|
|
59
|
+
"kizunajs": "2.0.0-beta.36",
|
|
60
60
|
"next": ">=16.0.0",
|
|
61
61
|
"zod": "^4.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"kizunajs": "2.0.0-beta.
|
|
64
|
+
"kizunajs": "2.0.0-beta.36",
|
|
65
65
|
"next": "^16.4.5",
|
|
66
66
|
"tsdown": "^0.21.10",
|
|
67
67
|
"typescript": "^6.0.3",
|