@kozojs/core 0.3.3 → 0.3.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/lib/index.d.ts +8 -8
- package/lib/index.js +20 -121
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -430,42 +430,42 @@ interface ProblemDetails {
|
|
|
430
430
|
}
|
|
431
431
|
declare const ERROR_RESPONSES: {
|
|
432
432
|
readonly VALIDATION_FAILED: {
|
|
433
|
-
readonly type: "https://kozo.
|
|
433
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#validation-failed";
|
|
434
434
|
readonly title: "Validation Failed";
|
|
435
435
|
readonly status: 400;
|
|
436
436
|
};
|
|
437
437
|
readonly INVALID_BODY: {
|
|
438
|
-
readonly type: "https://kozo.
|
|
438
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-body";
|
|
439
439
|
readonly title: "Invalid Request Body";
|
|
440
440
|
readonly status: 400;
|
|
441
441
|
};
|
|
442
442
|
readonly INVALID_QUERY: {
|
|
443
|
-
readonly type: "https://kozo.
|
|
443
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-query";
|
|
444
444
|
readonly title: "Invalid Query Parameters";
|
|
445
445
|
readonly status: 400;
|
|
446
446
|
};
|
|
447
447
|
readonly INVALID_PARAMS: {
|
|
448
|
-
readonly type: "https://kozo.
|
|
448
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-params";
|
|
449
449
|
readonly title: "Invalid Path Parameters";
|
|
450
450
|
readonly status: 400;
|
|
451
451
|
};
|
|
452
452
|
readonly INTERNAL_ERROR: {
|
|
453
|
-
readonly type: "https://kozo.
|
|
453
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#internal-error";
|
|
454
454
|
readonly title: "Internal Server Error";
|
|
455
455
|
readonly status: 500;
|
|
456
456
|
};
|
|
457
457
|
readonly NOT_FOUND: {
|
|
458
|
-
readonly type: "https://kozo.
|
|
458
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#not-found";
|
|
459
459
|
readonly title: "Resource Not Found";
|
|
460
460
|
readonly status: 404;
|
|
461
461
|
};
|
|
462
462
|
readonly UNAUTHORIZED: {
|
|
463
|
-
readonly type: "https://kozo.
|
|
463
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#unauthorized";
|
|
464
464
|
readonly title: "Unauthorized";
|
|
465
465
|
readonly status: 401;
|
|
466
466
|
};
|
|
467
467
|
readonly FORBIDDEN: {
|
|
468
|
-
readonly type: "https://kozo.
|
|
468
|
+
readonly type: "https://kozo-docs.vercel.app/docs/core/errors#forbidden";
|
|
469
469
|
readonly title: "Forbidden";
|
|
470
470
|
readonly status: 403;
|
|
471
471
|
};
|
package/lib/index.js
CHANGED
|
@@ -207,42 +207,42 @@ import { createServer as netCreateServer } from "net";
|
|
|
207
207
|
var CONTENT_TYPE_PROBLEM = "application/problem+json";
|
|
208
208
|
var ERROR_RESPONSES = {
|
|
209
209
|
VALIDATION_FAILED: {
|
|
210
|
-
type: "https://kozo.
|
|
210
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#validation-failed",
|
|
211
211
|
title: "Validation Failed",
|
|
212
212
|
status: 400
|
|
213
213
|
},
|
|
214
214
|
INVALID_BODY: {
|
|
215
|
-
type: "https://kozo.
|
|
215
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-body",
|
|
216
216
|
title: "Invalid Request Body",
|
|
217
217
|
status: 400
|
|
218
218
|
},
|
|
219
219
|
INVALID_QUERY: {
|
|
220
|
-
type: "https://kozo.
|
|
220
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-query",
|
|
221
221
|
title: "Invalid Query Parameters",
|
|
222
222
|
status: 400
|
|
223
223
|
},
|
|
224
224
|
INVALID_PARAMS: {
|
|
225
|
-
type: "https://kozo.
|
|
225
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#invalid-params",
|
|
226
226
|
title: "Invalid Path Parameters",
|
|
227
227
|
status: 400
|
|
228
228
|
},
|
|
229
229
|
INTERNAL_ERROR: {
|
|
230
|
-
type: "https://kozo.
|
|
230
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#internal-error",
|
|
231
231
|
title: "Internal Server Error",
|
|
232
232
|
status: 500
|
|
233
233
|
},
|
|
234
234
|
NOT_FOUND: {
|
|
235
|
-
type: "https://kozo.
|
|
235
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#not-found",
|
|
236
236
|
title: "Resource Not Found",
|
|
237
237
|
status: 404
|
|
238
238
|
},
|
|
239
239
|
UNAUTHORIZED: {
|
|
240
|
-
type: "https://kozo.
|
|
240
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#unauthorized",
|
|
241
241
|
title: "Unauthorized",
|
|
242
242
|
status: 401
|
|
243
243
|
},
|
|
244
244
|
FORBIDDEN: {
|
|
245
|
-
type: "https://kozo.
|
|
245
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#forbidden",
|
|
246
246
|
title: "Forbidden",
|
|
247
247
|
status: 403
|
|
248
248
|
}
|
|
@@ -352,7 +352,7 @@ var KozoError = class extends Error {
|
|
|
352
352
|
}
|
|
353
353
|
toResponse(instance) {
|
|
354
354
|
const body = {
|
|
355
|
-
type: `https://kozo.
|
|
355
|
+
type: `https://kozo-docs.vercel.app/docs/core/errors#${this.code}`,
|
|
356
356
|
title: this.message,
|
|
357
357
|
status: this.statusCode
|
|
358
358
|
};
|
|
@@ -378,7 +378,7 @@ var ValidationFailedError = class extends KozoError {
|
|
|
378
378
|
}
|
|
379
379
|
toResponse(instance) {
|
|
380
380
|
const body = {
|
|
381
|
-
type: "https://kozo.
|
|
381
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#validation-failed",
|
|
382
382
|
title: this.message,
|
|
383
383
|
status: 400,
|
|
384
384
|
errors: this.errors
|
|
@@ -424,7 +424,7 @@ var STATUS_TEXT = {
|
|
|
424
424
|
503: "503 Service Unavailable"
|
|
425
425
|
};
|
|
426
426
|
var BODY_404 = JSON.stringify({
|
|
427
|
-
type: "https://kozo.
|
|
427
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#not-found",
|
|
428
428
|
title: "Resource Not Found",
|
|
429
429
|
status: 404
|
|
430
430
|
});
|
|
@@ -432,7 +432,7 @@ var NO_BODY_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "DELETE", "OPTIONS
|
|
|
432
432
|
var CT_JSON = "application/json";
|
|
433
433
|
var CT_PROBLEM = "application/problem+json";
|
|
434
434
|
var BODY_500 = JSON.stringify({
|
|
435
|
-
type: "https://kozo.
|
|
435
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#internal-error",
|
|
436
436
|
title: "Internal Server Error",
|
|
437
437
|
status: 500
|
|
438
438
|
});
|
|
@@ -445,7 +445,7 @@ function uwsFastWriteJson(uwsRes, body) {
|
|
|
445
445
|
}
|
|
446
446
|
function uwsFastWrite400(field, errors, uwsRes) {
|
|
447
447
|
const body = JSON.stringify({
|
|
448
|
-
type: "https://kozo.
|
|
448
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#validation-failed",
|
|
449
449
|
title: "Validation Failed",
|
|
450
450
|
status: 400,
|
|
451
451
|
errors: (errors ?? []).map((e) => ({
|
|
@@ -470,7 +470,7 @@ function uwsFastWrite500(uwsRes) {
|
|
|
470
470
|
function uwsFastWriteError(err, uwsRes) {
|
|
471
471
|
if (err instanceof KozoError) {
|
|
472
472
|
const body = JSON.stringify({
|
|
473
|
-
type: `https://kozo.
|
|
473
|
+
type: `https://kozo-docs.vercel.app/docs/core/errors#${err.code}`,
|
|
474
474
|
title: err.message,
|
|
475
475
|
status: err.statusCode
|
|
476
476
|
});
|
|
@@ -619,13 +619,13 @@ var CT_PROBLEM2 = "application/problem+json";
|
|
|
619
619
|
var CT_TEXT = "text/plain";
|
|
620
620
|
var CT_HTML = "text/html; charset=utf-8";
|
|
621
621
|
var BODY_4042 = JSON.stringify({
|
|
622
|
-
type: "https://kozo.
|
|
622
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#not-found",
|
|
623
623
|
title: "Resource Not Found",
|
|
624
624
|
status: 404
|
|
625
625
|
});
|
|
626
626
|
var LEN_404 = fastCL(BODY_4042.length);
|
|
627
627
|
var BODY_5002 = JSON.stringify({
|
|
628
|
-
type: "https://kozo.
|
|
628
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#internal-error",
|
|
629
629
|
title: "Internal Server Error",
|
|
630
630
|
status: 500
|
|
631
631
|
});
|
|
@@ -688,7 +688,7 @@ function fastWrite500(res) {
|
|
|
688
688
|
}
|
|
689
689
|
function fastWrite400(field, errors, res) {
|
|
690
690
|
const body = JSON.stringify({
|
|
691
|
-
type: "https://kozo.
|
|
691
|
+
type: "https://kozo-docs.vercel.app/docs/core/errors#validation-failed",
|
|
692
692
|
title: "Validation Failed",
|
|
693
693
|
status: 400,
|
|
694
694
|
errors: (errors ?? []).map((e) => ({
|
|
@@ -708,7 +708,7 @@ function fastWrite400(field, errors, res) {
|
|
|
708
708
|
function fastWriteError(err, res) {
|
|
709
709
|
if (err instanceof KozoError) {
|
|
710
710
|
const body = JSON.stringify({
|
|
711
|
-
type: `https://kozo.
|
|
711
|
+
type: `https://kozo-docs.vercel.app/docs/core/errors#${err.code}`,
|
|
712
712
|
title: err.message,
|
|
713
713
|
status: err.statusCode
|
|
714
714
|
});
|
|
@@ -2389,110 +2389,9 @@ function buildNativeContext(req, res, params, body, services, serialize) {
|
|
|
2389
2389
|
import { z } from "zod";
|
|
2390
2390
|
|
|
2391
2391
|
// src/openapi.ts
|
|
2392
|
+
import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
|
|
2392
2393
|
function zodToJsonSchema2(zodSchema) {
|
|
2393
|
-
|
|
2394
|
-
const def = schema._def;
|
|
2395
|
-
if (!def) {
|
|
2396
|
-
return { type: "object" };
|
|
2397
|
-
}
|
|
2398
|
-
const typeName = def.typeName;
|
|
2399
|
-
switch (typeName) {
|
|
2400
|
-
case "ZodString": {
|
|
2401
|
-
const result = { type: "string" };
|
|
2402
|
-
for (const check of def.checks || []) {
|
|
2403
|
-
if (check.kind === "min") result.minLength = check.value;
|
|
2404
|
-
if (check.kind === "max") result.maxLength = check.value;
|
|
2405
|
-
if (check.kind === "email") result.format = "email";
|
|
2406
|
-
if (check.kind === "url") result.format = "uri";
|
|
2407
|
-
if (check.kind === "uuid") result.format = "uuid";
|
|
2408
|
-
if (check.kind === "regex") result.pattern = check.regex.source;
|
|
2409
|
-
}
|
|
2410
|
-
return result;
|
|
2411
|
-
}
|
|
2412
|
-
case "ZodNumber": {
|
|
2413
|
-
const result = { type: "number" };
|
|
2414
|
-
for (const check of def.checks || []) {
|
|
2415
|
-
if (check.kind === "min") result.minimum = check.value;
|
|
2416
|
-
if (check.kind === "max") result.maximum = check.value;
|
|
2417
|
-
if (check.kind === "int") result.type = "integer";
|
|
2418
|
-
}
|
|
2419
|
-
return result;
|
|
2420
|
-
}
|
|
2421
|
-
case "ZodBoolean":
|
|
2422
|
-
return { type: "boolean" };
|
|
2423
|
-
case "ZodNull":
|
|
2424
|
-
return { type: "null" };
|
|
2425
|
-
case "ZodArray":
|
|
2426
|
-
return {
|
|
2427
|
-
type: "array",
|
|
2428
|
-
items: zodToJsonSchema2(def.type)
|
|
2429
|
-
};
|
|
2430
|
-
case "ZodObject": {
|
|
2431
|
-
const properties = {};
|
|
2432
|
-
const required = [];
|
|
2433
|
-
const shape = def.shape?.() || def.shape;
|
|
2434
|
-
if (shape) {
|
|
2435
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
2436
|
-
properties[key] = zodToJsonSchema2(value);
|
|
2437
|
-
const fieldDef = value._def;
|
|
2438
|
-
if (fieldDef?.typeName !== "ZodOptional" && fieldDef?.typeName !== "ZodDefault") {
|
|
2439
|
-
required.push(key);
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
return {
|
|
2444
|
-
type: "object",
|
|
2445
|
-
properties,
|
|
2446
|
-
...required.length > 0 ? { required } : {}
|
|
2447
|
-
};
|
|
2448
|
-
}
|
|
2449
|
-
case "ZodEnum":
|
|
2450
|
-
return {
|
|
2451
|
-
type: "string",
|
|
2452
|
-
enum: def.values
|
|
2453
|
-
};
|
|
2454
|
-
case "ZodNativeEnum":
|
|
2455
|
-
return {
|
|
2456
|
-
type: "string",
|
|
2457
|
-
enum: Object.values(def.values)
|
|
2458
|
-
};
|
|
2459
|
-
case "ZodLiteral":
|
|
2460
|
-
return {
|
|
2461
|
-
type: typeof def.value,
|
|
2462
|
-
enum: [def.value]
|
|
2463
|
-
};
|
|
2464
|
-
case "ZodUnion":
|
|
2465
|
-
return {
|
|
2466
|
-
oneOf: def.options.map((opt) => zodToJsonSchema2(opt))
|
|
2467
|
-
};
|
|
2468
|
-
case "ZodOptional":
|
|
2469
|
-
return {
|
|
2470
|
-
...zodToJsonSchema2(def.innerType),
|
|
2471
|
-
nullable: true
|
|
2472
|
-
};
|
|
2473
|
-
case "ZodNullable":
|
|
2474
|
-
return {
|
|
2475
|
-
...zodToJsonSchema2(def.innerType),
|
|
2476
|
-
nullable: true
|
|
2477
|
-
};
|
|
2478
|
-
case "ZodDefault":
|
|
2479
|
-
return {
|
|
2480
|
-
...zodToJsonSchema2(def.innerType),
|
|
2481
|
-
default: def.defaultValue()
|
|
2482
|
-
};
|
|
2483
|
-
case "ZodRecord":
|
|
2484
|
-
return {
|
|
2485
|
-
type: "object",
|
|
2486
|
-
additionalProperties: zodToJsonSchema2(def.valueType)
|
|
2487
|
-
};
|
|
2488
|
-
case "ZodDate":
|
|
2489
|
-
return { type: "string", format: "date-time" };
|
|
2490
|
-
case "ZodAny":
|
|
2491
|
-
case "ZodUnknown":
|
|
2492
|
-
return {};
|
|
2493
|
-
default:
|
|
2494
|
-
return { type: "object" };
|
|
2495
|
-
}
|
|
2394
|
+
return _zodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
2496
2395
|
}
|
|
2497
2396
|
var OpenAPIGenerator = class {
|
|
2498
2397
|
config;
|