gemi 0.2.1 → 0.3.2
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/app/App.d.ts +11 -13
- package/dist/app/App.d.ts.map +1 -1
- package/dist/app/createComponentTree.d.ts +4 -0
- package/dist/app/createComponentTree.d.ts.map +1 -0
- package/dist/app/createFlatViewRoutes.d.ts +6 -0
- package/dist/app/createFlatViewRoutes.d.ts.map +1 -0
- package/dist/app/createRouteManifest.d.ts +3 -0
- package/dist/app/createRouteManifest.d.ts.map +1 -0
- package/dist/app/index.js +125 -124
- package/dist/bin/gemi +0 -0
- package/dist/client/ClientRouter.d.ts +2 -0
- package/dist/client/ClientRouter.d.ts.map +1 -1
- package/dist/client/ClientRouterContext.d.ts +1 -0
- package/dist/client/ClientRouterContext.d.ts.map +1 -1
- package/dist/client/createRoot.d.ts.map +1 -1
- package/dist/client/helpers/flattenComponentTree.d.ts +1 -1
- package/dist/client/helpers/flattenComponentTree.d.ts.map +1 -1
- package/dist/client/index.js +23 -37
- package/dist/client/init.d.ts.map +1 -1
- package/dist/client/types.d.ts +2 -2
- package/dist/client/types.d.ts.map +1 -1
- package/dist/http/ApiRouter.d.ts +19 -31
- package/dist/http/ApiRouter.d.ts.map +1 -1
- package/dist/http/Controller.d.ts +2 -1
- package/dist/http/Controller.d.ts.map +1 -1
- package/dist/http/ViewRouter.d.ts +10 -10
- package/dist/http/ViewRouter.d.ts.map +1 -1
- package/dist/http/index.js +82 -36
- package/package.json +6 -3
package/dist/app/App.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ interface RenderParams {
|
|
|
15
15
|
serverManifest: Record<string, any>;
|
|
16
16
|
}
|
|
17
17
|
interface AppParams {
|
|
18
|
-
viewRouter: new (
|
|
19
|
-
apiRouter: new (
|
|
18
|
+
viewRouter: new () => ViewRouter;
|
|
19
|
+
apiRouter: new () => ApiRouter;
|
|
20
20
|
plugins?: (new () => Plugin)[];
|
|
21
21
|
middlewareAliases?: Record<string, new () => Middleware>;
|
|
22
22
|
root: ComponentType;
|
|
@@ -44,16 +44,16 @@ export declare class App {
|
|
|
44
44
|
kind: string;
|
|
45
45
|
data?: undefined;
|
|
46
46
|
headers?: undefined;
|
|
47
|
-
status?: undefined;
|
|
48
47
|
} | {
|
|
49
48
|
kind: string;
|
|
50
|
-
data:
|
|
51
|
-
headers:
|
|
52
|
-
|
|
49
|
+
data: {};
|
|
50
|
+
headers: {
|
|
51
|
+
"Set-Cookie": string;
|
|
52
|
+
};
|
|
53
53
|
} | {
|
|
54
54
|
kind: string;
|
|
55
55
|
data: {
|
|
56
|
-
[x: string]:
|
|
56
|
+
[x: string]: any;
|
|
57
57
|
pageData?: undefined;
|
|
58
58
|
auth?: undefined;
|
|
59
59
|
routeManifest?: undefined;
|
|
@@ -61,14 +61,14 @@ export declare class App {
|
|
|
61
61
|
componentTree?: undefined;
|
|
62
62
|
};
|
|
63
63
|
meta: any[];
|
|
64
|
-
headers:
|
|
64
|
+
headers: {};
|
|
65
65
|
head?: undefined;
|
|
66
66
|
status?: undefined;
|
|
67
67
|
} | {
|
|
68
68
|
kind: string;
|
|
69
69
|
data: {
|
|
70
70
|
pageData: {
|
|
71
|
-
[x: string]:
|
|
71
|
+
[x: string]: any;
|
|
72
72
|
};
|
|
73
73
|
auth: {
|
|
74
74
|
user: any;
|
|
@@ -80,11 +80,9 @@ export declare class App {
|
|
|
80
80
|
currentPath: string;
|
|
81
81
|
is404: boolean;
|
|
82
82
|
};
|
|
83
|
-
componentTree: (string[] |
|
|
84
|
-
[x: string]: ComponentTree;
|
|
85
|
-
})[];
|
|
83
|
+
componentTree: ([string, [string, [string, [string, [string, [string, [string, [string, [string, [string, [string, any[]][]][]][]][]][]][]][]][]][]][]] | (string | any[])[])[];
|
|
86
84
|
};
|
|
87
|
-
head:
|
|
85
|
+
head: {};
|
|
88
86
|
headers: {
|
|
89
87
|
"Content-Type": string;
|
|
90
88
|
"Cache-Control": string;
|
package/dist/app/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../app/App.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAGV,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAKpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../app/App.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAGV,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAKpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAS3C,OAAO,EAAE,aAAa,EAA2B,MAAM,OAAO,CAAC;AAE/D,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrC;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,UAAU,UAAU,CAAC;IACjC,SAAS,EAAE,UAAU,SAAS,CAA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AChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CAoBvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFlatViewRoutes.d.ts","sourceRoot":"","sources":["../../app/createFlatViewRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEjE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY;UAG7C,aAAa,EAAE;gBAAc,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE;GA8CxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRouteManifest.d.ts","sourceRoot":"","sources":["../../app/createRouteManifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,4BAiCvD"}
|
package/dist/app/index.js
CHANGED
|
@@ -1311,111 +1311,115 @@ class RequestBreakerError extends Error {
|
|
|
1311
1311
|
import {AsyncLocalStorage} from "async_hooks";
|
|
1312
1312
|
var requestContext = new AsyncLocalStorage;
|
|
1313
1313
|
|
|
1314
|
-
//
|
|
1315
|
-
function
|
|
1316
|
-
|
|
1317
|
-
const
|
|
1314
|
+
// client/helpers/flattenComponentTree.ts
|
|
1315
|
+
function flattenComponentTree(componentTree) {
|
|
1316
|
+
let out = [];
|
|
1317
|
+
for (const [root, branches] of componentTree) {
|
|
1318
|
+
out.push(root, ...flattenComponentTree(branches).flat());
|
|
1319
|
+
}
|
|
1320
|
+
return Array.from(new Set(out));
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
// app/createComponentTree.ts
|
|
1324
|
+
function createComponentTree(routes) {
|
|
1318
1325
|
const componentTree = [];
|
|
1319
|
-
for (const [
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
const result2 = viewConfigOrViewRouter.prepare();
|
|
1326
|
-
children = result2.children;
|
|
1327
|
-
rootHandler = result2.exec;
|
|
1328
|
-
flatRoutes[rootPath] = {
|
|
1329
|
-
exec: [rootHandler],
|
|
1330
|
-
middleware: result2.middlewares
|
|
1331
|
-
};
|
|
1332
|
-
if (Object.keys(children).length > 0) {
|
|
1333
|
-
layoutViewPath = result2.viewPath;
|
|
1326
|
+
for (const [_2, routeHandler] of Object.entries(routes)) {
|
|
1327
|
+
if ("prepare" in routeHandler) {
|
|
1328
|
+
const { viewPath, children } = routeHandler.prepare();
|
|
1329
|
+
if (Object.entries(children).length > 0) {
|
|
1330
|
+
const branch = createComponentTree(children);
|
|
1331
|
+
componentTree.push([viewPath, branch]);
|
|
1334
1332
|
} else {
|
|
1335
|
-
|
|
1336
|
-
componentTree.push([result2.viewPath]);
|
|
1333
|
+
componentTree.push([viewPath, []]);
|
|
1337
1334
|
}
|
|
1338
1335
|
} else {
|
|
1339
|
-
const router = new
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
const middleware = new app.middlewareAliases[alias];
|
|
1343
|
-
return middleware.run;
|
|
1344
|
-
}
|
|
1345
|
-
}).filter(Boolean);
|
|
1346
|
-
rootMiddleware.push(router.middleware, ...middlewares);
|
|
1347
|
-
children = router.routes;
|
|
1336
|
+
const router = new routeHandler;
|
|
1337
|
+
const branch = createComponentTree(router.routes);
|
|
1338
|
+
componentTree.push(...branch);
|
|
1348
1339
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
const
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
]
|
|
1340
|
+
}
|
|
1341
|
+
return componentTree;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// app/createFlatViewRoutes.ts
|
|
1345
|
+
function createFlatViewRoutes(routes) {
|
|
1346
|
+
const flatRoutes = {};
|
|
1347
|
+
for (const [routePath, viewConfigOrViewRouter] of Object.entries(routes)) {
|
|
1348
|
+
if ("prepare" in viewConfigOrViewRouter) {
|
|
1349
|
+
const route = viewConfigOrViewRouter.prepare();
|
|
1350
|
+
if (Object.entries(route.children).length > 0) {
|
|
1351
|
+
const result = createFlatViewRoutes(route.children);
|
|
1352
|
+
if (route.kind === "view") {
|
|
1353
|
+
flatRoutes[routePath] = {
|
|
1354
|
+
exec: [route.exec],
|
|
1355
|
+
middleware: route.middlewares
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
for (const [path, { exec, middleware }] of Object.entries(result)) {
|
|
1359
|
+
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
1360
|
+
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
1361
|
+
flatRoutes[_key] = {
|
|
1362
|
+
exec,
|
|
1363
|
+
middleware: [...route.middlewares, ...middleware]
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1368
1366
|
} else {
|
|
1369
|
-
|
|
1367
|
+
flatRoutes[routePath] = {
|
|
1368
|
+
exec: [route.exec],
|
|
1369
|
+
middleware: route.middlewares
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
} else {
|
|
1373
|
+
const router = new viewConfigOrViewRouter;
|
|
1374
|
+
const result = createFlatViewRoutes(router.routes);
|
|
1375
|
+
for (const [path, { exec, middleware }] of Object.entries(result)) {
|
|
1376
|
+
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
1377
|
+
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
1378
|
+
flatRoutes[_key] = {
|
|
1379
|
+
exec,
|
|
1380
|
+
middleware: [...router.middlewares, ...middleware]
|
|
1381
|
+
};
|
|
1370
1382
|
}
|
|
1371
1383
|
}
|
|
1372
1384
|
}
|
|
1373
|
-
return
|
|
1374
|
-
flatRoutes,
|
|
1375
|
-
routeManifest,
|
|
1376
|
-
componentTree
|
|
1377
|
-
};
|
|
1385
|
+
return flatRoutes;
|
|
1378
1386
|
}
|
|
1379
1387
|
|
|
1380
|
-
//
|
|
1381
|
-
function
|
|
1382
|
-
const
|
|
1383
|
-
for (const
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1388
|
+
// app/createRouteManifest.ts
|
|
1389
|
+
function createRouteManifest(routes) {
|
|
1390
|
+
const routeManifest = {};
|
|
1391
|
+
for (const [routePath, routeHandler] of Object.entries(routes)) {
|
|
1392
|
+
if ("prepare" in routeHandler) {
|
|
1393
|
+
const { viewPath, children, kind } = routeHandler.prepare();
|
|
1394
|
+
if (kind === "view") {
|
|
1395
|
+
routeManifest[routePath] = [viewPath];
|
|
1396
|
+
}
|
|
1397
|
+
if (Object.entries(children).length > 0) {
|
|
1398
|
+
const manifest = createRouteManifest(children);
|
|
1399
|
+
for (const [path, viewPaths] of Object.entries(manifest)) {
|
|
1400
|
+
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
1401
|
+
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
1402
|
+
routeManifest[_key] = [viewPath, ...viewPaths];
|
|
1403
|
+
}
|
|
1404
|
+
} else {
|
|
1405
|
+
routeManifest[routePath] = [viewPath];
|
|
1406
|
+
}
|
|
1386
1407
|
} else {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1408
|
+
const router = new routeHandler;
|
|
1409
|
+
const manifest = createRouteManifest(router.routes);
|
|
1410
|
+
for (const [path, viewPaths] of Object.entries(manifest)) {
|
|
1411
|
+
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
1412
|
+
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
1413
|
+
routeManifest[_key] = viewPaths;
|
|
1390
1414
|
}
|
|
1391
1415
|
}
|
|
1392
1416
|
}
|
|
1393
|
-
return
|
|
1417
|
+
return routeManifest;
|
|
1394
1418
|
}
|
|
1395
1419
|
|
|
1396
1420
|
// app/App.ts
|
|
1397
1421
|
import {renderToReadableStream} from "react-dom/server.browser";
|
|
1398
1422
|
import {createElement, Fragment} from "react";
|
|
1399
|
-
var prepareViewData = function(result) {
|
|
1400
|
-
return result.reduce((acc, next) => {
|
|
1401
|
-
return {
|
|
1402
|
-
pageData: {
|
|
1403
|
-
...acc.pageData,
|
|
1404
|
-
...next.data
|
|
1405
|
-
},
|
|
1406
|
-
headers: {
|
|
1407
|
-
...acc.headers,
|
|
1408
|
-
...next.headers
|
|
1409
|
-
},
|
|
1410
|
-
head: {
|
|
1411
|
-
...acc.head,
|
|
1412
|
-
title: next?.head?.title ?? acc.head?.title ?? "Gemi App",
|
|
1413
|
-
meta: [...acc.head?.meta ?? [], ...next?.head?.meta ?? []],
|
|
1414
|
-
link: [...acc.head?.link ?? [], ...next?.head?.link ?? []]
|
|
1415
|
-
}
|
|
1416
|
-
};
|
|
1417
|
-
}, { pageData: {}, headers: {}, head: {} });
|
|
1418
|
-
};
|
|
1419
1423
|
|
|
1420
1424
|
class App {
|
|
1421
1425
|
flatViewRoutes = {};
|
|
@@ -1431,13 +1435,11 @@ class App {
|
|
|
1431
1435
|
viewRouter;
|
|
1432
1436
|
Root;
|
|
1433
1437
|
constructor(params) {
|
|
1434
|
-
console.log("[App] initialized");
|
|
1435
1438
|
this.params = params;
|
|
1436
1439
|
this.apiRouter = params.apiRouter;
|
|
1437
1440
|
this.viewRouter = params.viewRouter;
|
|
1438
1441
|
this.Root = params.root;
|
|
1439
1442
|
this.prepare();
|
|
1440
|
-
console.log("[App] routes are prepared");
|
|
1441
1443
|
this.appId = generateETag(Date.now());
|
|
1442
1444
|
}
|
|
1443
1445
|
prepare() {
|
|
@@ -1464,10 +1466,9 @@ class App {
|
|
|
1464
1466
|
};
|
|
1465
1467
|
}
|
|
1466
1468
|
}
|
|
1467
|
-
|
|
1468
|
-
this.componentTree =
|
|
1469
|
-
this.routeManifest =
|
|
1470
|
-
this.flatViewRoutes = flatRoutes;
|
|
1469
|
+
this.flatViewRoutes = createFlatViewRoutes(viewRouters);
|
|
1470
|
+
this.componentTree = createComponentTree(viewRouters);
|
|
1471
|
+
this.routeManifest = createRouteManifest(viewRouters);
|
|
1471
1472
|
this.flatApiRoutes = this.flattenApiRoutes(apiRouters);
|
|
1472
1473
|
}
|
|
1473
1474
|
printName() {
|
|
@@ -1544,7 +1545,12 @@ class App {
|
|
|
1544
1545
|
middlewares = handler.middleware;
|
|
1545
1546
|
}
|
|
1546
1547
|
}
|
|
1547
|
-
const reqWithMiddlewares = middlewares.
|
|
1548
|
+
const reqWithMiddlewares = middlewares.map((middleware) => {
|
|
1549
|
+
if (typeof middleware === "string") {
|
|
1550
|
+
return new this.middlewareAliases[middleware]().run;
|
|
1551
|
+
}
|
|
1552
|
+
return middleware;
|
|
1553
|
+
}).reduce((acc, middleware) => {
|
|
1548
1554
|
return async (req2, ctx) => {
|
|
1549
1555
|
return {
|
|
1550
1556
|
...await acc(req2, ctx),
|
|
@@ -1553,21 +1559,12 @@ class App {
|
|
|
1553
1559
|
};
|
|
1554
1560
|
}, (_req, _ctx) => Promise.resolve({}));
|
|
1555
1561
|
const reqCtx = new Map;
|
|
1556
|
-
const
|
|
1562
|
+
const data = await requestContext.run(reqCtx, async () => {
|
|
1557
1563
|
await reqWithMiddlewares(req, reqCtx);
|
|
1558
1564
|
return await Promise.all(handlers.map((fn) => fn(req, params, this)));
|
|
1559
1565
|
});
|
|
1560
|
-
let is404 = false;
|
|
1561
|
-
for (const res of result) {
|
|
1562
|
-
const [data] = Object.values(res.data ?? {});
|
|
1563
|
-
if (data?.status === 404) {
|
|
1564
|
-
is404 = true;
|
|
1565
|
-
break;
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
1566
|
return {
|
|
1569
|
-
|
|
1570
|
-
result,
|
|
1567
|
+
data,
|
|
1571
1568
|
currentPathName,
|
|
1572
1569
|
params,
|
|
1573
1570
|
user: reqCtx.get("user") ?? null
|
|
@@ -1602,11 +1599,12 @@ class App {
|
|
|
1602
1599
|
...err.payload.api
|
|
1603
1600
|
};
|
|
1604
1601
|
}
|
|
1602
|
+
throw err;
|
|
1605
1603
|
}
|
|
1606
1604
|
if (exec) {
|
|
1607
|
-
let
|
|
1605
|
+
let data = {};
|
|
1608
1606
|
try {
|
|
1609
|
-
|
|
1607
|
+
data = await exec(req, params, this);
|
|
1610
1608
|
} catch (err) {
|
|
1611
1609
|
if (err instanceof RequestBreakerError) {
|
|
1612
1610
|
return {
|
|
@@ -1614,18 +1612,16 @@ class App {
|
|
|
1614
1612
|
...err.payload.api
|
|
1615
1613
|
};
|
|
1616
1614
|
}
|
|
1615
|
+
throw err;
|
|
1617
1616
|
}
|
|
1618
|
-
const { data, cookies = {}, headers, status } = result;
|
|
1619
1617
|
return {
|
|
1620
1618
|
kind: "api",
|
|
1621
1619
|
data,
|
|
1622
1620
|
headers: {
|
|
1623
|
-
|
|
1624
|
-
"Set-Cookie": Object.entries(cookies).map(([name, config]) => {
|
|
1621
|
+
"Set-Cookie": Object.entries({}).map(([name, config]) => {
|
|
1625
1622
|
return `${name}=${config.value}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${config.maxAge}`;
|
|
1626
1623
|
}).join(", ")
|
|
1627
|
-
}
|
|
1628
|
-
status
|
|
1624
|
+
}
|
|
1629
1625
|
};
|
|
1630
1626
|
}
|
|
1631
1627
|
});
|
|
@@ -1654,16 +1650,21 @@ class App {
|
|
|
1654
1650
|
headers: {}
|
|
1655
1651
|
};
|
|
1656
1652
|
}
|
|
1657
|
-
const {
|
|
1658
|
-
const
|
|
1653
|
+
const { data, params, currentPathName, user } = pageData;
|
|
1654
|
+
const viewData = data.reduce((acc, data2) => {
|
|
1655
|
+
return {
|
|
1656
|
+
...acc,
|
|
1657
|
+
...data2
|
|
1658
|
+
};
|
|
1659
|
+
}, {});
|
|
1659
1660
|
if (url.searchParams.get("json")) {
|
|
1660
1661
|
return {
|
|
1661
1662
|
kind: "viewData",
|
|
1662
1663
|
data: {
|
|
1663
|
-
[url.pathname]:
|
|
1664
|
+
[url.pathname]: viewData
|
|
1664
1665
|
},
|
|
1665
1666
|
meta: [],
|
|
1666
|
-
headers:
|
|
1667
|
+
headers: {}
|
|
1667
1668
|
};
|
|
1668
1669
|
}
|
|
1669
1670
|
let cookieHeaders = {};
|
|
@@ -1677,7 +1678,7 @@ class App {
|
|
|
1677
1678
|
kind: "view",
|
|
1678
1679
|
data: {
|
|
1679
1680
|
pageData: {
|
|
1680
|
-
[url.pathname]:
|
|
1681
|
+
[url.pathname]: viewData
|
|
1681
1682
|
},
|
|
1682
1683
|
auth: { user },
|
|
1683
1684
|
routeManifest: this.routeManifest,
|
|
@@ -1685,19 +1686,18 @@ class App {
|
|
|
1685
1686
|
pathname: currentPathName,
|
|
1686
1687
|
params,
|
|
1687
1688
|
currentPath: url.pathname,
|
|
1688
|
-
is404
|
|
1689
|
+
is404: false
|
|
1689
1690
|
},
|
|
1690
|
-
componentTree: [["404"], ...this.componentTree]
|
|
1691
|
+
componentTree: [["404", []], ...this.componentTree]
|
|
1691
1692
|
},
|
|
1692
|
-
head:
|
|
1693
|
+
head: {},
|
|
1693
1694
|
headers: {
|
|
1694
|
-
...data.headers,
|
|
1695
1695
|
"Content-Type": "text/html",
|
|
1696
1696
|
"Cache-Control": user ? "private, no-cache, no-store, max-age=0, must-revalidate" : "public, max-age=864000, must-revalidate",
|
|
1697
1697
|
ETag: this.appId,
|
|
1698
1698
|
...cookieHeaders
|
|
1699
1699
|
},
|
|
1700
|
-
status:
|
|
1700
|
+
status: 200
|
|
1701
1701
|
};
|
|
1702
1702
|
}
|
|
1703
1703
|
}
|
|
@@ -1737,7 +1737,10 @@ class App {
|
|
|
1737
1737
|
let appDir = null;
|
|
1738
1738
|
const template = (viewName, path) => `"${viewName}": () => import("${path}")`;
|
|
1739
1739
|
const templates = [];
|
|
1740
|
-
for (const fileName of
|
|
1740
|
+
for (const fileName of [
|
|
1741
|
+
"404",
|
|
1742
|
+
...flattenComponentTree(this.componentTree)
|
|
1743
|
+
]) {
|
|
1741
1744
|
if (!manifest) {
|
|
1742
1745
|
appDir = `${process.env.APP_DIR}`;
|
|
1743
1746
|
const mod = await import(`${appDir}/views/${fileName}.tsx`);
|
|
@@ -1758,7 +1761,6 @@ class App {
|
|
|
1758
1761
|
children: [
|
|
1759
1762
|
styles,
|
|
1760
1763
|
createElement(this.Root, {
|
|
1761
|
-
head,
|
|
1762
1764
|
data,
|
|
1763
1765
|
viewImportMap
|
|
1764
1766
|
})
|
|
@@ -1776,9 +1778,8 @@ class App {
|
|
|
1776
1778
|
});
|
|
1777
1779
|
}
|
|
1778
1780
|
if (result.kind === "api") {
|
|
1779
|
-
const { data, headers
|
|
1781
|
+
const { data, headers } = result;
|
|
1780
1782
|
return new Response(JSON.stringify(data), {
|
|
1781
|
-
status,
|
|
1782
1783
|
headers: {
|
|
1783
1784
|
"Content-Type": "application/json",
|
|
1784
1785
|
...headers
|
package/dist/bin/gemi
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAkFf,eAAO,MAAM,YAAY,UAAW;IAClC,aAAa,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,UAAU,EAAE,cAAc,GAAG,CAAC,CAAC;CAChC,4CA2BA,CAAC"}
|
|
@@ -22,6 +22,7 @@ interface ClientRouterProviderProps {
|
|
|
22
22
|
export declare const ClientRouterProvider: (props: PropsWithChildren<ClientRouterProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
|
23
23
|
export declare function useLocation(): Location;
|
|
24
24
|
export declare function useParams(): Record<string, string>;
|
|
25
|
+
export declare function useViewData(): void;
|
|
25
26
|
export declare function useRouter(): {
|
|
26
27
|
push: (to: To, state?: any) => Promise<void>;
|
|
27
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRouterContext.d.ts","sourceRoot":"","sources":["../../client/ClientRouterContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAOL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,UAAU,wBAAwB;IAChC,kBAAkB,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACxD,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAClC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,mBAAmB,mDAE/B,CAAC;AAEF,UAAU,yBAAyB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,M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,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,oBAAoB,UACxB,kBAAkB,yBAAyB,CAAC,4CA2GpD,CAAC;AAUF,wBAAgB,WAAW,aAU1B;AAED,wBAAgB,SAAS,2BAGxB;AAED,wBAAgB,WAAW,SAAK;AAEhC,wBAAgB,SAAS;eAGJ,EAAE,UAAU,GAAG;EAsBnC;AAED,eAAO,MAAM,IAAI,UACR,KAAK,eAAe,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,EAAE,CAAA;CAAE,4CA0BxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.d.ts","sourceRoot":"","sources":["../../client/createRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAK3C,wBAAgB,UAAU,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,WACxC,GAAG,
|
|
1
|
+
{"version":3,"file":"createRoot.d.ts","sourceRoot":"","sources":["../../client/createRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAK3C,wBAAgB,UAAU,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,WACxC,GAAG,6CAQnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenComponentTree.d.ts","sourceRoot":"","sources":["../../../client/helpers/flattenComponentTree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"flattenComponentTree.d.ts","sourceRoot":"","sources":["../../../client/helpers/flattenComponentTree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,EAAE,CAM3E"}
|
package/dist/client/index.js
CHANGED
|
@@ -573,7 +573,7 @@ const ClientRouterProvider = (props) => {
|
|
|
573
573
|
params
|
|
574
574
|
} = props;
|
|
575
575
|
const [parameters, setParameters] = useState(params);
|
|
576
|
-
const pageDataRef = useRef(pageData);
|
|
576
|
+
const pageDataRef = useRef(structuredClone(pageData));
|
|
577
577
|
const scrollHistoryRef = useRef(/* @__PURE__ */ new Map());
|
|
578
578
|
const initalViewEntries = is404 ? ["404"] : routeManifest[pathname] ?? ["404"];
|
|
579
579
|
const viewEntriesSubject = useRef(new Subject(initalViewEntries));
|
|
@@ -29364,18 +29364,11 @@ if (process.env.NODE_ENV === "production") {
|
|
|
29364
29364
|
}
|
|
29365
29365
|
var clientExports = client.exports;
|
|
29366
29366
|
function flattenComponentTree(componentTree) {
|
|
29367
|
-
|
|
29368
|
-
for (const
|
|
29369
|
-
|
|
29370
|
-
out.push(section);
|
|
29371
|
-
} else {
|
|
29372
|
-
for (const [key, value] of Object.entries(section)) {
|
|
29373
|
-
out.push(key);
|
|
29374
|
-
out.push(...flattenComponentTree(value));
|
|
29375
|
-
}
|
|
29376
|
-
}
|
|
29367
|
+
let out = [];
|
|
29368
|
+
for (const [root, branches] of componentTree) {
|
|
29369
|
+
out.push(root, ...flattenComponentTree(branches).flat());
|
|
29377
29370
|
}
|
|
29378
|
-
return out;
|
|
29371
|
+
return Array.from(new Set(out));
|
|
29379
29372
|
}
|
|
29380
29373
|
let viewImportMap = null;
|
|
29381
29374
|
if (typeof window !== "undefined") {
|
|
@@ -29405,37 +29398,24 @@ const Route = (props) => {
|
|
|
29405
29398
|
});
|
|
29406
29399
|
}, []);
|
|
29407
29400
|
if (!render) return null;
|
|
29408
|
-
|
|
29409
|
-
|
|
29401
|
+
const Component = viewImportMap2[componentPath];
|
|
29402
|
+
if (Component) {
|
|
29410
29403
|
return /* @__PURE__ */ jsx(Component, { ...data, children: props.children });
|
|
29411
29404
|
}
|
|
29412
29405
|
return /* @__PURE__ */ jsx("div", { children: "Not found" });
|
|
29413
29406
|
};
|
|
29414
29407
|
const Routes = (props) => {
|
|
29415
29408
|
const { componentTree } = props;
|
|
29416
|
-
return /* @__PURE__ */ jsx(Suspense, { children: componentTree.map((node
|
|
29417
|
-
|
|
29418
|
-
|
|
29419
|
-
|
|
29420
|
-
if (typeof node === "string") {
|
|
29421
|
-
return /* @__PURE__ */ jsx(Route, { componentPath: node }, node);
|
|
29409
|
+
return /* @__PURE__ */ jsx(Suspense, { children: componentTree.map((node) => {
|
|
29410
|
+
const [path, subtree] = node;
|
|
29411
|
+
if (subtree.length > 0) {
|
|
29412
|
+
return /* @__PURE__ */ jsx(Route, { componentPath: path, children: /* @__PURE__ */ jsx(Routes, { componentTree: subtree }) }, path);
|
|
29422
29413
|
}
|
|
29423
|
-
|
|
29424
|
-
const [path, subtree2] = node;
|
|
29425
|
-
if (subtree2) {
|
|
29426
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Route, { componentPath: path, children: /* @__PURE__ */ jsx(Routes, { componentTree: subtree2 }) }, i) }, path);
|
|
29427
|
-
} else {
|
|
29428
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Route, { componentPath: path }, i) }, path);
|
|
29429
|
-
}
|
|
29430
|
-
}
|
|
29431
|
-
const [[first, subtree]] = Object.entries(node);
|
|
29432
|
-
if (subtree) {
|
|
29433
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Route, { componentPath: String(first), children: /* @__PURE__ */ jsx(Routes, { componentTree: subtree }) }, i) }, first);
|
|
29434
|
-
}
|
|
29435
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Route, { componentPath: String(first) }, i) }, first);
|
|
29414
|
+
return /* @__PURE__ */ jsx(Route, { componentPath: path }, path);
|
|
29436
29415
|
}) });
|
|
29437
29416
|
};
|
|
29438
29417
|
const ClientRouter = (props) => {
|
|
29418
|
+
const { RootLayout } = props;
|
|
29439
29419
|
const { routeManifest, router, componentTree, pageData, auth } = useContext(ServerDataContext);
|
|
29440
29420
|
return /* @__PURE__ */ jsx(
|
|
29441
29421
|
ClientRouterProvider,
|
|
@@ -29452,7 +29432,7 @@ const ClientRouter = (props) => {
|
|
|
29452
29432
|
value: {
|
|
29453
29433
|
viewImportMap: props.viewImportMap ?? viewImportMap
|
|
29454
29434
|
},
|
|
29455
|
-
children: /* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(Routes, { componentTree }) })
|
|
29435
|
+
children: /* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(RootLayout, { children: /* @__PURE__ */ jsx(Routes, { componentTree }) }) })
|
|
29456
29436
|
}
|
|
29457
29437
|
)
|
|
29458
29438
|
}
|
|
@@ -29460,12 +29440,18 @@ const ClientRouter = (props) => {
|
|
|
29460
29440
|
};
|
|
29461
29441
|
function init(RootLayout) {
|
|
29462
29442
|
clientExports.hydrateRoot(
|
|
29463
|
-
document,
|
|
29464
|
-
/* @__PURE__ */ jsx(
|
|
29443
|
+
document.body,
|
|
29444
|
+
/* @__PURE__ */ jsx(ServerDataProvider, { children: /* @__PURE__ */ jsx(ClientRouter, { RootLayout }) })
|
|
29465
29445
|
);
|
|
29466
29446
|
}
|
|
29467
29447
|
function createRoot(RootLayout) {
|
|
29468
|
-
return (props) => /* @__PURE__ */ jsx(
|
|
29448
|
+
return (props) => /* @__PURE__ */ jsx(ServerDataProvider, { value: props.data, children: /* @__PURE__ */ jsx(
|
|
29449
|
+
ClientRouter,
|
|
29450
|
+
{
|
|
29451
|
+
RootLayout,
|
|
29452
|
+
viewImportMap: props.viewImportMap
|
|
29453
|
+
}
|
|
29454
|
+
) });
|
|
29469
29455
|
}
|
|
29470
29456
|
export {
|
|
29471
29457
|
Form,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../client/init.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAK3C,wBAAgB,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../client/init.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAK3C,wBAAgB,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,QAOlD"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
2
|
-
export type ComponentTree =
|
|
1
|
+
type ComponentBranch = [string, ComponentBranch[]];
|
|
2
|
+
export type ComponentTree = ComponentBranch[];
|
|
3
3
|
export {};
|
|
4
4
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../client/types.ts"],"names":[],"mappings":"AAAA,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../client/types.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;AACnD,MAAM,MAAM,aAAa,GAAG,eAAe,EAAE,CAAC"}
|
package/dist/http/ApiRouter.d.ts
CHANGED
|
@@ -1,53 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Controller } from "./Controller";
|
|
2
2
|
import { type MiddlewareReturnType } from "./Router";
|
|
3
3
|
import type { App } from "../app/App";
|
|
4
|
+
import { HttpRequest } from "./HttpRequest";
|
|
4
5
|
type ControllerMethods<T extends new (app: App) => Controller> = {
|
|
5
6
|
[K in keyof InstanceType<T>]: InstanceType<T>[K] extends Function ? K : never;
|
|
6
7
|
}[keyof InstanceType<T>];
|
|
7
|
-
type DataResponse =
|
|
8
|
-
data: any;
|
|
9
|
-
status: number;
|
|
10
|
-
headers: Record<string, string>;
|
|
11
|
-
cookies: Record<string, string>;
|
|
12
|
-
};
|
|
8
|
+
type DataResponse = any;
|
|
13
9
|
type ErrorResponse = {
|
|
14
10
|
error: any;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
};
|
|
12
|
+
type ApiHandler<T extends new (app: App) => Controller, U = {}> = {
|
|
13
|
+
method: string;
|
|
14
|
+
exec: (req: Request, params: Record<string, any>, app: App) => Promise<Partial<DataResponse> | ErrorResponse>;
|
|
18
15
|
};
|
|
19
16
|
export type ApiRouteExec = (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
|
|
20
17
|
type ApiRouteConfig = {
|
|
21
18
|
method: string;
|
|
22
19
|
exec: ApiRouteExec;
|
|
23
20
|
};
|
|
21
|
+
type CallbackHandler<T> = (req: HttpRequest) => Promise<T> | T;
|
|
24
22
|
export type ApiRouteChildren = Record<string, ApiRouteConfig | ApiRouteConfig[] | (new (app: App) => ApiRouter)>;
|
|
25
23
|
export declare class ApiRouter {
|
|
26
24
|
routes: Record<string, any>;
|
|
27
25
|
middlewares: string[];
|
|
28
26
|
constructor();
|
|
29
|
-
middleware(
|
|
27
|
+
middleware(_req: Request): MiddlewareReturnType;
|
|
30
28
|
private handleRequest;
|
|
31
|
-
protected get<T
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
protected
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
protected patch<T
|
|
40
|
-
|
|
41
|
-
exec: (req: Request, params: Record<string, string>, app: App) => Promise<DataResponse | ErrorResponse>;
|
|
42
|
-
};
|
|
43
|
-
protected put<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): {
|
|
44
|
-
method: string;
|
|
45
|
-
exec: (req: Request, params: Record<string, string>, app: App) => Promise<DataResponse | ErrorResponse>;
|
|
46
|
-
};
|
|
47
|
-
protected delete<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): {
|
|
48
|
-
method: string;
|
|
49
|
-
exec: (req: Request, params: Record<string, string>, app: App) => Promise<DataResponse | ErrorResponse>;
|
|
50
|
-
};
|
|
29
|
+
protected get<T>(controller: CallbackHandler<T>): ApiHandler<any>;
|
|
30
|
+
protected get<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): ApiHandler<T>;
|
|
31
|
+
protected post<T>(controller: CallbackHandler<T>): ApiHandler<any>;
|
|
32
|
+
protected post<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): ApiHandler<T>;
|
|
33
|
+
protected put<T>(controller: CallbackHandler<T>): ApiHandler<any>;
|
|
34
|
+
protected put<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): ApiHandler<T>;
|
|
35
|
+
protected delete<T>(controller: CallbackHandler<T>): ApiHandler<any>;
|
|
36
|
+
protected delete<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): ApiHandler<T>;
|
|
37
|
+
protected patch<T>(controller: CallbackHandler<T>): ApiHandler<any>;
|
|
38
|
+
protected patch<T extends new (app: App) => Controller>(controller: T, methodName: ControllerMethods<T>): ApiHandler<T>;
|
|
51
39
|
}
|
|
52
40
|
export {};
|
|
53
41
|
//# sourceMappingURL=ApiRouter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiRouter.d.ts","sourceRoot":"","sources":["../../http/ApiRouter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ApiRouter.d.ts","sourceRoot":"","sources":["../../http/ApiRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU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AC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC;IACpE,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACrD,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC/B,UAAU,CAAC,CAAC,CAAC;IAShB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC;IACnE,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACpD,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC/B,UAAU,CAAC,CAAC,CAAC;CAQjB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { App } from "../app/App";
|
|
2
2
|
import type { HttpRequest } from "./HttpRequest";
|
|
3
3
|
export declare class Controller {
|
|
4
|
-
app
|
|
4
|
+
private app;
|
|
5
5
|
requests: Record<string, typeof HttpRequest<any>>;
|
|
6
|
+
static kind: "controller";
|
|
6
7
|
constructor(app: App);
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=Controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../http/Controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../http/Controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,UAAU;IAKT,OAAO,CAAC,GAAG;IAJvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAM;IAEvD,MAAM,CAAC,IAAI,eAAyB;gBAEhB,GAAG,EAAE,GAAG;CAC7B"}
|
|
@@ -4,30 +4,30 @@ import type { App } from "../app/App";
|
|
|
4
4
|
type ControllerMethods<T extends new () => Controller> = {
|
|
5
5
|
[K in keyof InstanceType<T>]: InstanceType<T>[K] extends Function ? K : never;
|
|
6
6
|
}[keyof InstanceType<T>];
|
|
7
|
-
type ViewHandler<T extends new () => Controller> = [
|
|
8
|
-
controller: T,
|
|
9
|
-
method: ControllerMethods<T>
|
|
10
|
-
];
|
|
7
|
+
type ViewHandler<T extends new () => Controller> = [controller: T, method: ControllerMethods<T>] | ((req: Request) => Promise<any> | any);
|
|
11
8
|
type ViewPrepare = {
|
|
12
9
|
exec: (req: Request, params: Record<string, string>) => any;
|
|
13
10
|
viewPath: string;
|
|
14
11
|
children: ViewChildren;
|
|
15
12
|
middlewares: any[];
|
|
13
|
+
kind: "view" | "layout";
|
|
16
14
|
};
|
|
17
15
|
type ViewConfig = {
|
|
18
16
|
prepare: (_middlewares?: any[]) => ViewPrepare;
|
|
19
|
-
|
|
20
|
-
prepare: () => ViewPrepare;
|
|
21
|
-
};
|
|
17
|
+
middleware: (middlewares: any[]) => ViewConfig;
|
|
22
18
|
};
|
|
23
|
-
export type ViewChildren = Record<string, ViewConfig | (new (
|
|
19
|
+
export type ViewChildren = Record<string, ViewConfig | (new () => ViewRouter)>;
|
|
24
20
|
export type ViewRouteExec = (req: Request, params: Record<string, string>, app: App) => any;
|
|
25
21
|
export declare class ViewRouter {
|
|
26
22
|
routes: ViewChildren;
|
|
27
23
|
middlewares: string[];
|
|
28
|
-
constructor();
|
|
29
24
|
middleware(req: Request): MiddlewareReturnType;
|
|
30
|
-
protected
|
|
25
|
+
protected layout<T extends new (app: App) => Controller>(viewPath: string): ViewConfig;
|
|
26
|
+
protected layout<T extends new (app: App) => Controller>(viewPath: string, children?: ViewChildren): ViewConfig;
|
|
27
|
+
protected layout<T extends new (app: App) => Controller>(viewPath: string, handler: ViewHandler<T>): ViewConfig;
|
|
28
|
+
protected view<T extends new (app: App) => Controller>(viewPath: string): ViewConfig;
|
|
29
|
+
protected view<T extends new (app: App) => Controller>(viewPath: string, children?: ViewChildren): ViewConfig;
|
|
30
|
+
protected view<T extends new (app: App) => Controller>(viewPath: string, handler: ViewHandler<T>): ViewConfig;
|
|
31
31
|
}
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=ViewRouter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewRouter.d.ts","sourceRoot":"","sources":["../../http/ViewRouter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,KAAK,iBAAiB,CAAC,CAAC,SAAS,UAAU,UAAU,IAAI;KACtD,CAAC,IAAI,MAAM,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK;CAC9E,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzB,KAAK,WAAW,CAAC,CAAC,SAAS,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"ViewRouter.d.ts","sourceRoot":"","sources":["../../http/ViewRouter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,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AM,EAAE,YAAY,CAAM;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAM;IAE3B,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,oBAAoB;IAErD,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACrD,QAAQ,EAAE,MAAM,GACf,UAAU;IACb,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACrD,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,YAAiB,GAC1B,UAAU;IACb,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACrD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,UAAU;IAmDb,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACnD,QAAQ,EAAE,MAAM,GACf,UAAU;IACb,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACnD,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,YAAiB,GAC1B,UAAU;IACb,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,KAAK,UAAU,EACnD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,UAAU;CAkDd"}
|
package/dist/http/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var __require = createRequire(import.meta.url);
|
|
|
22
22
|
class Controller {
|
|
23
23
|
app;
|
|
24
24
|
requests = {};
|
|
25
|
+
static kind = "controller";
|
|
25
26
|
constructor(app) {
|
|
26
27
|
this.app = app;
|
|
27
28
|
}
|
|
@@ -225,34 +226,33 @@ class HttpRequest {
|
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
// http/ApiRouter.ts
|
|
229
|
+
var isController = function(controller) {
|
|
230
|
+
return "kind" in controller && controller.kind === "controller";
|
|
231
|
+
};
|
|
232
|
+
|
|
228
233
|
class ApiRouter {
|
|
229
234
|
routes = {};
|
|
230
235
|
middlewares = [];
|
|
231
236
|
constructor() {
|
|
232
237
|
}
|
|
233
|
-
middleware(
|
|
238
|
+
middleware(_req) {
|
|
234
239
|
}
|
|
235
240
|
handleRequest(controller, methodName) {
|
|
236
241
|
return (method) => {
|
|
237
242
|
return {
|
|
238
243
|
method,
|
|
239
244
|
exec: async (req, params, app) => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
return
|
|
251
|
-
data,
|
|
252
|
-
status,
|
|
253
|
-
headers,
|
|
254
|
-
cookies
|
|
255
|
-
};
|
|
245
|
+
let handler = (_req, params2) => Promise.resolve({});
|
|
246
|
+
let httpRequest = new HttpRequest(req);
|
|
247
|
+
if (isController(controller)) {
|
|
248
|
+
const controllerInstance = new controller(app);
|
|
249
|
+
const Req = controllerInstance.requests[methodName] ?? HttpRequest;
|
|
250
|
+
httpRequest = new Req(req);
|
|
251
|
+
handler = controllerInstance[methodName].bind(controllerInstance);
|
|
252
|
+
} else if (typeof controller === "function") {
|
|
253
|
+
handler = (req2) => controller(new HttpRequest(req2));
|
|
254
|
+
}
|
|
255
|
+
return await handler(httpRequest, params);
|
|
256
256
|
}
|
|
257
257
|
};
|
|
258
258
|
};
|
|
@@ -265,10 +265,6 @@ class ApiRouter {
|
|
|
265
265
|
const handler = this.handleRequest(controller, methodName);
|
|
266
266
|
return handler("post");
|
|
267
267
|
}
|
|
268
|
-
patch(controller, methodName) {
|
|
269
|
-
const handler = this.handleRequest(controller, methodName);
|
|
270
|
-
return handler("patch");
|
|
271
|
-
}
|
|
272
268
|
put(controller, methodName) {
|
|
273
269
|
const handler = this.handleRequest(controller, methodName);
|
|
274
270
|
return handler("put");
|
|
@@ -277,39 +273,89 @@ class ApiRouter {
|
|
|
277
273
|
const handler = this.handleRequest(controller, methodName);
|
|
278
274
|
return handler("delete");
|
|
279
275
|
}
|
|
276
|
+
patch(controller, methodName) {
|
|
277
|
+
const handler = this.handleRequest(controller, methodName);
|
|
278
|
+
return handler("patch");
|
|
279
|
+
}
|
|
280
280
|
}
|
|
281
281
|
// http/ViewRouter.ts
|
|
282
282
|
class ViewRouter {
|
|
283
283
|
routes = {};
|
|
284
284
|
middlewares = [];
|
|
285
|
-
constructor() {
|
|
286
|
-
}
|
|
287
285
|
middleware(req) {
|
|
288
286
|
}
|
|
289
|
-
|
|
287
|
+
layout(viewPath, handler, children = {}) {
|
|
290
288
|
function prepare(middlewares = []) {
|
|
289
|
+
let _children = children;
|
|
290
|
+
if (handler && handler.constructor === Object) {
|
|
291
|
+
_children = handler;
|
|
292
|
+
}
|
|
291
293
|
return {
|
|
292
294
|
exec: async (req, params, app) => {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
let _handler = () => Promise.resolve({
|
|
296
|
+
data: { [viewPath]: {} },
|
|
297
|
+
headers: {},
|
|
298
|
+
head: {}
|
|
299
|
+
});
|
|
300
|
+
if (typeof handler === "function") {
|
|
301
|
+
_handler = handler;
|
|
295
302
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
303
|
+
if (Array.isArray(handler)) {
|
|
304
|
+
const [controller, methodName] = handler;
|
|
305
|
+
const instance = new controller(app);
|
|
306
|
+
_handler = instance[methodName].bind(instance);
|
|
307
|
+
}
|
|
308
|
+
const data = await _handler(req, params);
|
|
309
|
+
return { [viewPath]: data };
|
|
301
310
|
},
|
|
302
|
-
children,
|
|
311
|
+
children: _children,
|
|
303
312
|
viewPath,
|
|
304
|
-
middlewares
|
|
313
|
+
middlewares,
|
|
314
|
+
kind: "layout"
|
|
305
315
|
};
|
|
306
316
|
}
|
|
307
317
|
return {
|
|
308
318
|
prepare,
|
|
309
|
-
|
|
310
|
-
prepare:
|
|
311
|
-
|
|
319
|
+
middleware: (middlewares) => ({
|
|
320
|
+
prepare: () => prepare(middlewares)
|
|
321
|
+
})
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
view(viewPath, handler, children = {}) {
|
|
325
|
+
function prepare(middlewares = []) {
|
|
326
|
+
let _children = children;
|
|
327
|
+
if (handler && handler.constructor === Object) {
|
|
328
|
+
_children = handler;
|
|
312
329
|
}
|
|
330
|
+
return {
|
|
331
|
+
exec: async (req, params, app) => {
|
|
332
|
+
let _handler = () => Promise.resolve({
|
|
333
|
+
data: { [viewPath]: {} },
|
|
334
|
+
headers: {},
|
|
335
|
+
head: {}
|
|
336
|
+
});
|
|
337
|
+
if (typeof handler === "function") {
|
|
338
|
+
_handler = handler;
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(handler)) {
|
|
341
|
+
const [controller, methodName] = handler;
|
|
342
|
+
const instance = new controller(app);
|
|
343
|
+
_handler = instance[methodName].bind(instance);
|
|
344
|
+
}
|
|
345
|
+
const data = await _handler(req, params);
|
|
346
|
+
return { [viewPath]: data };
|
|
347
|
+
},
|
|
348
|
+
children: _children,
|
|
349
|
+
viewPath,
|
|
350
|
+
middlewares,
|
|
351
|
+
kind: "view"
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
prepare,
|
|
356
|
+
middleware: (middlewares) => ({
|
|
357
|
+
prepare: () => prepare(middlewares)
|
|
358
|
+
})
|
|
313
359
|
};
|
|
314
360
|
}
|
|
315
361
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gemi",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@repo/eslint-config": "*",
|
|
6
6
|
"@repo/typescript-config": "*",
|
|
7
|
+
"@types/bun": "^1.1.4",
|
|
7
8
|
"@types/eslint": "^8.56.5",
|
|
8
9
|
"@types/node": "^20.11.24",
|
|
9
10
|
"@types/react": "^18.2.61",
|
|
10
11
|
"@types/react-dom": "^18.2.19",
|
|
11
12
|
"eslint": "^8.57.0",
|
|
12
|
-
"typescript": "^5.3.3"
|
|
13
|
+
"typescript": "^5.3.3",
|
|
14
|
+
"vitest": "^1.6.0"
|
|
13
15
|
},
|
|
14
16
|
"bin": {
|
|
15
17
|
"gemi": "./dist/bin/gemi"
|
|
@@ -35,7 +37,8 @@
|
|
|
35
37
|
"build:bin": "bun build --compile ./bin/gemi.ts --external vite --external react-dom --external react/jsx-runtime --outfile ./dist/bin/gemi",
|
|
36
38
|
"build:client": "vite build",
|
|
37
39
|
"build:types": "tsc",
|
|
38
|
-
"build:client-types": "tsc -p tsconfig.browser.json"
|
|
40
|
+
"build:client-types": "tsc -p tsconfig.browser.json",
|
|
41
|
+
"test": "vitest"
|
|
39
42
|
},
|
|
40
43
|
"dependencies": {
|
|
41
44
|
"@react-email/components": "^0.0.19",
|