@fedify/solidstart 2.4.0-pr.936.41 → 2.5.0-dev.2271

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 CHANGED
@@ -1,8 +1,55 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _solidjs_start_middleware = require("@solidjs/start/middleware");
3
- //#region src/index.ts
3
+ //#region src/handlers.ts
4
4
  const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
5
5
  /**
6
+ * Creates the `onRequest` handler wired into SolidStart by
7
+ * `fedifyMiddleware()`.
8
+ *
9
+ * @template TContextData A type of the context data for the
10
+ * {@link Federation} object.
11
+ * @param federation A {@link Federation} object to integrate with SolidStart.
12
+ * @param createContextData A function to create context data for the
13
+ * {@link Federation} object.
14
+ * @returns The `onRequest` handler.
15
+ */
16
+ function createOnRequestHandler(federation, createContextData) {
17
+ return async (event) => {
18
+ const response = await federation.fetch(event.request, {
19
+ contextData: await createContextData(event),
20
+ onNotFound: () => new Response("Not Found", { status: 404 }),
21
+ onNotAcceptable: () => new Response("Not Acceptable", {
22
+ status: 406,
23
+ headers: {
24
+ "Content-Type": "text/plain",
25
+ Vary: "Accept"
26
+ }
27
+ })
28
+ });
29
+ if (response.status === 404) return;
30
+ if (response.status === 406) {
31
+ notAcceptableResponses.set(event.request, response);
32
+ return;
33
+ }
34
+ return response;
35
+ };
36
+ }
37
+ /**
38
+ * Handles the response before SolidStart sends it to the client.
39
+ *
40
+ * @param event The SolidStart {@link FetchEvent} for the current request.
41
+ * @returns The stored 406 response if SolidStart could not handle the route.
42
+ */
43
+ function onBeforeResponse(event) {
44
+ const stored = notAcceptableResponses.get(event.request);
45
+ if (stored != null) {
46
+ notAcceptableResponses.delete(event.request);
47
+ if ((event.response.status ?? 200) === 404) return stored;
48
+ }
49
+ }
50
+ //#endregion
51
+ //#region src/index.ts
52
+ /**
6
53
  * Create a SolidStart middleware to integrate with the {@link Federation}
7
54
  * object.
8
55
  *
@@ -24,32 +71,8 @@ const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
24
71
  */
25
72
  function fedifyMiddleware(federation, createContextData = () => void 0) {
26
73
  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
- }
74
+ onRequest: createOnRequestHandler(federation, createContextData),
75
+ onBeforeResponse
53
76
  });
54
77
  }
55
78
  //#endregion
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { Federation } from "@fedify/fedify/federation";
2
2
  import { createMiddleware } from "@solidjs/start/middleware";
3
3
  import { FetchEvent } from "@solidjs/start/server";
4
4
 
5
- //#region src/index.d.ts
5
+ //#region src/handlers.d.ts
6
6
  /**
7
7
  * A factory function that creates the context data for the
8
8
  * {@link Federation} object.
@@ -13,6 +13,8 @@ import { FetchEvent } from "@solidjs/start/server";
13
13
  * @since 2.2.0
14
14
  */
15
15
  type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Promise<TContextData>;
16
+ //#endregion
17
+ //#region src/index.d.ts
16
18
  /**
17
19
  * Create a SolidStart middleware to integrate with the {@link Federation}
18
20
  * object.
@@ -35,4 +37,4 @@ type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Pr
35
37
  */
36
38
  declare function fedifyMiddleware<TContextData>(federation: Federation<TContextData>, createContextData?: ContextDataFactory<TContextData>): ReturnType<typeof createMiddleware>;
37
39
  //#endregion
38
- export { ContextDataFactory, fedifyMiddleware };
40
+ export { type ContextDataFactory, fedifyMiddleware };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { createMiddleware } from "@solidjs/start/middleware";
2
2
  import { Federation } from "@fedify/fedify/federation";
3
3
  import { FetchEvent } from "@solidjs/start/server";
4
4
 
5
- //#region src/index.d.ts
5
+ //#region src/handlers.d.ts
6
6
  /**
7
7
  * A factory function that creates the context data for the
8
8
  * {@link Federation} object.
@@ -13,6 +13,8 @@ import { FetchEvent } from "@solidjs/start/server";
13
13
  * @since 2.2.0
14
14
  */
