@kozojs/core 0.3.5 → 0.3.6

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.js CHANGED
@@ -601,10 +601,6 @@ async function createUwsServer(opts) {
601
601
  });
602
602
  }
603
603
 
604
- // src/compiler.ts
605
- import { zodToJsonSchema } from "zod-to-json-schema";
606
- import fastJson from "fast-json-stringify";
607
-
608
604
  // src/fast-response.ts
609
605
  var CL_CACHE = /* @__PURE__ */ (() => {
610
606
  const arr = new Array(1e4);
@@ -750,7 +746,6 @@ function makeZValidator(schema) {
750
746
  function isZodSchema(schema) {
751
747
  return typeof schema === "object" && schema !== null && "safeParse" in schema;
752
748
  }
753
- var ZOD_OPTS = { $refStrategy: "none", target: "jsonSchema7" };
754
749
  var HDR_JSON = { "Content-Type": "application/json" };
755
750
  var RESPONSE_INIT_200 = Object.freeze({ status: 200, headers: HDR_JSON });
756
751
  function jsonResponse200(body) {
@@ -775,23 +770,7 @@ var SchemaCompiler = class {
775
770
  compiled.validateParams = makeZValidator(schema.params);
776
771
  }
777
772
  if (schema.response) {
778
- if (typeof schema.response === "object" && !isZodSchema(schema.response)) {
779
- const keys = Object.keys(schema.response);
780
- const isStatusMap = keys.length > 0 && keys.every((k) => !isNaN(Number(k)));
781
- if (isStatusMap) {
782
- const responseSchemas = schema.response;
783
- if (responseSchemas[200]) {
784
- const jsonSchema = isZodSchema(responseSchemas[200]) ? zodToJsonSchema(responseSchemas[200], ZOD_OPTS) : responseSchemas[200];
785
- compiled.serialize = fastJson(jsonSchema);
786
- }
787
- } else {
788
- compiled.serialize = fastJson(schema.response);
789
- }
790
- } else {
791
- const responseSchema = schema.response;
792
- const jsonSchema = zodToJsonSchema(responseSchema, ZOD_OPTS);
793
- compiled.serialize = fastJson(jsonSchema);
794
- }
773
+ compiled.serialize = JSON.stringify;
795
774
  }
796
775
  return compiled;
797
776
  }
@@ -2030,7 +2009,7 @@ function createShutdownManager() {
2030
2009
  }
2031
2010
 
2032
2011
  // src/router.ts
2033
- import { glob } from "glob";
2012
+ import { readdir } from "fs/promises";
2034
2013
  import { join } from "path";
2035
2014
  import { pathToFileURL } from "url";
2036
2015
 
@@ -2080,6 +2059,19 @@ function isRouteFile(filename) {
2080
2059
  }
2081
2060
 
2082
2061
  // src/router.ts
2062
+ async function scanFiles(dir, base = "") {
2063
+ const results = [];
2064
+ const entries = await readdir(dir, { withFileTypes: true });
2065
+ for (const e of entries) {
2066
+ const rel = base ? `${base}/${e.name}` : e.name;
2067
+ if (e.isDirectory()) {
2068
+ results.push(...await scanFiles(join(dir, e.name), rel));
2069
+ } else if (/\.(ts|js)$/.test(e.name) && !e.name.startsWith("_") && !e.name.endsWith(".test.ts") && !e.name.endsWith(".test.js") && !e.name.endsWith(".spec.ts") && !e.name.endsWith(".spec.js")) {
2070
+ results.push(rel);
2071
+ }
2072
+ }
2073
+ return results;
2074
+ }
2083
2075
  async function scanRoutes(options) {
2084
2076
  const { routesDir, verbose = true } = options;
2085
2077
  const routes = [];
@@ -2088,12 +2080,7 @@ async function scanRoutes(options) {
2088
2080
  \u{1F50D} Scanning routes in: ${routesDir}
2089
2081
  `);
2090
2082
  }
2091
- const pattern = "**/*.{ts,js}";
2092
- const files = await glob(pattern, {
2093
- cwd: routesDir,
2094
- nodir: true,
2095
- ignore: ["**/_*.ts", "**/_*.js", "**/*.test.ts", "**/*.spec.ts"]
2096
- });
2083
+ const files = await scanFiles(routesDir);
2097
2084
  for (const file of files) {
2098
2085
  if (!isRouteFile(file)) continue;
2099
2086
  const parsed = fileToPath(file);
@@ -2390,7 +2377,7 @@ import { z } from "zod";
2390
2377
 
2391
2378
  // src/openapi.ts
2392
2379
  import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
2393
- function zodToJsonSchema2(zodSchema) {
2380
+ function zodToJsonSchema(zodSchema) {
2394
2381
  return _zodToJsonSchema(zodSchema, { $refStrategy: "none" });
2395
2382
  }
2396
2383
  var OpenAPIGenerator = class {
@@ -2480,7 +2467,7 @@ var OpenAPIGenerator = class {
2480
2467
  }
2481
2468
  }
2482
2469
  if (schema?.query) {
2483
- const querySchema = zodToJsonSchema2(schema.query);
2470
+ const querySchema = zodToJsonSchema(schema.query);
2484
2471
  if (querySchema.properties) {
2485
2472
  for (const [name, propSchema] of Object.entries(querySchema.properties)) {
2486
2473
  operation.parameters.push({
@@ -2493,7 +2480,7 @@ var OpenAPIGenerator = class {
2493
2480
  }
2494
2481
  }
2495
2482
  if (schema?.params) {
2496
- const paramsSchema = zodToJsonSchema2(schema.params);
2483
+ const paramsSchema = zodToJsonSchema(schema.params);
2497
2484
  if (paramsSchema.properties) {
2498
2485
  for (const [name, propSchema] of Object.entries(paramsSchema.properties)) {
2499
2486
  const existingIdx = operation.parameters.findIndex(
@@ -2510,7 +2497,7 @@ var OpenAPIGenerator = class {
2510
2497
  required: true,
2511
2498
  content: {
2512
2499
  "application/json": {
2513
- schema: zodToJsonSchema2(schema.body)
2500
+ schema: zodToJsonSchema(schema.body)
2514
2501
  }
2515
2502
  }
2516
2503
  };
@@ -2521,7 +2508,7 @@ var OpenAPIGenerator = class {
2521
2508
  description: this.getStatusDescription(parseInt(status)),
2522
2509
  content: {
2523
2510
  "application/json": {
2524
- schema: zodToJsonSchema2(responseSchema)
2511
+ schema: zodToJsonSchema(responseSchema)
2525
2512
  }
2526
2513
  }
2527
2514
  };