better-call 1.0.0 → 1.0.2
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 +22 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.cjs +19 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -22
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{router-Bpb8tT1Y.d.cts → router-DUkPVacX.d.cts} +2 -2
- package/dist/{router-Bpb8tT1Y.d.ts → router-DUkPVacX.d.ts} +2 -2
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -459,7 +459,7 @@ const createItem = createEndpoint("/item/:id", {
|
|
|
459
459
|
})
|
|
460
460
|
}),
|
|
461
461
|
metadata: {
|
|
462
|
-
|
|
462
|
+
openapi: {
|
|
463
463
|
requestBody: {
|
|
464
464
|
content: {
|
|
465
465
|
"application/json": {
|
|
@@ -486,5 +486,26 @@ const createItem = createEndpoint("/item/:id", {
|
|
|
486
486
|
})
|
|
487
487
|
```
|
|
488
488
|
|
|
489
|
+
#### Configuration
|
|
490
|
+
|
|
491
|
+
You can configure the open api schema by passing the `openapi` option to the router.
|
|
492
|
+
|
|
493
|
+
```ts
|
|
494
|
+
const router = createRouter({
|
|
495
|
+
createItem
|
|
496
|
+
}, {
|
|
497
|
+
openapi: {
|
|
498
|
+
disabled: false, //default false
|
|
499
|
+
path: "/api/reference", //default /api/reference
|
|
500
|
+
scalar: {
|
|
501
|
+
title: "My API",
|
|
502
|
+
version: "1.0.0",
|
|
503
|
+
description: "My API Description",
|
|
504
|
+
theme: "dark" //default saturn
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
})
|
|
508
|
+
```
|
|
509
|
+
|
|
489
510
|
## License
|
|
490
511
|
MIT
|
package/dist/client.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
-
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-
|
|
2
|
+
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-DUkPVacX.cjs';
|
|
3
3
|
|
|
4
4
|
type HasRequired<T extends {
|
|
5
5
|
body?: any;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
|
|
2
|
-
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-
|
|
2
|
+
import { j as Router, W as UnionToIntersection, b as Endpoint, T as HasRequiredKeys } from './router-DUkPVacX.js';
|
|
3
3
|
|
|
4
4
|
type HasRequired<T extends {
|
|
5
5
|
body?: any;
|
package/dist/index.cjs
CHANGED
|
@@ -151,10 +151,7 @@ function toResponse(data, init) {
|
|
|
151
151
|
return toResponse(data.body, {
|
|
152
152
|
status: data.statusCode,
|
|
153
153
|
statusText: data.status.toString(),
|
|
154
|
-
headers:
|
|
155
|
-
...data.headers instanceof Headers ? Object.fromEntries(data.headers.entries()) : data?.headers,
|
|
156
|
-
...init?.headers instanceof Headers ? Object.fromEntries(init.headers.entries()) : init?.headers
|
|
157
|
-
}
|
|
154
|
+
headers: init?.headers || data.headers
|
|
158
155
|
});
|
|
159
156
|
}
|
|
160
157
|
let body = data;
|
|
@@ -4478,8 +4475,8 @@ function getTypeFromZodType(zodType) {
|
|
|
4478
4475
|
}
|
|
4479
4476
|
function getParameters(options) {
|
|
4480
4477
|
const parameters = [];
|
|
4481
|
-
if (options.metadata?.
|
|
4482
|
-
parameters.push(...options.metadata.
|
|
4478
|
+
if (options.metadata?.openapi?.parameters) {
|
|
4479
|
+
parameters.push(...options.metadata.openapi.parameters);
|
|
4483
4480
|
return parameters;
|
|
4484
4481
|
}
|
|
4485
4482
|
if (options.query instanceof ZodObject) {
|
|
@@ -4502,8 +4499,8 @@ function getParameters(options) {
|
|
|
4502
4499
|
return parameters;
|
|
4503
4500
|
}
|
|
4504
4501
|
function getRequestBody(options) {
|
|
4505
|
-
if (options.metadata?.
|
|
4506
|
-
return options.metadata.
|
|
4502
|
+
if (options.metadata?.openapi?.requestBody) {
|
|
4503
|
+
return options.metadata.openapi.requestBody;
|
|
4507
4504
|
}
|
|
4508
4505
|
if (!options.body) return void 0;
|
|
4509
4506
|
if (options.body instanceof ZodObject || options.body instanceof ZodOptional) {
|
|
@@ -4644,16 +4641,16 @@ async function generator(endpoints, config) {
|
|
|
4644
4641
|
if (options.method === "GET") {
|
|
4645
4642
|
paths[value.path] = {
|
|
4646
4643
|
get: {
|
|
4647
|
-
tags: ["Default", ...options.metadata?.
|
|
4648
|
-
description: options.metadata?.
|
|
4649
|
-
operationId: options.metadata?.
|
|
4644
|
+
tags: ["Default", ...options.metadata?.openapi?.tags || []],
|
|
4645
|
+
description: options.metadata?.openapi?.description,
|
|
4646
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
4650
4647
|
security: [
|
|
4651
4648
|
{
|
|
4652
4649
|
bearerAuth: []
|
|
4653
4650
|
}
|
|
4654
4651
|
],
|
|
4655
4652
|
parameters: getParameters(options),
|
|
4656
|
-
responses: getResponse(options.metadata?.
|
|
4653
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
4657
4654
|
}
|
|
4658
4655
|
};
|
|
4659
4656
|
}
|
|
@@ -4661,9 +4658,9 @@ async function generator(endpoints, config) {
|
|
|
4661
4658
|
const body = getRequestBody(options);
|
|
4662
4659
|
paths[value.path] = {
|
|
4663
4660
|
post: {
|
|
4664
|
-
tags: ["Default", ...options.metadata?.
|
|
4665
|
-
description: options.metadata?.
|
|
4666
|
-
operationId: options.metadata?.
|
|
4661
|
+
tags: ["Default", ...options.metadata?.openapi?.tags || []],
|
|
4662
|
+
description: options.metadata?.openapi?.description,
|
|
4663
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
4667
4664
|
security: [
|
|
4668
4665
|
{
|
|
4669
4666
|
bearerAuth: []
|
|
@@ -4683,7 +4680,7 @@ async function generator(endpoints, config) {
|
|
|
4683
4680
|
}
|
|
4684
4681
|
}
|
|
4685
4682
|
},
|
|
4686
|
-
responses: getResponse(options.metadata?.
|
|
4683
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
4687
4684
|
}
|
|
4688
4685
|
};
|
|
4689
4686
|
}
|
|
@@ -4790,19 +4787,19 @@ async function getBody(request) {
|
|
|
4790
4787
|
|
|
4791
4788
|
// src/router.ts
|
|
4792
4789
|
var createRouter = (endpoints, config) => {
|
|
4793
|
-
if (!config?.
|
|
4794
|
-
const
|
|
4790
|
+
if (!config?.openapi?.disabled) {
|
|
4791
|
+
const openapi = {
|
|
4795
4792
|
path: "/api/reference",
|
|
4796
|
-
...config?.
|
|
4793
|
+
...config?.openapi
|
|
4797
4794
|
};
|
|
4798
|
-
endpoints["
|
|
4799
|
-
|
|
4795
|
+
endpoints["openapi"] = createEndpoint2(
|
|
4796
|
+
openapi.path,
|
|
4800
4797
|
{
|
|
4801
4798
|
method: "GET"
|
|
4802
4799
|
},
|
|
4803
4800
|
async (c) => {
|
|
4804
4801
|
const schema = await generator(endpoints);
|
|
4805
|
-
return new Response(getHTML(schema,
|
|
4802
|
+
return new Response(getHTML(schema, openapi.scalar), {
|
|
4806
4803
|
headers: {
|
|
4807
4804
|
"Content-Type": "text/html"
|
|
4808
4805
|
}
|