15
15
  type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Promise<TContextData>;
16
+ //#endregion
17
+ //#region src/index.d.ts
16
18
  /**
17
19
  * Create a SolidStart middleware to integrate with the {@link Federation}
18
20
  * object.
@@ -35,4 +37,4 @@ type ContextDataFactory<TContextData> = (event: FetchEvent) => TContextData | Pr
35
37
  */
36
38
  declare function fedifyMiddleware<TContextData>(federation: Federation<TContextData>, createContextData?: ContextDataFactory<TContextData>): ReturnType<typeof createMiddleware>;
37
39
  //#endregion
38
- export { ContextDataFactory, fedifyMiddleware };
40
+ export { type ContextDataFactory, fedifyMiddleware };
package/dist/index.js CHANGED
@@ -1,7 +1,54 @@
1
1
  import { createMiddleware } from "@solidjs/start/middleware";
2
- //#region src/index.ts
2
+ //#region src/handlers.ts
3
3
  const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
4
4
  /**
5
+ * Creates the `onRequest` handler wired into SolidStart by
6
+ * `fedifyMiddleware()`.
7
+ *
8
+ * @template TContextData A type of the context data for the
9
+ * {@link Federation} object.
10
+ * @param federation A {@link Federation} object to integrate with SolidStart.
11
+ * @param createContextData A function to create context data for the
12
+ * {@link Federation} object.
13
+ * @returns The `onRequest` handler.
14
+ */
15
+ function createOnRequestHandler(federation, createContextData) {
16
+ return async (event) => {
17
+ const response = await federation.fetch(event.request, {
18
+ contextData: await createContextData(event),
19
+ onNotFound: () => new Response("Not Found", { status: 404 }),
20
+ onNotAcceptable: () => new Response("Not Acceptable", {
21
+ status: 406,
22
+ headers: {
23
+ "Content-Type": "text/plain",
24
+ Vary: "Accept"
25
+ }
26
+ })
27
+ });
28
+ if (response.status === 404) return;
29
+ if (response.status === 406) {
30
+ notAcceptableResponses.set(event.request, response);
31
+ return;
32
+ }
33
+ return response;
34
+ };
35
+ }
36
+ /**
37
+ * Handles the response before SolidStart sends it to the client.
38
+ *
39
+ * @param event The SolidStart {@link FetchEvent} for the current request.
40
+ * @returns The stored 406 response if SolidStart could not handle the route.
41
+ */
42
+ function onBeforeResponse(event) {
43
+ const stored = notAcceptableResponses.get(event.request);
44
+ if (stored != null) {
45
+ notAcceptableResponses.delete(event.request);
46
+ if ((event.response.status ?? 200) === 404) return stored;
47
+ }
48
+ }
49
+ //#endregion
50
+ //#region src/index.ts
51
+ /**
5
52
  * Create a SolidStart middleware to integrate with the {@link Federation}
6
53
  * object.
7
54
  *
@@ -23,32 +70,8 @@ const notAcceptableResponses = /* @__PURE__ */ new WeakMap();
23
70
  */
24
71
  function fedifyMiddleware(federation, createContextData = () => void 0) {
25
72
  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
- }
73
+ onRequest: createOnRequestHandler(federation, createContextData),
74
+ onBeforeResponse
52
75
  });
53
76
  }
54
77
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/solidstart",
3
- "version": "2.4.0-pr.936.41+59c7432c",
3
+ "version": "2.5.0-dev.2271+49d937e2",
4
4
  "description": "Integrate Fedify with SolidStart",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "peerDependencies": {
49
49
  "@solidjs/start": "^1.3.0",
50
- "@fedify/fedify": "^2.4.0-pr.936.41+59c7432c"
50
+ "@fedify/fedify": "^2.5.0-dev.2271+49d937e2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "tsdown": "^0.22.0",
@@ -56,6 +56,8 @@
56
56
  "scripts": {
57
57
  "build:self": "tsdown",
58
58
  "build": "pnpm --filter @fedify/solidstart... run build:self",
59
- "prepublish": "pnpm build"
59
+ "prepublish": "pnpm build",
60
+ "test": "node --experimental-transform-types --test",
61
+ "test:bun": "bun test"
60
62
  }
61
63
  }