@sigil-dev/grimoire 0.4.0 → 0.6.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/README.md +174 -174
- package/index.ts +47 -23
- package/package.json +6 -6
- package/src/{enhance.ts → client/enhance.ts} +2 -1
- package/src/client/index.ts +5 -0
- package/src/{client-router.ts → client/router.ts} +1 -1
- package/src/{vite-plugin.ts → integrations/vite.ts} +4 -4
- package/src/{hydrate.ts → rendering/hydrate.ts} +2 -2
- package/src/{renderer.ts → rendering/index.ts} +39 -15
- package/src/{ssrPlugin.ts → rendering/ssrPlugin.ts} +8 -2
- package/src/{scanner.ts → routing/scanner.ts} +16 -4
- package/src/{transform-routes.ts → routing/transform-routes.ts} +7 -1
- package/src/{fail.ts → sentinels/fail.ts} +1 -1
- package/src/server/build.ts +90 -0
- package/src/{cookie-utils.ts → server/cookie-utils.ts} +66 -66
- package/src/server/coordinator.ts +297 -0
- package/src/{hooks.ts → server/hooks.ts} +1 -1
- package/src/{server.ts → server/index.ts} +153 -105
- package/src/server/plugins.ts +119 -0
- package/src/server/worker.ts +59 -0
- package/src/{typegen.ts → typegen/index.ts} +81 -4
- package/src/types.ts +176 -1
- package/test/context.test.ts +1 -1
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +100 -96
- package/test/hydration.test.ts +1 -1
- package/test/middleware.test.ts +221 -217
- package/test/preload.ts +1 -1
- package/test/redirect-error.test.ts +112 -112
- package/test/rendering.test.ts +319 -310
- package/test/routing.test.ts +2 -2
- package/test/scanning.test.ts +40 -11
- package/test/scope.test.ts +25 -10
- package/test/server.test.ts +150 -1
- package/test/streaming.test.ts +145 -132
- package/test/transform-routes.test.ts +2 -2
- package/test/typegen.test.ts +10 -8
- package/tsconfig.json +3 -1
- package/.grimoire/_routes.dom.js +0 -4
- package/.grimoire/_routes.hydrate.js +0 -4
- package/.grimoire/_routes.ts +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
- package/public/__grimoire__/client.js +0 -86
- package/public/__grimoire__/hydrate.js +0 -101
- package/src/client.ts +0 -4
- package/src/plugins.ts +0 -25
- package/src/sync.ts +0 -18
- /package/src/{scope.ts → client/scope.ts} +0 -0
- /package/src/{head.ts → rendering/head.ts} +0 -0
- /package/src/{manifest-gen.ts → routing/manifest-gen.ts} +0 -0
- /package/src/{router.ts → routing/router.ts} +0 -0
- /package/src/{error.ts → sentinels/error.ts} +0 -0
- /package/src/{redirect.ts → sentinels/redirect.ts} +0 -0
- /package/src/{context.ts → server/context.ts} +0 -0
package/test/typegen.test.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join, sep } from "node:path";
|
|
6
|
-
import type { RouteFile } from "../src/scanner";
|
|
7
|
-
import { scanRoutes } from "../src/scanner";
|
|
6
|
+
import type { RouteFile } from "../src/routing/scanner";
|
|
7
|
+
import { scanRoutes } from "../src/routing/scanner";
|
|
8
8
|
import {
|
|
9
9
|
buildParams,
|
|
10
10
|
generateTypes,
|
|
@@ -416,9 +416,11 @@ describe("generateTypes — route without +page.server.ts", () => {
|
|
|
416
416
|
expect(content).toContain("export type Actions = Record<string, never>;");
|
|
417
417
|
});
|
|
418
418
|
|
|
419
|
-
test("PageProps contains params", async () => {
|
|
419
|
+
test("PageProps contains data and params", async () => {
|
|
420
420
|
const content = await readGenerated("src/routes/blog");
|
|
421
|
-
expect(content).toContain(
|
|
421
|
+
expect(content).toContain(
|
|
422
|
+
"export type PageProps = { data: PageData; params: Params };",
|
|
423
|
+
);
|
|
422
424
|
});
|
|
423
425
|
});
|
|
424
426
|
|
|
@@ -448,10 +450,10 @@ describe("generateTypes — route with +page.server.ts", () => {
|
|
|
448
450
|
expect(content).toContain('Awaited<ReturnType<_PS["load"]>>');
|
|
449
451
|
});
|
|
450
452
|
|
|
451
|
-
test("PageProps =
|
|
453
|
+
test("PageProps = { data: PageData; params: Params }", async () => {
|
|
452
454
|
const content = await readGenerated("src/routes/blog/[slug]");
|
|
453
455
|
expect(content).toContain(
|
|
454
|
-
"export type PageProps =
|
|
456
|
+
"export type PageProps = { data: PageData; params: Params };",
|
|
455
457
|
);
|
|
456
458
|
});
|
|
457
459
|
|
|
@@ -559,8 +561,8 @@ describe("tsc integration", () => {
|
|
|
559
561
|
join(routeDir, "check.ts"),
|
|
560
562
|
`import type { PageProps } from "./$types";
|
|
561
563
|
declare const props: PageProps;
|
|
562
|
-
const _title: string = props.post.title;
|
|
563
|
-
const _views: number = props.post.views;
|
|
564
|
+
const _title: string = props.data.post.title;
|
|
565
|
+
const _views: number = props.data.post.views;
|
|
564
566
|
const _slug: string = props.params.slug;
|
|
565
567
|
export {};`,
|
|
566
568
|
);
|
package/tsconfig.json
CHANGED
package/.grimoire/_routes.dom.js
DELETED
package/.grimoire/_routes.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, createMemo, reconcile, claim, claimText, claimComment, hydrateKeyedList, insert } from "@sigil-dev/runtime";
|
|
2
|
-
export default function P() {
|
|
3
|
-
return (() => {
|
|
4
|
-
const _el0 = document.createElement("div");
|
|
5
|
-
_el0.classList.add("9i0yqs");
|
|
6
|
-
_el0.append(document.createTextNode("secret"));
|
|
7
|
-
return _el0;
|
|
8
|
-
})();
|
|
9
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, createMemo, reconcile, claim, claimText, claimComment, hydrateKeyedList, insert } from "@sigil-dev/runtime";
|
|
2
|
-
export default function P() {
|
|
3
|
-
return (() => {
|
|
4
|
-
const _el0 = claim(__nodes, "div");
|
|
5
|
-
const _el1 = Array.from(_el0.childNodes);
|
|
6
|
-
_el0.classList.add("9i0yqs");
|
|
7
|
-
if (_el1.length === 0)
|
|
8
|
-
_el0.append(document.createTextNode("secret"));
|
|
9
|
-
return _el0;
|
|
10
|
-
})();
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, createMemo, reconcile, claim, claimText, claimComment, hydrateKeyedList, insert } from "@sigil-dev/runtime";
|
|
2
|
-
export default function Login() {
|
|
3
|
-
return (() => {
|
|
4
|
-
const _el0 = document.createElement("form");
|
|
5
|
-
_el0.classList.add("6ulz94");
|
|
6
|
-
return _el0;
|
|
7
|
-
})();
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, createMemo, reconcile, claim, claimText, claimComment, hydrateKeyedList, insert } from "@sigil-dev/runtime";
|
|
2
|
-
export default function Login() {
|
|
3
|
-
return (() => {
|
|
4
|
-
const _el0 = claim(__nodes, "form");
|
|
5
|
-
const _el1 = Array.from(_el0.childNodes);
|
|
6
|
-
_el0.classList.add("6ulz94");
|
|
7
|
-
return _el0;
|
|
8
|
-
})();
|
|
9
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Auto-generated by @sigil-dev/grimoire — do not edit
|
|
2
|
-
|
|
3
|
-
export type Params = {};
|
|
4
|
-
|
|
5
|
-
export type PageData = Record<string, never>;
|
|
6
|
-
export type PageProps = { params: Params };
|
|
7
|
-
export type PageServerLoad = never;
|
|
8
|
-
export type Actions = Record<string, never>;
|
|
9
|
-
|
|
10
|
-
export type LayoutData = Record<string, never>;
|
|
11
|
-
export type LayoutProps = LayoutData & { params: Params; children?: unknown };
|
|
12
|
-
export type LayoutServerLoad = (ctx: {
|
|
13
|
-
params: Params;
|
|
14
|
-
request: Request;
|
|
15
|
-
url: URL;
|
|
16
|
-
locals: App.Locals;
|
|
17
|
-
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
18
|
-
|
|
19
|
-
type _SRV = typeof import("C:/Users/Cane1712/AppData/Local/Temp/grimoire-server-1780504083027/api/hello/+server.js");
|
|
20
|
-
type _HttpMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
21
|
-
type _ServerKeys = Extract<keyof _SRV, _HttpMethods>;
|
|
22
|
-
export type ServerHandlers = {
|
|
23
|
-
[K in _ServerKeys]: (ctx: {
|
|
24
|
-
params: Params;
|
|
25
|
-
request: Request;
|
|
26
|
-
url: URL;
|
|
27
|
-
locals: App.Locals;
|
|
28
|
-
}) => Response | Promise<Response>;
|
|
29
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Auto-generated by @sigil-dev/grimoire — do not edit
|
|
2
|
-
|
|
3
|
-
export type Params = {};
|
|
4
|
-
|
|
5
|
-
export type PageData = Record<string, never>;
|
|
6
|
-
export type PageProps = { params: Params };
|
|
7
|
-
export type PageServerLoad = never;
|
|
8
|
-
export type Actions = Record<string, never>;
|
|
9
|
-
|
|
10
|
-
export type LayoutData = Record<string, never>;
|
|
11
|
-
export type LayoutProps = LayoutData & { params: Params; children?: unknown };
|
|
12
|
-
export type LayoutServerLoad = (ctx: {
|
|
13
|
-
params: Params;
|
|
14
|
-
request: Request;
|
|
15
|
-
url: URL;
|
|
16
|
-
locals: App.Locals;
|
|
17
|
-
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
18
|
-
|
|
19
|
-
type _SRV = typeof import("C:/Users/Cane1712/AppData/Local/Temp/grimoire-server-1780504083027/api/items/+server.js");
|
|
20
|
-
type _HttpMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
21
|
-
type _ServerKeys = Extract<keyof _SRV, _HttpMethods>;
|
|
22
|
-
export type ServerHandlers = {
|
|
23
|
-
[K in _ServerKeys]: (ctx: {
|
|
24
|
-
params: Params;
|
|
25
|
-
request: Request;
|
|
26
|
-
url: URL;
|
|
27
|
-
locals: App.Locals;
|
|
28
|
-
}) => Response | Promise<Response>;
|
|
29
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// .grimoire/_routes.dom.js
|
|
2
|
-
var routes = {};
|
|
3
|
-
|
|
4
|
-
// src/scope.ts
|
|
5
|
-
function withEffectScope(fn) {
|
|
6
|
-
const prev = globalThis.__sigilEffectScope;
|
|
7
|
-
const disposers = [];
|
|
8
|
-
globalThis.__sigilEffectScope = disposers;
|
|
9
|
-
try {
|
|
10
|
-
fn();
|
|
11
|
-
} finally {
|
|
12
|
-
globalThis.__sigilEffectScope = prev;
|
|
13
|
-
}
|
|
14
|
-
return () => {
|
|
15
|
-
for (const d of disposers)
|
|
16
|
-
d();
|
|
17
|
-
disposers.length = 0;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/client-router.ts
|
|
22
|
-
var routeMap = {};
|
|
23
|
-
var disposeCurrentPage = null;
|
|
24
|
-
async function navigate(path) {
|
|
25
|
-
const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
|
|
26
|
-
const json = await res.json();
|
|
27
|
-
const { data, params, pattern, head } = json;
|
|
28
|
-
const Page = routeMap[pattern];
|
|
29
|
-
if (!Page) {
|
|
30
|
-
window.location.href = path;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
disposeCurrentPage?.();
|
|
34
|
-
disposeCurrentPage = null;
|
|
35
|
-
globalThis.__nodes = [];
|
|
36
|
-
let node;
|
|
37
|
-
disposeCurrentPage = withEffectScope(() => {
|
|
38
|
-
node = Page({ data, params });
|
|
39
|
-
});
|
|
40
|
-
const slot = document.getElementById("grimoire-page");
|
|
41
|
-
if (!slot)
|
|
42
|
-
return;
|
|
43
|
-
slot.replaceChildren(node);
|
|
44
|
-
updateHead(head);
|
|
45
|
-
history.pushState({}, "", path);
|
|
46
|
-
currentPath = path;
|
|
47
|
-
window.scrollTo(0, 0);
|
|
48
|
-
}
|
|
49
|
-
var currentPath = location.pathname;
|
|
50
|
-
function initRouter(routes2, initialDispose) {
|
|
51
|
-
routeMap = routes2;
|
|
52
|
-
disposeCurrentPage = initialDispose ?? null;
|
|
53
|
-
document.addEventListener("click", handleClick);
|
|
54
|
-
window.addEventListener("popstate", () => {
|
|
55
|
-
if (location.pathname !== currentPath) {
|
|
56
|
-
currentPath = location.pathname;
|
|
57
|
-
navigate(location.pathname);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function updateHead(headHtml) {
|
|
62
|
-
document.querySelectorAll("[data-grimoire-head]").forEach((el) => el.remove());
|
|
63
|
-
if (!headHtml)
|
|
64
|
-
return;
|
|
65
|
-
const tmp = document.createElement("head");
|
|
66
|
-
tmp.innerHTML = headHtml;
|
|
67
|
-
for (const el of Array.from(tmp.children)) {
|
|
68
|
-
el.dataset.grimoireHead = "1";
|
|
69
|
-
document.head.appendChild(el);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function handleClick(e) {
|
|
73
|
-
const a = e.target.closest("a");
|
|
74
|
-
if (!a)
|
|
75
|
-
return;
|
|
76
|
-
const href = a.getAttribute("href");
|
|
77
|
-
if (!href)
|
|
78
|
-
return;
|
|
79
|
-
if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href))
|
|
80
|
-
return;
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
navigate(href);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/client.ts
|
|
86
|
-
initRouter(routes);
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// .grimoire/_routes.hydrate.js
|
|
2
|
-
var routes = {};
|
|
3
|
-
|
|
4
|
-
// src/scope.ts
|
|
5
|
-
function withEffectScope(fn) {
|
|
6
|
-
const prev = globalThis.__sigilEffectScope;
|
|
7
|
-
const disposers = [];
|
|
8
|
-
globalThis.__sigilEffectScope = disposers;
|
|
9
|
-
try {
|
|
10
|
-
fn();
|
|
11
|
-
} finally {
|
|
12
|
-
globalThis.__sigilEffectScope = prev;
|
|
13
|
-
}
|
|
14
|
-
return () => {
|
|
15
|
-
for (const d of disposers)
|
|
16
|
-
d();
|
|
17
|
-
disposers.length = 0;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/client-router.ts
|
|
22
|
-
var routeMap = {};
|
|
23
|
-
var disposeCurrentPage = null;
|
|
24
|
-
async function navigate(path) {
|
|
25
|
-
const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
|
|
26
|
-
const json = await res.json();
|
|
27
|
-
const { data, params, pattern, head } = json;
|
|
28
|
-
const Page = routeMap[pattern];
|
|
29
|
-
if (!Page) {
|
|
30
|
-
window.location.href = path;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
disposeCurrentPage?.();
|
|
34
|
-
disposeCurrentPage = null;
|
|
35
|
-
globalThis.__nodes = [];
|
|
36
|
-
let node;
|
|
37
|
-
disposeCurrentPage = withEffectScope(() => {
|
|
38
|
-
node = Page({ data, params });
|
|
39
|
-
});
|
|
40
|
-
const slot = document.getElementById("grimoire-page");
|
|
41
|
-
if (!slot)
|
|
42
|
-
return;
|
|
43
|
-
slot.replaceChildren(node);
|
|
44
|
-
updateHead(head);
|
|
45
|
-
history.pushState({}, "", path);
|
|
46
|
-
currentPath = path;
|
|
47
|
-
window.scrollTo(0, 0);
|
|
48
|
-
}
|
|
49
|
-
var currentPath = location.pathname;
|
|
50
|
-
function initRouter(routes2, initialDispose) {
|
|
51
|
-
routeMap = routes2;
|
|
52
|
-
disposeCurrentPage = initialDispose ?? null;
|
|
53
|
-
document.addEventListener("click", handleClick);
|
|
54
|
-
window.addEventListener("popstate", () => {
|
|
55
|
-
if (location.pathname !== currentPath) {
|
|
56
|
-
currentPath = location.pathname;
|
|
57
|
-
navigate(location.pathname);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function updateHead(headHtml) {
|
|
62
|
-
document.querySelectorAll("[data-grimoire-head]").forEach((el) => el.remove());
|
|
63
|
-
if (!headHtml)
|
|
64
|
-
return;
|
|
65
|
-
const tmp = document.createElement("head");
|
|
66
|
-
tmp.innerHTML = headHtml;
|
|
67
|
-
for (const el of Array.from(tmp.children)) {
|
|
68
|
-
el.dataset.grimoireHead = "1";
|
|
69
|
-
document.head.appendChild(el);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function handleClick(e) {
|
|
73
|
-
const a = e.target.closest("a");
|
|
74
|
-
if (!a)
|
|
75
|
-
return;
|
|
76
|
-
const href = a.getAttribute("href");
|
|
77
|
-
if (!href)
|
|
78
|
-
return;
|
|
79
|
-
if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href))
|
|
80
|
-
return;
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
navigate(href);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/hydrate.ts
|
|
86
|
-
var stateEl = document.getElementById("__grimoire_state__");
|
|
87
|
-
var initialDispose;
|
|
88
|
-
if (stateEl) {
|
|
89
|
-
const state = JSON.parse(stateEl.textContent);
|
|
90
|
-
const Page = routes[state.pattern];
|
|
91
|
-
if (Page) {
|
|
92
|
-
const slot = document.getElementById("grimoire-page");
|
|
93
|
-
if (slot) {
|
|
94
|
-
globalThis.__nodes = Array.from(slot.childNodes);
|
|
95
|
-
initialDispose = withEffectScope(() => {
|
|
96
|
-
Page({ data: state.data, params: state.params });
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
initRouter(routes, initialDispose);
|
package/src/client.ts
DELETED
package/src/plugins.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { GrimoirePlugin } from "./types";
|
|
2
|
-
|
|
3
|
-
export async function runHook(
|
|
4
|
-
plugins: GrimoirePlugin[],
|
|
5
|
-
hook: keyof GrimoirePlugin,
|
|
6
|
-
...args: any
|
|
7
|
-
): Promise<void> {
|
|
8
|
-
for (const plugin of plugins) {
|
|
9
|
-
await (plugin[hook] as any)?.(...args);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function runRequestHooks(
|
|
14
|
-
plugins: GrimoirePlugin[],
|
|
15
|
-
req: Request,
|
|
16
|
-
final: () => Promise<Response>,
|
|
17
|
-
): Promise<Response> {
|
|
18
|
-
const chain = plugins
|
|
19
|
-
.filter((p) => p.onRequest)
|
|
20
|
-
.reduceRight(
|
|
21
|
-
(next, plugin) => async () => plugin.onRequest!(req, next),
|
|
22
|
-
final,
|
|
23
|
-
);
|
|
24
|
-
return chain();
|
|
25
|
-
}
|
package/src/sync.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { mkdir } from "node:fs/promises";
|
|
3
|
-
import { isAbsolute, join } from "node:path";
|
|
4
|
-
import { scanRoutes } from "./scanner";
|
|
5
|
-
import { generateTypes } from "./typegen";
|
|
6
|
-
|
|
7
|
-
const routes = process.env.GRIMOIRE_ROUTES ?? "src/routes";
|
|
8
|
-
const routesDir = isAbsolute(routes) ? routes : join(process.cwd(), routes);
|
|
9
|
-
|
|
10
|
-
await mkdir(join(process.cwd(), ".grimoire"), { recursive: true });
|
|
11
|
-
const tree = await scanRoutes(routesDir, process.cwd());
|
|
12
|
-
await generateTypes(tree, {
|
|
13
|
-
projectRoot: process.cwd(),
|
|
14
|
-
routesDir,
|
|
15
|
-
outDir: join(process.cwd(), ".grimoire/types"),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
console.log("Grimoire: types generated");
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|