@server/next 0.25.10 → 0.27.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.
Files changed (63) hide show
  1. package/index.js +2005 -0
  2. package/package.json +17 -13
  3. package/readme.md +1 -0
  4. package/src/{helpers/jsx.js → jsx/jsx-dev-runtime.js} +32 -17
  5. package/src/{helpers/jsx.test.jsx → jsx/jsx-runtime.test.jsx} +1 -1
  6. package/src/ServerError.js +0 -27
  7. package/src/auth/NoSession.js +0 -19
  8. package/src/auth/auth-cookie.test.js +0 -42
  9. package/src/auth/auth-token.test.js +0 -110
  10. package/src/auth/auth.js +0 -62
  11. package/src/auth/index.js +0 -104
  12. package/src/auth/index.test.js +0 -133
  13. package/src/auth/logout.js +0 -20
  14. package/src/auth/providers/email.js +0 -145
  15. package/src/auth/providers/github.js +0 -84
  16. package/src/auth/providers/index.js +0 -4
  17. package/src/auth/session.js +0 -18
  18. package/src/auth/updateUser.js +0 -6
  19. package/src/auth/user.js +0 -9
  20. package/src/context/node.js +0 -68
  21. package/src/context/parseBody.js +0 -107
  22. package/src/context/parseBody.test.js +0 -60
  23. package/src/context/parseCookies.js +0 -9
  24. package/src/context/winter.js +0 -46
  25. package/src/errors/index.js +0 -36
  26. package/src/helpers/StatusError.js +0 -6
  27. package/src/helpers/bucket.js +0 -89
  28. package/src/helpers/bucket.test.js +0 -51
  29. package/src/helpers/color.js +0 -30
  30. package/src/helpers/config.js +0 -64
  31. package/src/helpers/cookies.test.js +0 -23
  32. package/src/helpers/cors.js +0 -24
  33. package/src/helpers/cors.test.js +0 -64
  34. package/src/helpers/createCookies.js +0 -16
  35. package/src/helpers/createId.js +0 -51
  36. package/src/helpers/define.js +0 -18
  37. package/src/helpers/getMachine.js +0 -26
  38. package/src/helpers/handleRequest.js +0 -34
  39. package/src/helpers/index.js +0 -11
  40. package/src/helpers/iterate.js +0 -8
  41. package/src/helpers/parseHeaders.js +0 -15
  42. package/src/helpers/toWeb.js +0 -15
  43. package/src/helpers/types.js +0 -81
  44. package/src/helpers/validate.js +0 -34
  45. package/src/index.d.ts +0 -198
  46. package/src/index.js +0 -268
  47. package/src/index.test.js +0 -87
  48. package/src/index.types.ts +0 -28
  49. package/src/middle/assets.js +0 -17
  50. package/src/middle/assets.test.js +0 -10
  51. package/src/middle/index.js +0 -7
  52. package/src/middle/openapi.js +0 -147
  53. package/src/middle/timer.js +0 -14
  54. package/src/parseResponse.js +0 -111
  55. package/src/pathPattern.js +0 -47
  56. package/src/pathPattern.test.js +0 -99
  57. package/src/polyfill.js +0 -18
  58. package/src/reply.js +0 -153
  59. package/src/router.js +0 -53
  60. package/src/router.test.js +0 -57
  61. package/src/session.test.js +0 -65
  62. package/src/test/toSucceed.js +0 -64
  63. package/src/url.test.js +0 -26
