@boon4681/giri 0.0.3-alpha-2 → 0.0.3-alpha-4
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 +60 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -63
- package/dist/index.js +60 -15
- 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/dist/validators/zod.js +1 -1
- package/dist/validators/zod.js.map +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
|
@@ -1421,7 +1421,12 @@ function inputToJsonSchema(schema) {
|
|
|
1421
1421
|
if (!isGiriInputSchema(schema)) {
|
|
1422
1422
|
return void 0;
|
|
1423
1423
|
}
|
|
1424
|
-
|
|
1424
|
+
try {
|
|
1425
|
+
return sanitize(schema.toJsonSchema());
|
|
1426
|
+
} catch (error) {
|
|
1427
|
+
console.warn(`giri: skipped a request schema that can't be represented as JSON Schema (${error.message}).`);
|
|
1428
|
+
return void 0;
|
|
1429
|
+
}
|
|
1425
1430
|
}
|
|
1426
1431
|
function bodyToJsonSchemas(value) {
|
|
1427
1432
|
if (!isGiriBodySchema(value)) {
|
|
@@ -1437,6 +1442,46 @@ function bodyToJsonSchemas(value) {
|
|
|
1437
1442
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
1438
1443
|
}
|
|
1439
1444
|
|
|
1445
|
+
// src/generator/schema/route-openapi.ts
|
|
1446
|
+
var import_typebox2 = require("@sinclair/typebox");
|
|
1447
|
+
var import_value2 = require("@sinclair/typebox/value");
|
|
1448
|
+
var StringSchema = import_typebox2.Type.String();
|
|
1449
|
+
var BooleanSchema = import_typebox2.Type.Boolean();
|
|
1450
|
+
var StringArraySchema = import_typebox2.Type.Array(StringSchema);
|
|
1451
|
+
var routeOpenApiSchema = import_typebox2.Type.Object(
|
|
1452
|
+
{
|
|
1453
|
+
hidden: import_typebox2.Type.Optional(BooleanSchema),
|
|
1454
|
+
tags: import_typebox2.Type.Optional(StringArraySchema),
|
|
1455
|
+
summary: import_typebox2.Type.Optional(StringSchema),
|
|
1456
|
+
description: import_typebox2.Type.Optional(StringSchema),
|
|
1457
|
+
deprecated: import_typebox2.Type.Optional(BooleanSchema),
|
|
1458
|
+
operationId: import_typebox2.Type.Optional(StringSchema)
|
|
1459
|
+
},
|
|
1460
|
+
{ additionalProperties: true }
|
|
1461
|
+
);
|
|
1462
|
+
function pick(schema, value) {
|
|
1463
|
+
return import_value2.Value.Check(schema, value) ? value : void 0;
|
|
1464
|
+
}
|
|
1465
|
+
function parseRouteOpenApi(value) {
|
|
1466
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1467
|
+
return void 0;
|
|
1468
|
+
}
|
|
1469
|
+
const o = value;
|
|
1470
|
+
const parsed = {};
|
|
1471
|
+
if ("hidden" in o) {
|
|
1472
|
+
parsed.hidden = Boolean(o.hidden);
|
|
1473
|
+
}
|
|
1474
|
+
const tags = pick(StringArraySchema, o.tags);
|
|
1475
|
+
if (tags) {
|
|
1476
|
+
parsed.tags = tags;
|
|
1477
|
+
}
|
|
1478
|
+
parsed.summary = pick(StringSchema, o.summary);
|
|
1479
|
+
parsed.description = pick(StringSchema, o.description);
|
|
1480
|
+
parsed.operationId = pick(StringSchema, o.operationId);
|
|
1481
|
+
parsed.deprecated = pick(BooleanSchema, o.deprecated);
|
|
1482
|
+
return parsed;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1440
1485
|
// src/generator/route-meta.ts
|
|
1441
1486
|
function loadModule2(file) {
|
|
1442
1487
|
const resolved = require.resolve(file);
|
|
@@ -1749,27 +1794,27 @@ function resolveOpenApi(route, routeModule, loadShared) {
|
|
|
1749
1794
|
hidden = false;
|
|
1750
1795
|
return;
|
|
1751
1796
|
}
|
|
1752
|
-
|
|
1797
|
+
const parsed = parseRouteOpenApi(value);
|
|
1798
|
+
if (!parsed) {
|
|
1753
1799
|
return;
|
|
1754
1800
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
hidden = Boolean(o.hidden);
|
|
1801
|
+
if (parsed.hidden !== void 0) {
|
|
1802
|
+
hidden = parsed.hidden;
|
|
1758
1803
|
}
|
|
1759
|
-
if (
|
|
1760
|
-
tags.push(...
|
|
1804
|
+
if (parsed.tags) {
|
|
1805
|
+
tags.push(...parsed.tags);
|
|
1761
1806
|
}
|
|
1762
|
-
if (
|
|
1763
|
-
meta.summary =
|
|
1807
|
+
if (parsed.summary !== void 0) {
|
|
1808
|
+
meta.summary = parsed.summary;
|
|
1764
1809
|
}
|
|
1765
|
-
if (
|
|
1766
|
-
meta.description =
|
|
1810
|
+
if (parsed.description !== void 0) {
|
|
1811
|
+
meta.description = parsed.description;
|
|
1767
1812
|
}
|
|
1768
|
-
if (
|
|
1769
|
-
meta.deprecated =
|
|
1813
|
+
if (parsed.deprecated !== void 0) {
|
|
1814
|
+
meta.deprecated = parsed.deprecated;
|
|
1770
1815
|
}
|
|
1771
|
-
if (isVerb &&
|
|
1772
|
-
meta.operationId =
|
|
1816
|
+
if (isVerb && parsed.operationId !== void 0) {
|
|
1817
|
+
meta.operationId = parsed.operationId;
|
|
1773
1818
|
}
|
|
1774
1819
|
};
|
|
1775
1820
|
for (const file of route.sharedFiles) {
|