@boon4681/giri 0.0.3-alpha-3 → 0.0.3-alpha-5
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 +41 -1
- package/dist/adapters/hono.d.ts +1 -1
- package/dist/cli.js +37 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -63
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +49 -0
- package/dist/runtime.js +464 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +424 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/{types-BvRph0mx.d.ts → types-DZ-14IP6.d.ts} +2 -1
- package/dist/validation-Cma_ytxd.d.ts +63 -0
- package/dist/validators/valibot.d.ts +1 -1
- package/dist/validators/zod.d.ts +1 -1
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -228,6 +228,46 @@ yarn sync
|
|
|
228
228
|
yarn dev
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
+
## Portable runtime
|
|
232
|
+
|
|
233
|
+
`@boon4681/giri/runtime` is the portable composition layer for generated integrations. It does
|
|
234
|
+
not implement routing itself: it accepts a complete `GiriAdapter`, creates that adapter's app, and
|
|
235
|
+
registers statically imported route modules. Hono is the supported adapter today:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { createApp } from "@boon4681/giri/runtime";
|
|
239
|
+
import { hono } from "@boon4681/giri/adapters/hono";
|
|
240
|
+
import * as rootShared from "./src/routes/+shared";
|
|
241
|
+
import * as usersGet from "./src/routes/users/+get";
|
|
242
|
+
|
|
243
|
+
export const app = createApp({
|
|
244
|
+
adapter: hono(),
|
|
245
|
+
services: { source: "playground" },
|
|
246
|
+
routes: [
|
|
247
|
+
{
|
|
248
|
+
method: "GET",
|
|
249
|
+
path: "/api/users",
|
|
250
|
+
module: usersGet,
|
|
251
|
+
shared: [rootShared],
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The result is a normal Fetch application:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
const response = await app.fetch(new Request("https://example.test/api/users"));
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`app` is the native Hono application, so SvelteKit or Next.js can forward a framework request
|
|
264
|
+
directly to `app.fetch(request)`. This is the low-level target for virtual modules such as
|
|
265
|
+
`@giri/project-1`; the Vite integration should generate the route descriptor array.
|
|
266
|
+
|
|
267
|
+
The shipped Hono adapter also owns its Node server binding. A browser playground should provide a
|
|
268
|
+
different `GiriAdapter` implementation whose `createApp`, `register`, `fetch`, and `serve` methods
|
|
269
|
+
bind to the desired browser runtime; `createApp` itself does not special-case that environment.
|
|
270
|
+
|
|
231
271
|
## License
|
|
232
272
|
|
|
233
|
-
MIT
|
|
273
|
+
MIT
|
package/dist/adapters/hono.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContextVariableMap, Hono, MiddlewareHandler } from 'hono';
|
|
2
|
-
import { M as Middleware, V as ValidatedInput, G as GiriAdapter } from '../types-
|
|
2
|
+
import { M as Middleware, V as ValidatedInput, G as GiriAdapter } from '../types-DZ-14IP6.js';
|
|
3
3
|
|
|
4
4
|
type HonoGiriApp = Hono;
|
|
5
5
|
type HonoContextVars = {
|
package/dist/cli.js
CHANGED
|
@@ -688,6 +688,42 @@ function urlSegment(segment) {
|
|
|
688
688
|
}
|
|
689
689
|
return { value: segment };
|
|
690
690
|
}
|
|
691
|
+
function segmentRanks(segments) {
|
|
692
|
+
const ranks = [];
|
|
693
|
+
for (const segment of segments) {
|
|
694
|
+
const converted = urlSegment(segment);
|
|
695
|
+
if (!converted.value) {
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (converted.param?.catchAll) {
|
|
699
|
+
ranks.push({ rank: 2, text: converted.param.name });
|
|
700
|
+
} else if (converted.param) {
|
|
701
|
+
ranks.push({ rank: 1, text: converted.param.name });
|
|
702
|
+
} else {
|
|
703
|
+
ranks.push({ rank: 0, text: converted.value });
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return ranks;
|
|
707
|
+
}
|
|
708
|
+
function compareRoutes(left, right) {
|
|
709
|
+
const leftRanks = segmentRanks(left.routeSegments);
|
|
710
|
+
const rightRanks = segmentRanks(right.routeSegments);
|
|
711
|
+
const shared = Math.min(leftRanks.length, rightRanks.length);
|
|
712
|
+
for (let i = 0; i < shared; i++) {
|
|
713
|
+
const a = leftRanks[i];
|
|
714
|
+
const b = rightRanks[i];
|
|
715
|
+
if (a.rank !== b.rank) {
|
|
716
|
+
return a.rank - b.rank;
|
|
717
|
+
}
|
|
718
|
+
if (a.rank === 0 && a.text !== b.text) {
|
|
719
|
+
return a.text.localeCompare(b.text);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (leftRanks.length !== rightRanks.length) {
|
|
723
|
+
return leftRanks.length - rightRanks.length;
|
|
724
|
+
}
|
|
725
|
+
return METHOD_ORDER.indexOf(left.method) - METHOD_ORDER.indexOf(right.method);
|
|
726
|
+
}
|
|
691
727
|
function pathFromSegments(segments) {
|
|
692
728
|
const pathSegments = [];
|
|
693
729
|
const params = [];
|
|
@@ -764,13 +800,7 @@ async function scanRoutes(routesDir) {
|
|
|
764
800
|
sharedFiles: sharedFilesForDir(routesDir, routeDir, sharedCache)
|
|
765
801
|
});
|
|
766
802
|
}
|
|
767
|
-
return routes.sort(
|
|
768
|
-
const pathOrder = left.path.localeCompare(right.path);
|
|
769
|
-
if (pathOrder !== 0) {
|
|
770
|
-
return pathOrder;
|
|
771
|
-
}
|
|
772
|
-
return METHOD_ORDER.indexOf(left.method) - METHOD_ORDER.indexOf(right.method);
|
|
773
|
-
});
|
|
803
|
+
return routes.sort(compareRoutes);
|
|
774
804
|
}
|
|
775
805
|
|
|
776
806
|
// src/types.ts
|