@fedify/hono 2.0.0-pr.433.1601 → 2.0.0-pr.434.1659
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/mod.cjs +46 -0
- package/dist/mod.d.cts +39 -0
- package/package.json +10 -12
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mod.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a Hono middleware to integrate with the {@link Federation} object.
|
|
5
|
+
*
|
|
6
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
7
|
+
* object.
|
|
8
|
+
* @template THonoContext A type of the Hono context.
|
|
9
|
+
* @param federation A {@link Federation} object to integrate with Hono.
|
|
10
|
+
* @param contextDataFactory A function to create a context data for the
|
|
11
|
+
* {@link Federation} object.
|
|
12
|
+
* @returns A Hono middleware.
|
|
13
|
+
* @since 1.9.0
|
|
14
|
+
*/
|
|
15
|
+
function federation(federation$1, contextDataFactory) {
|
|
16
|
+
return async (ctx, next) => {
|
|
17
|
+
let contextData = contextDataFactory(ctx);
|
|
18
|
+
if (contextData instanceof Promise) contextData = await contextData;
|
|
19
|
+
return await federation$1.fetch(ctx.req.raw, {
|
|
20
|
+
contextData,
|
|
21
|
+
...integrateFetchOptions(ctx, next)
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function integrateFetchOptions(ctx, next) {
|
|
26
|
+
return {
|
|
27
|
+
async onNotFound(_req) {
|
|
28
|
+
await next();
|
|
29
|
+
return ctx.res;
|
|
30
|
+
},
|
|
31
|
+
async onNotAcceptable(_req) {
|
|
32
|
+
await next();
|
|
33
|
+
if (ctx.res.status !== 404) return ctx.res;
|
|
34
|
+
return new Response("Not acceptable", {
|
|
35
|
+
status: 406,
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "text/plain",
|
|
38
|
+
Vary: "Accept"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.federation = federation;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Federation } from "@fedify/fedify/federation";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
interface HonoRequest {
|
|
6
|
+
raw: Request;
|
|
7
|
+
}
|
|
8
|
+
interface HonoContext {
|
|
9
|
+
req: HonoRequest;
|
|
10
|
+
res: Response;
|
|
11
|
+
}
|
|
12
|
+
type HonoMiddleware<THonoContext extends HonoContext> = (ctx: THonoContext, next: () => Promise<void>) => Promise<Response | void>;
|
|
13
|
+
/**
|
|
14
|
+
* A factory function to create a context data for the {@link Federation}
|
|
15
|
+
* object.
|
|
16
|
+
*
|
|
17
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
18
|
+
* object.
|
|
19
|
+
* @template THonoContext A type of the Hono context.
|
|
20
|
+
* @param context A Hono context object.
|
|
21
|
+
* @returns A context data for the {@link Federation} object.
|
|
22
|
+
* @since 1.9.0
|
|
23
|
+
*/
|
|
24
|
+
type ContextDataFactory<TContextData, THonoContext> = (context: THonoContext) => TContextData | Promise<TContextData>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Hono middleware to integrate with the {@link Federation} object.
|
|
27
|
+
*
|
|
28
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
29
|
+
* object.
|
|
30
|
+
* @template THonoContext A type of the Hono context.
|
|
31
|
+
* @param federation A {@link Federation} object to integrate with Hono.
|
|
32
|
+
* @param contextDataFactory A function to create a context data for the
|
|
33
|
+
* {@link Federation} object.
|
|
34
|
+
* @returns A Hono middleware.
|
|
35
|
+
* @since 1.9.0
|
|
36
|
+
*/
|
|
37
|
+
declare function federation<TContextData, THonoContext extends HonoContext>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData, THonoContext>): HonoMiddleware<THonoContext>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ContextDataFactory, federation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/hono",
|
|
3
|
-
"version": "2.0.0-pr.
|
|
3
|
+
"version": "2.0.0-pr.434.1659+7c115883",
|
|
4
4
|
"description": "Integrate Fedify with Hono",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -28,21 +28,19 @@
|
|
|
28
28
|
"https://github.com/sponsors/dahlia"
|
|
29
29
|
],
|
|
30
30
|
"type": "module",
|
|
31
|
-
"main": "./dist/mod.
|
|
31
|
+
"main": "./dist/mod.cjs",
|
|
32
32
|
"module": "./dist/mod.js",
|
|
33
33
|
"types": "./dist/mod.d.ts",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"default": "./dist/mod.
|
|
36
|
+
"types": {
|
|
37
|
+
"import": "./dist/mod.d.ts",
|
|
38
|
+
"require": "./dist/mod.d.cts",
|
|
39
|
+
"default": "./dist/mod.d.ts"
|
|
40
40
|
},
|
|
41
|
-
"import":
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"default": "./dist/mod.js"
|
|
45
|
-
}
|
|
41
|
+
"import": "./dist/mod.js",
|
|
42
|
+
"require": "./dist/mod.cjs",
|
|
43
|
+
"default": "./dist/mod.js"
|
|
46
44
|
},
|
|
47
45
|
"./package.json": "./package.json"
|
|
48
46
|
},
|
|
@@ -52,7 +50,7 @@
|
|
|
52
50
|
],
|
|
53
51
|
"peerDependencies": {
|
|
54
52
|
"hono": "^4.0.0",
|
|
55
|
-
"@fedify/fedify": "^2.0.0-pr.
|
|
53
|
+
"@fedify/fedify": "^2.0.0-pr.434.1659+7c115883"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"tsdown": "^0.12.9",
|