@sigil-dev/grimoire 0.4.0 → 0.5.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/index.ts +29 -23
- package/package.json +1 -1
- package/public/__grimoire__/client.js +5 -36
- package/public/__grimoire__/hydrate.js +7 -45
- package/src/build.ts +88 -0
- package/src/cookie-utils.ts +66 -66
- package/src/plugins.ts +19 -5
- package/src/renderer.ts +12 -1
- package/src/server.ts +81 -81
- package/src/ssrPlugin.ts +7 -2
- package/src/transform-routes.ts +6 -1
- package/src/typegen.ts +77 -3
- package/src/types.ts +45 -1
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +96 -96
- package/test/middleware.test.ts +217 -217
- package/test/redirect-error.test.ts +112 -112
- package/test/rendering.test.ts +310 -310
- package/test/server.test.ts +120 -0
- package/test/streaming.test.ts +132 -132
- package/test/typegen.test.ts +6 -6
- package/.grimoire/_routes.dom.js +0 -4
- package/.grimoire/_routes.hydrate.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503001657_protected__page.dom.js +0 -9
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503001657_protected__page.hydrate.js +0 -11
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503161592_protected__page.dom.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503161592_protected__page.hydrate.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503395872_login.dom.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503395872_login.hydrate.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503614350_login.dom.js +0 -4
- package/.grimoire/compiled/0-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503614350_login.hydrate.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503001657_login__page.dom.js +0 -8
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503001657_login__page.hydrate.js +0 -9
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503161592_login__page.dom.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503161592_login__page.hydrate.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503395872_protected.dom.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503395872_protected.hydrate.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503614350_protected.dom.js +0 -4
- package/.grimoire/compiled/1-C__Users_Cane1712_AppData_Local_Temp_grimoire-actions-1780503614350_protected.hydrate.js +0 -4
- package/.grimoire/tsconfig.generated.json +0 -11
- package/.grimoire/types/ambient.d.ts +0 -6
- package/.grimoire/types/api/hello/$types.d.ts +0 -29
- package/.grimoire/types/api/items/$types.d.ts +0 -29
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { redirect, isRedirectResult } from "../src/redirect";
|
|
3
|
-
import { error, isErrorResult } from "../src/error";
|
|
4
|
-
|
|
5
|
-
describe("redirect()", () => {
|
|
6
|
-
test("throws a RedirectResult", () => {
|
|
7
|
-
try {
|
|
8
|
-
redirect(302, "/login");
|
|
9
|
-
expect(true).toBe(false); // should not reach
|
|
10
|
-
} catch (e) {
|
|
11
|
-
expect(isRedirectResult(e)).toBe(true);
|
|
12
|
-
expect(e.status).toBe(302);
|
|
13
|
-
expect(e.location).toBe("/login");
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("isRedirectResult returns false for plain objects", () => {
|
|
18
|
-
expect(isRedirectResult({ status: 302, location: "/login" })).toBe(false);
|
|
19
|
-
expect(isRedirectResult(null)).toBe(false);
|
|
20
|
-
expect(isRedirectResult(undefined)).toBe(false);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("works with different status codes", () => {
|
|
24
|
-
try {
|
|
25
|
-
redirect(301, "/old");
|
|
26
|
-
} catch (e) {
|
|
27
|
-
expect(e.status).toBe(301);
|
|
28
|
-
expect(e.location).toBe("/old");
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
redirect(303, "/other");
|
|
32
|
-
} catch (e) {
|
|
33
|
-
expect(e.status).toBe(303);
|
|
34
|
-
expect(e.location).toBe("/other");
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
redirect(307, "/temp");
|
|
38
|
-
} catch (e) {
|
|
39
|
-
expect(e.status).toBe(307);
|
|
40
|
-
expect(e.location).toBe("/temp");
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("error()", () => {
|
|
46
|
-
test("throws an ErrorResult with status and message", () => {
|
|
47
|
-
try {
|
|
48
|
-
error(404, "Not found");
|
|
49
|
-
expect(true).toBe(false);
|
|
50
|
-
} catch (e) {
|
|
51
|
-
expect(isErrorResult(e)).toBe(true);
|
|
52
|
-
expect(e.status).toBe(404);
|
|
53
|
-
expect(e.message).toBe("Not found");
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("isErrorResult returns false for plain objects", () => {
|
|
58
|
-
expect(isErrorResult({ status: 404, message: "Not found" })).toBe(false);
|
|
59
|
-
expect(isErrorResult(null)).toBe(false);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("works with different status codes", () => {
|
|
63
|
-
try {
|
|
64
|
-
error(401, "Unauthorized");
|
|
65
|
-
} catch (e) {
|
|
66
|
-
expect(e.status).toBe(401);
|
|
67
|
-
expect(e.message).toBe("Unauthorized");
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
error(500, "Internal Server Error");
|
|
71
|
-
} catch (e) {
|
|
72
|
-
expect(e.status).toBe(500);
|
|
73
|
-
expect(e.message).toBe("Internal Server Error");
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("redirect and error together", () => {
|
|
79
|
-
test("can be caught in sequence", async () => {
|
|
80
|
-
let caught = 0;
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
redirect(302, "/login");
|
|
84
|
-
} catch (e) {
|
|
85
|
-
if (isRedirectResult(e)) caught++;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
error(404, "Not found");
|
|
90
|
-
} catch (e) {
|
|
91
|
-
if (isErrorResult(e)) caught++;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
expect(caught).toBe(2);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("redirect and error are distinguishable", () => {
|
|
98
|
-
try {
|
|
99
|
-
redirect(302, "/login");
|
|
100
|
-
} catch (e) {
|
|
101
|
-
expect(isRedirectResult(e)).toBe(true);
|
|
102
|
-
expect(isErrorResult(e)).toBe(false);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
error(404, "Not found");
|
|
107
|
-
} catch (e) {
|
|
108
|
-
expect(isErrorResult(e)).toBe(true);
|
|
109
|
-
expect(isRedirectResult(e)).toBe(false);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { redirect, isRedirectResult } from "../src/redirect";
|
|
3
|
+
import { error, isErrorResult } from "../src/error";
|
|
4
|
+
|
|
5
|
+
describe("redirect()", () => {
|
|
6
|
+
test("throws a RedirectResult", () => {
|
|
7
|
+
try {
|
|
8
|
+
redirect(302, "/login");
|
|
9
|
+
expect(true).toBe(false); // should not reach
|
|
10
|
+
} catch (e) {
|
|
11
|
+
expect(isRedirectResult(e)).toBe(true);
|
|
12
|
+
expect(e.status).toBe(302);
|
|
13
|
+
expect(e.location).toBe("/login");
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("isRedirectResult returns false for plain objects", () => {
|
|
18
|
+
expect(isRedirectResult({ status: 302, location: "/login" })).toBe(false);
|
|
19
|
+
expect(isRedirectResult(null)).toBe(false);
|
|
20
|
+
expect(isRedirectResult(undefined)).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("works with different status codes", () => {
|
|
24
|
+
try {
|
|
25
|
+
redirect(301, "/old");
|
|
26
|
+
} catch (e) {
|
|
27
|
+
expect(e.status).toBe(301);
|
|
28
|
+
expect(e.location).toBe("/old");
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
redirect(303, "/other");
|
|
32
|
+
} catch (e) {
|
|
33
|
+
expect(e.status).toBe(303);
|
|
34
|
+
expect(e.location).toBe("/other");
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
redirect(307, "/temp");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
expect(e.status).toBe(307);
|
|
40
|
+
expect(e.location).toBe("/temp");
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("error()", () => {
|
|
46
|
+
test("throws an ErrorResult with status and message", () => {
|
|
47
|
+
try {
|
|
48
|
+
error(404, "Not found");
|
|
49
|
+
expect(true).toBe(false);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
expect(isErrorResult(e)).toBe(true);
|
|
52
|
+
expect(e.status).toBe(404);
|
|
53
|
+
expect(e.message).toBe("Not found");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("isErrorResult returns false for plain objects", () => {
|
|
58
|
+
expect(isErrorResult({ status: 404, message: "Not found" })).toBe(false);
|
|
59
|
+
expect(isErrorResult(null)).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("works with different status codes", () => {
|
|
63
|
+
try {
|
|
64
|
+
error(401, "Unauthorized");
|
|
65
|
+
} catch (e) {
|
|
66
|
+
expect(e.status).toBe(401);
|
|
67
|
+
expect(e.message).toBe("Unauthorized");
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
error(500, "Internal Server Error");
|
|
71
|
+
} catch (e) {
|
|
72
|
+
expect(e.status).toBe(500);
|
|
73
|
+
expect(e.message).toBe("Internal Server Error");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("redirect and error together", () => {
|
|
79
|
+
test("can be caught in sequence", async () => {
|
|
80
|
+
let caught = 0;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
redirect(302, "/login");
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (isRedirectResult(e)) caught++;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
error(404, "Not found");
|
|
90
|
+
} catch (e) {
|
|
91
|
+
if (isErrorResult(e)) caught++;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
expect(caught).toBe(2);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("redirect and error are distinguishable", () => {
|
|
98
|
+
try {
|
|
99
|
+
redirect(302, "/login");
|
|
100
|
+
} catch (e) {
|
|
101
|
+
expect(isRedirectResult(e)).toBe(true);
|
|
102
|
+
expect(isErrorResult(e)).toBe(false);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
error(404, "Not found");
|
|
107
|
+
} catch (e) {
|
|
108
|
+
expect(isErrorResult(e)).toBe(true);
|
|
109
|
+
expect(isRedirectResult(e)).toBe(false);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|