@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/dist/index.d.ts
CHANGED
|
@@ -1,65 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
interface CreateContextOptions<Params extends Record<string, string> = Record<string, string>, Input extends ValidatedInput = ValidatedInput> {
|
|
5
|
-
request: Request;
|
|
6
|
-
params?: Params;
|
|
7
|
-
validated?: Input;
|
|
8
|
-
app?: Services;
|
|
9
|
-
/** The adapter's native per-request context, stashed for backend-specific bridges. */
|
|
10
|
-
native?: unknown;
|
|
11
|
-
/** Secret for `c.signedCookie` / `c.req.signedCookie` (from `config.cookieSecret`). */
|
|
12
|
-
cookieSecret?: string;
|
|
13
|
-
/** The adapter's cookie jar, built from its runtime's native helpers. */
|
|
14
|
-
cookies?: CookieJarFactory;
|
|
15
|
-
}
|
|
16
|
-
declare function createTypedResponse<T, S extends StatusCode, F extends ResponseFormat>(data: T, status: S, format: F, headers?: HeadersInit): TypedResponse<T, S, F>;
|
|
17
|
-
declare function isTypedResponse(value: unknown): value is TypedResponse<unknown>;
|
|
18
|
-
declare function createContext<Params extends Record<string, string> = Record<string, string>, Input extends ValidatedInput = ValidatedInput>(options: CreateContextOptions<Params, Input>): Context<Params, Input>;
|
|
19
|
-
declare function typedResponseToResponse(response: TypedResponse<unknown>): Response;
|
|
20
|
-
/**
|
|
21
|
-
* Convert a handler's return value to a real `Response`, then merge any headers set imperatively via
|
|
22
|
-
* `c.header()` (the response's own headers win; pending ones fill the gaps). Pass the `context` so
|
|
23
|
-
* those imperative headers are applied; without it the response is returned unchanged.
|
|
24
|
-
*/
|
|
25
|
-
declare function toResponse(response: HandlerResponse, context?: Context): Response;
|
|
26
|
-
declare function composeMiddleware(middleware: Middleware[], handle: (c: Context) => HandlerResponse | Promise<HandlerResponse>, context: Context): Promise<HandlerResponse>;
|
|
27
|
-
type AnyMiddleware<Vars extends Record<string, unknown>> = Middleware<Record<string, string>, ValidatedInput, Vars>;
|
|
28
|
-
declare function defineMiddleware<Vars extends Record<string, unknown> = {}>(middleware: AnyMiddleware<Vars>): AnyMiddleware<Vars>;
|
|
29
|
-
declare function defineMiddleware<Vars extends Record<string, unknown> = {}>(options: MiddlewareOptions, middleware: AnyMiddleware<Vars>): AnyMiddleware<Vars>;
|
|
30
|
-
/**
|
|
31
|
-
* Group middleware into an ordered stack, preserving each element's type as a tuple so
|
|
32
|
-
* the injected context vars (`defineMiddleware<Vars>` / `Middleware<…, Vars>`) propagate
|
|
33
|
-
* to downstream handlers. Use it for `+shared.ts` and verb `middleware` exports:
|
|
34
|
-
* `export const middleware = stack(auth, requireAdmin)`.
|
|
35
|
-
*/
|
|
36
|
-
declare function stack<T extends Middleware<Record<string, string>, ValidatedInput, any>[]>(...middleware: T): T;
|
|
37
|
-
|
|
38
|
-
interface PreparedInput {
|
|
39
|
-
ok: true;
|
|
40
|
-
validated: ValidatedInput;
|
|
41
|
-
}
|
|
42
|
-
interface FailedInput {
|
|
43
|
-
ok: false;
|
|
44
|
-
response: TypedResponse<{
|
|
45
|
-
message: string;
|
|
46
|
-
issues: unknown;
|
|
47
|
-
}, 400 | 415, 'json'>;
|
|
48
|
-
}
|
|
49
|
-
type PreparedRequestInput = PreparedInput | FailedInput;
|
|
50
|
-
/**
|
|
51
|
-
* Build a giri input schema from a `validate` + `toJsonSchema` pair. Vendor adapters use
|
|
52
|
-
* this; you can call it directly to make a custom validator. The brand is a global symbol,
|
|
53
|
-
* so a hand-rolled `{ [Symbol.for("giri.input-schema")]: true, validate, toJsonSchema }` works too.
|
|
54
|
-
*/
|
|
55
|
-
declare function defineInputSchema<Output>(schema: Omit<GiriInputSchema<Output>, typeof inputSchemaBrand>): GiriInputSchema<Output>;
|
|
56
|
-
declare function isGiriInputSchema(value: unknown): value is GiriInputSchema;
|
|
57
|
-
/**
|
|
58
|
-
* Build a giri body schema from per-content-type input schemas. Validator adapters use this `zod.body({ json, form })`
|
|
59
|
-
*/
|
|
60
|
-
declare function defineBodySchema<Outputs extends Partial<Record<BodyContentType, unknown>>>(contents: GiriBodySchema<Outputs>['contents']): GiriBodySchema<Outputs>;
|
|
61
|
-
declare function isGiriBodySchema(value: unknown): value is GiriBodySchema;
|
|
62
|
-
declare function prepareRequestInput(request: Request, input?: RouteInput): Promise<PreparedRequestInput>;
|
|
1
|
+
import { H as HttpMethod, h as GiriConfig, S as Services, j as GiriPaths, B as BodyContentType, A as SecurityRequirement } from './types-DZ-14IP6.js';
|
|
2
|
+
export { C as Context, d as CookieJar, e as CookieJarFactory, f as CookieOptions, g as CookieSink, G as GiriAdapter, b as GiriBodySchema, i as GiriFetchHandler, c as GiriInputSchema, k as GiriRequest, l as GiriRouteRegistration, m as GiriServeOptions, n as GiriServer, o as GiriServerInfo, a as Handle, p as HandlerResponse, I as Infer, q as InferStackVars, r as InputValidationResult, J as JsonSchema, s as MergeStack, M as Middleware, t as MiddlewareOpenApi, u as MiddlewareOptions, v as MiddlewareVarsOf, N as Next, w as RouteInput, x as RouteInputOf, y as RouteOpenApi, z as RouteOpenApiConfig, D as StatusCode, T as TypedResponse, E as ValidBody, F as ValidQuery, V as ValidatedInput, K as VarsOf } from './types-DZ-14IP6.js';
|
|
3
|
+
export { c as composeMiddleware, a as createContext, b as createTypedResponse, d as defineBodySchema, e as defineInputSchema, f as defineMiddleware, i as isGiriBodySchema, g as isGiriInputSchema, h as isTypedResponse, p as prepareRequestInput, s as stack, t as toResponse, j as typedResponseToResponse } from './validation-Cma_ytxd.js';
|
|
63
4
|
|
|
64
5
|
interface RouteParam {
|
|
65
6
|
name: string;
|
|
@@ -189,4 +130,4 @@ declare function runInit(lifecycle: GiriLifecycle): Promise<Services>;
|
|
|
189
130
|
|
|
190
131
|
declare function defineConfig<App>(config: GiriConfig<App>): GiriConfig<App>;
|
|
191
132
|
|
|
192
|
-
export { BodyContentType,
|
|
133
|
+
export { BodyContentType, GiriConfig, type GiriLifecycle, GiriPaths, HttpMethod, SecurityRequirement, Services, buildGiriApp, defineConfig, loadLifecycle, resolveGiriPaths, runInit, scanRoutes, syncProject };
|
package/dist/index.js
CHANGED
|
@@ -1697,7 +1697,12 @@ function inputToJsonSchema(schema) {
|
|
|
1697
1697
|
if (!isGiriInputSchema(schema)) {
|
|
1698
1698
|
return void 0;
|
|
1699
1699
|
}
|
|
1700
|
-
|
|
1700
|
+
try {
|
|
1701
|
+
return sanitize(schema.toJsonSchema());
|
|
1702
|
+
} catch (error) {
|
|
1703
|
+
console.warn(`giri: skipped a request schema that can't be represented as JSON Schema (${error.message}).`);
|
|
1704
|
+
return void 0;
|
|
1705
|
+
}
|
|
1701
1706
|
}
|
|
1702
1707
|
function bodyToJsonSchemas(value) {
|
|
1703
1708
|
if (!isGiriBodySchema(value)) {
|
|
@@ -1713,6 +1718,46 @@ function bodyToJsonSchemas(value) {
|
|
|
1713
1718
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
1714
1719
|
}
|
|
1715
1720
|
|
|
1721
|
+
// src/generator/schema/route-openapi.ts
|
|
1722
|
+
var import_typebox2 = require("@sinclair/typebox");
|
|
1723
|
+
var import_value2 = require("@sinclair/typebox/value");
|
|
1724
|
+
var StringSchema = import_typebox2.Type.String();
|
|
1725
|
+
var BooleanSchema = import_typebox2.Type.Boolean();
|
|
1726
|
+
var StringArraySchema = import_typebox2.Type.Array(StringSchema);
|
|
1727
|
+
var routeOpenApiSchema = import_typebox2.Type.Object(
|
|
1728
|
+
{
|
|
1729
|
+
hidden: import_typebox2.Type.Optional(BooleanSchema),
|
|
1730
|
+
tags: import_typebox2.Type.Optional(StringArraySchema),
|
|
1731
|
+
summary: import_typebox2.Type.Optional(StringSchema),
|
|
1732
|
+
description: import_typebox2.Type.Optional(StringSchema),
|
|
1733
|
+
deprecated: import_typebox2.Type.Optional(BooleanSchema),
|
|
1734
|
+
operationId: import_typebox2.Type.Optional(StringSchema)
|
|
1735
|
+
},
|
|
1736
|
+
{ additionalProperties: true }
|
|
1737
|
+
);
|
|
1738
|
+
function pick(schema, value) {
|
|
1739
|
+
return import_value2.Value.Check(schema, value) ? value : void 0;
|
|
1740
|
+
}
|
|
1741
|
+
function parseRouteOpenApi(value) {
|
|
1742
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1743
|
+
return void 0;
|
|
1744
|
+
}
|
|
1745
|
+
const o = value;
|
|
1746
|
+
const parsed = {};
|
|
1747
|
+
if ("hidden" in o) {
|
|
1748
|
+
parsed.hidden = Boolean(o.hidden);
|
|
1749
|
+
}
|
|
1750
|
+
const tags = pick(StringArraySchema, o.tags);
|
|
1751
|
+
if (tags) {
|
|
1752
|
+
parsed.tags = tags;
|
|
1753
|
+
}
|
|
1754
|
+
parsed.summary = pick(StringSchema, o.summary);
|
|
1755
|
+
parsed.description = pick(StringSchema, o.description);
|
|
1756
|
+
parsed.operationId = pick(StringSchema, o.operationId);
|
|
1757
|
+
parsed.deprecated = pick(BooleanSchema, o.deprecated);
|
|
1758
|
+
return parsed;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1716
1761
|
// src/generator/route-meta.ts
|
|
1717
1762
|
function loadModule2(file) {
|
|
1718
1763
|
const resolved = require.resolve(file);
|
|
@@ -2025,27 +2070,27 @@ function resolveOpenApi(route, routeModule, loadShared) {
|
|
|
2025
2070
|
hidden = false;
|
|
2026
2071
|
return;
|
|
2027
2072
|
}
|
|
2028
|
-
|
|
2073
|
+
const parsed = parseRouteOpenApi(value);
|
|
2074
|
+
if (!parsed) {
|
|
2029
2075
|
return;
|
|
2030
2076
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
hidden = Boolean(o.hidden);
|
|
2077
|
+
if (parsed.hidden !== void 0) {
|
|
2078
|
+
hidden = parsed.hidden;
|
|
2034
2079
|
}
|
|
2035
|
-
if (
|
|
2036
|
-
tags.push(...
|
|
2080
|
+
if (parsed.tags) {
|
|
2081
|
+
tags.push(...parsed.tags);
|
|
2037
2082
|
}
|
|
2038
|
-
if (
|
|
2039
|
-
meta.summary =
|
|
2083
|
+
if (parsed.summary !== void 0) {
|
|
2084
|
+
meta.summary = parsed.summary;
|
|
2040
2085
|
}
|
|
2041
|
-
if (
|
|
2042
|
-
meta.description =
|
|
2086
|
+
if (parsed.description !== void 0) {
|
|
2087
|
+
meta.description = parsed.description;
|
|
2043
2088
|
}
|
|
2044
|
-
if (
|
|
2045
|
-
meta.deprecated =
|
|
2089
|
+
if (parsed.deprecated !== void 0) {
|
|
2090
|
+
meta.deprecated = parsed.deprecated;
|
|
2046
2091
|
}
|
|
2047
|
-
if (isVerb &&
|
|
2048
|
-
meta.operationId =
|
|
2092
|
+
if (isVerb && parsed.operationId !== void 0) {
|
|
2093
|
+
meta.operationId = parsed.operationId;
|
|
2049
2094
|
}
|
|
2050
2095
|
};
|
|
2051
2096
|
for (const file of route.sharedFiles) {
|