@kozojs/core 0.3.11 → 0.3.12
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/lib/index.d.ts +48 -1
- package/lib/index.js +38 -12
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -301,10 +301,15 @@ declare class Kozo<TServices extends Services = Services> {
|
|
|
301
301
|
loadRoutes(routesDir?: string): Promise<this>;
|
|
302
302
|
generateClient(baseUrl?: string): string;
|
|
303
303
|
generateClient(options?: ClientGeneratorOptions): string;
|
|
304
|
+
get(path: string, handler: KozoHandler<{}, TServices>): this;
|
|
304
305
|
get<S extends RouteSchema>(path: string, schema: S, handler: KozoHandler<S, TServices>): this;
|
|
306
|
+
post(path: string, handler: KozoHandler<{}, TServices>): this;
|
|
305
307
|
post<S extends RouteSchema>(path: string, schema: S, handler: KozoHandler<S, TServices>): this;
|
|
308
|
+
put(path: string, handler: KozoHandler<{}, TServices>): this;
|
|
306
309
|
put<S extends RouteSchema>(path: string, schema: S, handler: KozoHandler<S, TServices>): this;
|
|
310
|
+
patch(path: string, handler: KozoHandler<{}, TServices>): this;
|
|
307
311
|
patch<S extends RouteSchema>(path: string, schema: S, handler: KozoHandler<S, TServices>): this;
|
|
312
|
+
delete(path: string, handler: KozoHandler<{}, TServices>): this;
|
|
308
313
|
delete<S extends RouteSchema>(path: string, schema: S, handler: KozoHandler<S, TServices>): this;
|
|
309
314
|
private register;
|
|
310
315
|
/**
|
|
@@ -657,4 +662,46 @@ declare class OpenAPIGenerator {
|
|
|
657
662
|
declare function generateSwaggerHtml(specUrl: string, title?: string): string;
|
|
658
663
|
declare function createOpenAPIGenerator(config: OpenAPIConfig): OpenAPIGenerator;
|
|
659
664
|
|
|
660
|
-
|
|
665
|
+
/**
|
|
666
|
+
* Common pagination query schema.
|
|
667
|
+
* Use it directly as the `query` field to avoid repeating this pattern everywhere.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* app.get('/users', { query: paginationSchema }, (ctx) => {
|
|
671
|
+
* const { page, limit } = ctx.query; // fully typed
|
|
672
|
+
* });
|
|
673
|
+
*/
|
|
674
|
+
declare const paginationSchema: z.ZodObject<{
|
|
675
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
676
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
677
|
+
}, z.core.$strip>;
|
|
678
|
+
/**
|
|
679
|
+
* Route param schema for `:id` routes that expect a UUID.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* app.get('/users/:id', { params: uuidParams }, (ctx) => ctx.params.id);
|
|
683
|
+
*/
|
|
684
|
+
declare const uuidParams: z.ZodObject<{
|
|
685
|
+
id: z.ZodString;
|
|
686
|
+
}, z.core.$strip>;
|
|
687
|
+
/**
|
|
688
|
+
* Route param schema for `:id` routes that expect a positive integer.
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* app.get('/posts/:id', { params: idParams }, (ctx) => ctx.params.id);
|
|
692
|
+
*/
|
|
693
|
+
declare const idParams: z.ZodObject<{
|
|
694
|
+
id: z.ZodCoercedNumber<unknown>;
|
|
695
|
+
}, z.core.$strip>;
|
|
696
|
+
/**
|
|
697
|
+
* Standard success/deleted response schema.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* app.delete('/users/:id', { params: uuidParams, response: deletedSchema }, ...);
|
|
701
|
+
*/
|
|
702
|
+
declare const deletedSchema: z.ZodObject<{
|
|
703
|
+
success: z.ZodBoolean;
|
|
704
|
+
deletedId: z.ZodString;
|
|
705
|
+
}, z.core.$strip>;
|
|
706
|
+
|
|
707
|
+
export { type ClientGeneratorOptions, type CompiledRoute, ERROR_RESPONSES, ForbiddenError, type InferResponse, type InferSchema, type InflightTracker, Kozo, type KozoConfig, type KozoContext, type KozoEnv, KozoError, type KozoHandler, type NativeKozoContext, type NativeKozoHandler, NotFoundError, type OpenAPIConfig, OpenAPIGenerator, type OpenAPIInfo, type OpenAPISpec, type Plugin, type ProblemDetails, type RouteInfo, type RouteSchema, SchemaCompiler, type Services, ShutdownManager, type ShutdownOptions, type ShutdownState, UnauthorizedError, type ValidationError, ValidationFailedError, buildNativeContext, compileRouteHandler, createInflightTracker, createKozo, createOpenAPIGenerator, createShutdownManager, deletedSchema, fastCL, fastWrite400, fastWrite404, fastWrite500, fastWriteError, fastWriteHtml, fastWriteJson, fastWriteJsonStatus, fastWriteText, forbiddenResponse, formatAjvErrors, formatZodErrors, generateSwaggerHtml, generateTypedClient, idParams, internalErrorResponse, notFoundResponse, paginationSchema, trackRequest, unauthorizedResponse, uuidParams, validationErrorResponse };
|
package/lib/index.js
CHANGED
|
@@ -2210,20 +2210,25 @@ var Kozo = class {
|
|
|
2210
2210
|
}));
|
|
2211
2211
|
return generateTypedClient(routeInfos, options);
|
|
2212
2212
|
}
|
|
2213
|
-
get(path,
|
|
2214
|
-
return this.register("get", path,
|
|
2213
|
+
get(path, schemaOrHandler, handler) {
|
|
2214
|
+
if (typeof schemaOrHandler === "function") return this.register("get", path, {}, schemaOrHandler);
|
|
2215
|
+
return this.register("get", path, schemaOrHandler, handler);
|
|
2215
2216
|
}
|
|
2216
|
-
post(path,
|
|
2217
|
-
return this.register("post", path,
|
|
2217
|
+
post(path, schemaOrHandler, handler) {
|
|
2218
|
+
if (typeof schemaOrHandler === "function") return this.register("post", path, {}, schemaOrHandler);
|
|
2219
|
+
return this.register("post", path, schemaOrHandler, handler);
|
|
2218
2220
|
}
|
|
2219
|
-
put(path,
|
|
2220
|
-
return this.register("put", path,
|
|
2221
|
+
put(path, schemaOrHandler, handler) {
|
|
2222
|
+
if (typeof schemaOrHandler === "function") return this.register("put", path, {}, schemaOrHandler);
|
|
2223
|
+
return this.register("put", path, schemaOrHandler, handler);
|
|
2221
2224
|
}
|
|
2222
|
-
patch(path,
|
|
2223
|
-
return this.register("patch", path,
|
|
2225
|
+
patch(path, schemaOrHandler, handler) {
|
|
2226
|
+
if (typeof schemaOrHandler === "function") return this.register("patch", path, {}, schemaOrHandler);
|
|
2227
|
+
return this.register("patch", path, schemaOrHandler, handler);
|
|
2224
2228
|
}
|
|
2225
|
-
delete(path,
|
|
2226
|
-
return this.register("delete", path,
|
|
2229
|
+
delete(path, schemaOrHandler, handler) {
|
|
2230
|
+
if (typeof schemaOrHandler === "function") return this.register("delete", path, {}, schemaOrHandler);
|
|
2231
|
+
return this.register("delete", path, schemaOrHandler, handler);
|
|
2227
2232
|
}
|
|
2228
2233
|
register(method, path, schema, handler) {
|
|
2229
2234
|
this.routes.push({ method, path, schema });
|
|
@@ -2381,7 +2386,7 @@ function buildNativeContext(req, res, params, body, services, serialize) {
|
|
|
2381
2386
|
}
|
|
2382
2387
|
|
|
2383
2388
|
// src/index.ts
|
|
2384
|
-
import { z } from "zod";
|
|
2389
|
+
import { z as z2 } from "zod";
|
|
2385
2390
|
|
|
2386
2391
|
// src/openapi.ts
|
|
2387
2392
|
import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
|
|
@@ -2797,6 +2802,23 @@ async function applyFileSystemRouting(app, options = {}) {
|
|
|
2797
2802
|
function createFileSystemRouting(options = {}) {
|
|
2798
2803
|
return (app) => applyFileSystemRouting(app, options);
|
|
2799
2804
|
}
|
|
2805
|
+
|
|
2806
|
+
// src/helpers.ts
|
|
2807
|
+
import { z } from "zod";
|
|
2808
|
+
var paginationSchema = z.object({
|
|
2809
|
+
page: z.coerce.number().int().min(1).default(1),
|
|
2810
|
+
limit: z.coerce.number().int().min(1).max(100).default(10)
|
|
2811
|
+
});
|
|
2812
|
+
var uuidParams = z.object({
|
|
2813
|
+
id: z.string().uuid()
|
|
2814
|
+
});
|
|
2815
|
+
var idParams = z.object({
|
|
2816
|
+
id: z.coerce.number().int().positive()
|
|
2817
|
+
});
|
|
2818
|
+
var deletedSchema = z.object({
|
|
2819
|
+
success: z.boolean(),
|
|
2820
|
+
deletedId: z.string()
|
|
2821
|
+
});
|
|
2800
2822
|
export {
|
|
2801
2823
|
ERROR_RESPONSES,
|
|
2802
2824
|
ForbiddenError,
|
|
@@ -2825,6 +2847,7 @@ export {
|
|
|
2825
2847
|
createKozo,
|
|
2826
2848
|
createOpenAPIGenerator,
|
|
2827
2849
|
createShutdownManager,
|
|
2850
|
+
deletedSchema,
|
|
2828
2851
|
errorHandler,
|
|
2829
2852
|
fastCL,
|
|
2830
2853
|
fastWrite400,
|
|
@@ -2840,13 +2863,16 @@ export {
|
|
|
2840
2863
|
formatZodErrors,
|
|
2841
2864
|
generateSwaggerHtml,
|
|
2842
2865
|
generateTypedClient,
|
|
2866
|
+
idParams,
|
|
2843
2867
|
internalErrorResponse,
|
|
2844
2868
|
logger,
|
|
2845
2869
|
notFoundResponse,
|
|
2870
|
+
paginationSchema,
|
|
2846
2871
|
rateLimit,
|
|
2847
2872
|
trackRequest,
|
|
2848
2873
|
unauthorizedResponse,
|
|
2874
|
+
uuidParams,
|
|
2849
2875
|
validationErrorResponse,
|
|
2850
|
-
z
|
|
2876
|
+
z2 as z
|
|
2851
2877
|
};
|
|
2852
2878
|
//# sourceMappingURL=index.js.map
|