@fedify/solidstart 2.2.0-dev.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/LICENSE +20 -0
- package/README.md +32 -0
- package/dist/index.cjs +56 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +55 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024–2026 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@fedify/solidstart: Integrate Fedify with SolidStart
|
|
4
|
+
====================================================
|
|
5
|
+
|
|
6
|
+
[![npm][npm badge]][npm]
|
|
7
|
+
[![Matrix][Matrix badge]][Matrix]
|
|
8
|
+
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]
|
|
9
|
+
|
|
10
|
+
This package provides a simple way to integrate [Fedify] with [SolidStart].
|
|
11
|
+
|
|
12
|
+
The integration code looks like this:
|
|
13
|
+
|
|
14
|
+
~~~~ typescript
|
|
15
|
+
// src/middleware/index.ts
|
|
16
|
+
import { fedifyMiddleware } from "@fedify/solidstart";
|
|
17
|
+
import federation from "../lib/federation";
|
|
18
|
+
|
|
19
|
+
export default fedifyMiddleware(federation, (event) => "context data");
|
|
20
|
+
~~~~
|
|
21
|
+
|
|
22
|
+
Put the above code in your *src/middleware/index.ts* file, and set
|
|
23
|
+
`middleware: "src/middleware/index.ts"` in your *app.config.ts*.
|
|
24
|
+
|
|
25
|
+
[npm badge]: https://img.shields.io/npm/v/@fedify/solidstart?logo=npm
|
|
26
|
+
[npm]: https://www.npmjs.com/package/@fedify/solidstart
|
|
27
|
+
[Matrix badge]: https://img.shields.io/matrix/fedify%3Amatrix.org
|
|
28
|
+
[Matrix]: https://matrix.to/#/#fedify:matrix.org
|
|
29
|
+
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
30
|
+
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
31
|
+
[Fedify]: https://fedify.dev/
|
|
32
|
+
[SolidStart]: https://start.solidjs.com/
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _solidjs_start_middleware = require("@solidjs/start/middleware");
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* Create a SolidStart middleware to integrate with the {@link Federation}
|
|
7
|
+
* object.
|
|
8
|
+
*
|
|
9
|
+
* @example src/middleware/index.ts
|
|
10
|
+
* ``` typescript
|
|
11
|
+
* import { fedifyMiddleware } from "@fedify/solidstart";
|
|
12
|
+
* import federation from "../lib/federation";
|
|
13
|
+
*
|
|
14
|
+
* export default fedifyMiddleware(federation);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @template TContextData A type of the context data for the
|
|
18
|
+
* {@link Federation} object.
|
|
19
|
+
* @param federation A {@link Federation} object to integrate with SolidStart.
|
|
20
|
+
* @param createContextData A function to create context data for the
|
|
21
|
+
* {@link Federation} object.
|
|
22
|
+
* @returns A SolidStart middleware object.
|
|
23
|
+
* @since 2.2.0
|
|
24
|
+
*/
|
|
25
|
+
function fedifyMiddleware(federation, createContextData = () => void 0) {
|
|
26
|
+
return (0, _solidjs_start_middleware.createMiddleware)({
|
|
27
|
+
onRequest: async (event) => {
|
|
28
|
+
const response = await federation.fetch(event.request, {
|
|
29
|
+
contextData: await createContextData(event),
|
|
30
|
+
onNotFound: () => new Response("Not Found", { status: 404 }),
|
|
31
|
+
onNotAcceptable: () => new Response("Not Acceptable", {
|
|
32
|
+
status: 406,
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "text/plain",
|
|
35
|
+
Vary: "Accept"
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
if (response.status === 404) return;
|
|
40
|
+
if (response.status === 406) {
|
|
41
|
+
notAcceptableResponses.set(event.request, response);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
},
|
|
46
|
+
onBeforeResponse: (event) => {
|
|
47
|
+
const stored = notAcceptableResponses.get(event.request);
|
|
48
|
+
if (stored != null) {
|
|
49
|
+
notAcceptableResponses.delete(event.request);
|
|
50
|
+
if ((event.response.status ?? 200) === 404) return stored;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.fedifyMiddleware = fedifyMiddleware;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Federation } from "@fedify/fedify/federation";
|
|
2
|
+
import { createMiddleware } from "@solidjs/start/middleware";
|
|
3
|
+
import { FetchEvent } from "@solidjs/start/server";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A factory function that creates the context data for the
|
|
8
|
+
* {@link Federation} object.
|
|
9
|
+
*
|
|
10
|
+
* @template TContextData The type of the context data.
|
|
11
|
+
* @param event The SolidStart {@link FetchEvent} for the current request.
|
|
12
|
+
* @returns The context data, or a promise resolving to the context data.
|
|
13
|
+
* @since 2.2.0
|
|
14
|
+
*/
|
|
15
|
+
type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Promise<TContextData>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a SolidStart middleware to integrate with the {@link Federation}
|
|
18
|
+
* object.
|
|
19
|
+
*
|
|
20
|
+
* @example src/middleware/index.ts
|
|
21
|
+
* ``` typescript
|
|
22
|
+
* import { fedifyMiddleware } from "@fedify/solidstart";
|
|
23
|
+
* import federation from "../lib/federation";
|
|
24
|
+
*
|
|
25
|
+
* export default fedifyMiddleware(federation);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @template TContextData A type of the context data for the
|
|
29
|
+
* {@link Federation} object.
|
|
30
|
+
* @param federation A {@link Federation} object to integrate with SolidStart.
|
|
31
|
+
* @param createContextData A function to create context data for the
|
|
32
|
+
* {@link Federation} object.
|
|
33
|
+
* @returns A SolidStart middleware object.
|
|
34
|
+
* @since 2.2.0
|
|
35
|
+
*/
|
|
36
|
+
declare function fedifyMiddleware<TContextData>(federation: Federation<TContextData>, createContextData?: ContextDataFactory<TContextData>): ReturnType<typeof createMiddleware>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ContextDataFactory, fedifyMiddleware };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createMiddleware } from "@solidjs/start/middleware";
|
|
2
|
+
import { Federation } from "@fedify/fedify/federation";
|
|
3
|
+
import { FetchEvent } from "@solidjs/start/server";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A factory function that creates the context data for the
|
|
8
|
+
* {@link Federation} object.
|
|
9
|
+
*
|
|
10
|
+
* @template TContextData The type of the context data.
|
|
11
|
+
* @param event The SolidStart {@link FetchEvent} for the current request.
|
|
12
|
+
* @returns The context data, or a promise resolving to the context data.
|
|
13
|
+
* @since 2.2.0
|
|
14
|
+
*/
|
|
15
|
+
type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Promise<TContextData>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a SolidStart middleware to integrate with the {@link Federation}
|
|
18
|
+
* object.
|
|
19
|
+
*
|
|
20
|
+
* @example src/middleware/index.ts
|
|
21
|
+
* ``` typescript
|
|
22
|
+
* import { fedifyMiddleware } from "@fedify/solidstart";
|
|
23
|
+
* import federation from "../lib/federation";
|
|
24
|
+
*
|
|
25
|
+
* export default fedifyMiddleware(federation);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @template TContextData A type of the context data for the
|
|
29
|
+
* {@link Federation} object.
|
|
30
|
+
* @param federation A {@link Federation} object to integrate with SolidStart.
|
|
31
|
+
* @param createContextData A function to create context data for the
|
|
32
|
+
* {@link Federation} object.
|
|
33
|
+
* @returns A SolidStart middleware object.
|
|
34
|
+
* @since 2.2.0
|
|
35
|
+
*/
|
|
36
|
+
declare function fedifyMiddleware<TContextData>(federation: Federation<TContextData>, createContextData?: ContextDataFactory<TContextData>): ReturnType<typeof createMiddleware>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ContextDataFactory, fedifyMiddleware };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createMiddleware } from "@solidjs/start/middleware";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Create a SolidStart middleware to integrate with the {@link Federation}
|
|
6
|
+
* object.
|
|
7
|
+
*
|
|
8
|
+
* @example src/middleware/index.ts
|
|
9
|
+
* ``` typescript
|
|
10
|
+
* import { fedifyMiddleware } from "@fedify/solidstart";
|
|
11
|
+
* import federation from "../lib/federation";
|
|
12
|
+
*
|
|
13
|
+
* export default fedifyMiddleware(federation);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @template TContextData A type of the context data for the
|
|
17
|
+
* {@link Federation} object.
|
|
18
|
+
* @param federation A {@link Federation} object to integrate with SolidStart.
|
|
19
|
+
* @param createContextData A function to create context data for the
|
|
20
|
+
* {@link Federation} object.
|
|
21
|
+
* @returns A SolidStart middleware object.
|
|
22
|
+
* @since 2.2.0
|
|
23
|
+
*/
|
|
24
|
+
function fedifyMiddleware(federation, createContextData = () => void 0) {
|
|
25
|
+
return createMiddleware({
|
|
26
|
+
onRequest: async (event) => {
|
|
27
|
+
const response = await federation.fetch(event.request, {
|
|
28
|
+
contextData: await createContextData(event),
|
|
29
|
+
onNotFound: () => new Response("Not Found", { status: 404 }),
|
|
30
|
+
onNotAcceptable: () => new Response("Not Acceptable", {
|
|
31
|
+
status: 406,
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "text/plain",
|
|
34
|
+
Vary: "Accept"
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
if (response.status === 404) return;
|
|
39
|
+
if (response.status === 406) {
|
|
40
|
+
notAcceptableResponses.set(event.request, response);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
},
|
|
45
|
+
onBeforeResponse: (event) => {
|
|
46
|
+
const stored = notAcceptableResponses.get(event.request);
|
|
47
|
+
if (stored != null) {
|
|
48
|
+
notAcceptableResponses.delete(event.request);
|
|
49
|
+
if ((event.response.status ?? 200) === 404) return stored;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { fedifyMiddleware };
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fedify/solidstart",
|
|
3
|
+
"version": "2.2.0-dev.0",
|
|
4
|
+
"description": "Integrate Fedify with SolidStart",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Fedify",
|
|
7
|
+
"ActivityPub",
|
|
8
|
+
"Fediverse",
|
|
9
|
+
"SolidStart",
|
|
10
|
+
"SolidJS"
|
|
11
|
+
],
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Hyeonseo Kim",
|
|
14
|
+
"email": "dodok8@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://fedify.dev/",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/fedify-dev/fedify.git",
|
|
20
|
+
"directory": "packages/solidstart"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/fedify-dev/fedify/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
"https://opencollective.com/fedify",
|
|
28
|
+
"https://github.com/sponsors/dahlia"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": {
|
|
37
|
+
"import": "./dist/index.d.ts",
|
|
38
|
+
"require": "./dist/index.d.cts",
|
|
39
|
+
"default": "./dist/index.d.ts"
|
|
40
|
+
},
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"require": "./dist/index.cjs",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist/",
|
|
49
|
+
"package.json"
|
|
50
|
+
],
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@solidjs/start": "^1.3.0",
|
|
53
|
+
"@fedify/fedify": "^2.2.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"tsdown": "^0.21.6",
|
|
57
|
+
"typescript": "^5.9.2"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build:self": "tsdown",
|
|
61
|
+
"build": "pnpm --filter @fedify/solidstart... run build:self",
|
|
62
|
+
"prepublish": "pnpm build"
|
|
63
|
+
}
|
|
64
|
+
}
|