bxo 0.0.5-dev.71 → 0.0.5-dev.73

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/example/index.ts CHANGED
@@ -3,7 +3,7 @@ import index from "./index.html";
3
3
  import { openapi } from "../plugins/openapi";
4
4
 
5
5
  async function main() {
6
- const bxo = new BXO();
6
+ const bxo = new BXO({ serve: { port: 0 } });
7
7
 
8
8
  bxo.default("/", index);
9
9
  bxo.default("/*", index);
@@ -136,8 +136,8 @@ async function main() {
136
136
 
137
137
  // Health check route
138
138
  bxo.get("/health", (ctx) => {
139
- return ctx.json({
140
- status: "ok",
139
+ return ctx.json({
140
+ status: "ok",
141
141
  timestamp: new Date().toISOString(),
142
142
  uptime: process.uptime()
143
143
  });
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  ".": "./src/index.ts",
6
6
  "./plugins": "./plugins/index.ts"
7
7
  },
8
- "version": "0.0.5-dev.71",
8
+ "version": "0.0.5-dev.73",
9
9
  "type": "module",
10
10
  "devDependencies": {
11
11
  "@types/bun": "latest"
@@ -1,5 +1,5 @@
1
1
  import BXO, { z } from "../src";
2
- import { createDocument, type CreateDocumentOptions, type ZodOpenApiPathsObject, type ZodOpenApiSecuritySchemeObject } from "zod-openapi";
2
+ import { createDocument, type CreateDocumentOptions, type ZodOpenApiPathItemObject, type ZodOpenApiPathsObject, type ZodOpenApiSecuritySchemeObject } from "zod-openapi";
3
3
 
4
4
  interface SecurityScheme extends ZodOpenApiSecuritySchemeObject {
5
5
  type: "http" | "apiKey" | "oauth2" | "openIdConnect";
@@ -40,24 +40,24 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
40
40
  }
41
41
 
42
42
  // Extract tags from route metadata
43
- const tags = route.schema?.detail?.tags ||
44
- route.schema?.detail?.tag ||
45
- config?.defaultTags ||
46
- []
43
+ const tags = route.schema?.detail?.tags ||
44
+ route.schema?.detail?.tag ||
45
+ config?.defaultTags ||
46
+ []
47
47
 
48
48
  // Extract security requirements from route metadata
49
- const routeSecurity = route.schema?.detail?.security ||
50
- route.schema?.detail?.auth ||
51
- undefined
49
+ const routeSecurity = route.schema?.detail?.security ||
50
+ route.schema?.detail?.auth ||
51
+ undefined
52
52
 
53
53
  // Extract operation summary and description
54
- const summary = route.schema?.detail?.summary ||
55
- route.schema?.detail?.title ||
56
- `${method.toUpperCase()} ${route.path}`
57
-
58
- const description = route.schema?.detail?.description ||
59
- route.schema?.detail?.docs ||
60
- undefined
54
+ const summary = route.schema?.detail?.summary ||
55
+ route.schema?.detail?.title ||
56
+ `${method.toUpperCase()} ${route.path}`
57
+
58
+ const description = route.schema?.detail?.description ||
59
+ route.schema?.detail?.docs ||
60
+ undefined
61
61
 
62
62
  // Extract parameters from route path
63
63
  const parameters = []
@@ -76,15 +76,16 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
76
76
  }
77
77
 
78
78
  // Add query parameters if defined
79
- if (route.schema?.detail?.query) {
80
- const querySchema = route.schema?.detail?.query
79
+ if (route.schema?.query) {
80
+ const querySchema = route.schema?.query
81
81
  if (querySchema && typeof querySchema === 'object' && 'shape' in querySchema) {
82
82
  const queryShape = (querySchema as any).shape
83
83
  for (const [key, schema] of Object.entries(queryShape)) {
84
+ const isOptional = schema instanceof z.ZodOptional
84
85
  parameters.push({
85
86
  name: key,
86
87
  in: "query",
87
- required: false, // Query params are typically optional
88
+ required: !isOptional, // Query params are typically optional
88
89
  schema: schema as any
89
90
  })
90
91
  }
@@ -138,7 +139,7 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
138
139
  }
139
140
  }
140
141
  }
141
- }
142
+ } satisfies ZodOpenApiPathItemObject
142
143
  }
143
144
  return paths
144
145
  }
package/src/index.ts CHANGED
@@ -272,12 +272,13 @@ export default class BXO {
272
272
  }
273
273
  }
274
274
 
275
+ this.serveOptions.port = this.serveOptions.port === undefined ? 3000 : this.serveOptions.port;
276
+
275
277
  this.server = Bun.serve({
276
278
  ...this.serveOptions,
277
279
  routes: nativeRoutes as any,
278
280
  fetch: (req: Request) => this.dispatchAny(req, nativeRoutes)
279
281
  });
280
- const port = (this.server as any).port ?? this.serveOptions.port ?? 3000;
281
282
  }
282
283
 
283
284
  // Lifecycle hook methods