@@ -1,57 +0,0 @@
1
- import server, { router, status } from "./index.js";
2
-
3
- describe("can route properly", () => {
4
- const apiRouter = router()
5
- .get("/hello", (ctx) => `Hello ${ctx.url.pathname}`)
6
- .put("/hello", (ctx) => `Hello ${ctx.url.pathname}`)
7
- .post("/hello", (ctx) => `Hello ${ctx.url.pathname}`);
8
-
9
- const app = server()
10
- .router("/", apiRouter)
11
- .router("/api/", apiRouter)
12
- .get("/", () => "Fallback");
13
- const api = app.test();
14
-
15
- // INTERNAL - so this might change in the future
16
- it("has the correct structure", () => {
17
- const registeredPaths = app.handlers.get.map((h) => h[1]);
18
- expect(registeredPaths).toEqual(["*", "*", "/hello", "/api/hello", "/"]);
19
- });
20
-
21
- it("can get fallback when nothing matches", async () => {
22
- const res = await api.get("/");
23
- expect(res.body).toBe("Fallback");
24
- });
25
-
26
- it("can get the base get", async () => {
27
- const res = await api.get("/hello");
28
- expect(res.body).toBe("Hello /hello");
29
- });
30
-
31
- it("can get the nested get", async () => {
32
- const res = await api.get("/api/hello");
33
- expect(res.body).toBe("Hello /api/hello");
34
- });
35
-
36
- it("can post to the base get", async () => {
37
- const res = await api.post("/hello");
38
- expect(res.body).toBe("Hello /hello");
39
- });
40
-
41
- it("can post to the nested get", async () => {
42
- const res = await api.post("/api/hello");
43
- expect(res.body).toBe("Hello /api/hello");
44
- });
45
-
46
- it("no status reuse", async () => {
47
- const api = server()
48
- .get("/a", () => status(201).send("hello"))
49
- .get("/b", () => ({ hello: "bye" }))
50
- .get("/", () => "Fallback")
51
- .test();
52
- const { status: statusA } = await api.get("/a");
53
- expect(statusA).toBe(201);
54
- const { status: statusB } = await api.get("/b");
55
- expect(statusB).toBe(200);
56
- });
57
- });
@@ -1,65 +0,0 @@
1
- import kv from "polystore";
2
-
3
- import server from "./index.js";
4
-
5
- describe("session", () => {
6
- const store = kv(new Map());
7
- const api = server({ store })
8
- .get("/hello", (ctx) => `Hello ${ctx.session.a}`)
9
- .post("/hello", (ctx) => {
10
- if (!ctx.session.a) ctx.session.a = 0;
11
- ctx.session.a += 1;
12
- return `Bye ${ctx.session.a}`;
13
- })
14
- .get("/", () => "Fallback")
15
- .test();
16
-
17
- it("can get the nested get", async () => {
18
- const cookie = "session=REqA2l022l8Q0tuIRtqLOPUy";
19
- const options = { headers: { cookie } };
20
- await store.set("session:REqA2l022l8Q0tuIRtqLOPUy", { a: 0 });
21
-
22
- const res = await api.get("/hello", options);
23
- expect(res.body).toBe("Hello 0");
24
-
25
- const res2 = await api.post("/hello", {}, options);
26
- expect(res2.body).toBe("Bye 1");
27
-
28
- const res3 = await api.get("/hello", options);
29
- expect(res3.body).toBe("Hello 1");
30
- expect(await store.get("session:REqA2l022l8Q0tuIRtqLOPUy")).toEqual({
31
- a: 1,
32
- });
33
-
34
- const res4 = await api.post("/hello", {}, options);
35
- expect(res4.body).toBe("Bye 2");
36
-
37
- const res5 = await api.get("/hello", options);
38
- expect(res5.body).toBe("Hello 2");
39
- expect(await store.get("session:REqA2l022l8Q0tuIRtqLOPUy")).toEqual({
40
- a: 2,
41
- });
42
- });
43
- });
44
-
45
- describe("missing store", () => {
46
- const api = server({ store: null })
47
- .get("/read", (ctx) => `Bye ${ctx.session.a}`)
48
- .get("/write", (ctx) => {
49
- ctx.session.a = "hello";
50
- return "All good";
51
- })
52
- .test();
53
-
54
- it("cannot read a session without a store", async () => {
55
- const res = await api.get("/read");
56
- expect(res.status).toBe(500);
57
- expect(res.body).toBe("You need a 'store' to read 'ctx.session.a'");
58
- });
59
-
60
- it("cannot write a session without a store", async () => {
61
- const res = await api.get("/write");
62
- expect(res.status).toBe(500);
63
- expect(res.body).toBe("You need a 'store' to write 'ctx.session.a'");
64
- });
65
- });
@@ -1,64 +0,0 @@
1
- import { expect } from "@jest/globals";
2
-
3
- const reset = "\x1b[0m";
4
-
5
- const spaceOrEnter = (msg) => {
6
- if (typeof msg === "string") {
7
- return " ";
8
- }
9
- return "\n";
10
- };
11
-
12
- export default function toSucceed(request, message) {
13
- const pass = request.status >= 200 && request.status < 400;
14
-
15
- if (message && JSON.stringify(request.body) !== JSON.stringify(message)) {
16
- if (pass) {
17
- return {
18
- message: () =>
19
- `${reset}Expected body:${spaceOrEnter(
20
- message,
21
- )}${this.utils.printExpected(message)}\nReceived body:${spaceOrEnter(
22
- request.body,
23
- )}${this.utils.printReceived(request.body)}`,
24
- pass,
25
- };
26
- }
27
-
28
- return {
29
- message: () =>
30
- `${reset}Expected error:${spaceOrEnter(
31
- message,
32
- )}${this.utils.printExpected(message)}\nReceived error:${spaceOrEnter(
33
- request.body,
34
- )}${this.utils.printReceived(request.body)}`,
35
- pass: !pass,
36
- };
37
- }
38
-
39
- if (pass) {
40
- return {
41
- message: () =>
42
- `${reset}Expected ${this.utils.printExpected(
43
- request.status,
44
- )} to be an error code, received body:\n${this.utils.printExpected(
45
- request.body,
46
- )}`,
47
- pass: true,
48
- };
49
- }
50
-
51
- return {
52
- message: () =>
53
- `${reset}Expected ${this.utils.printReceived(
54
- request.status,
55
- )} to succeed, received body:\n${this.utils.printReceived(
56
- request.body,
57
- null,
58
- 2,
59
- )}`,
60
- pass: false,
61
- };
62
- }
63
-
64
- expect.extend({ toSucceed });
package/src/url.test.js DELETED
@@ -1,26 +0,0 @@
1
- import server from "./index.js";
2
-
3
- describe("can match the url", () => {
4
- it("stops at the first matching route", async () => {
5
- const api = server()
6
- .get("/:id", (ctx) => ctx.url.params)
7
- .get("/*", (ctx) => ctx.url.params)
8
- .test();
9
-
10
- const { body, headers } = await api.get("/hello");
11
- expect(body).toEqual({ id: "hello" });
12
- expect(headers["content-type"]).toEqual("application/json");
13
- });
14
-
15
- it("but it doesn't if it's a use", async () => {
16
- const api = server()
17
- .use(() => {}) // No-op
18
- .get("/:id", (ctx) => ctx.url.params)
19
- .get("/*", (ctx) => ctx.url.params)
20
- .test();
21
-
22
- const { body, headers, ...rest } = await api.get("/hello");
23
- expect(body).toEqual({ id: "hello" });
24
- expect(headers["content-type"]).toEqual("application/json");
25
- });
26
- });