Skip to content

Commit 6274203

Browse files
committed
Migrate to tsdown and update internal APIs
1 parent 033bf36 commit 6274203

16 files changed

Lines changed: 665 additions & 1202 deletions

.ls-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ignore:
1515
- dist
1616
- "**/dist"
1717
- apis
18+
- "**/@types"
1819
- "*.tsbuildinfo"
1920
- "**/*.tsbuildinfo"
2021
- "**/*.log"

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set windows-shell := ["powershell"]
44
node_bin := "./node_modules/.bin/"
55
tsc := node_bin + "tsc"
66
biome := node_bin + "biome"
7-
tsup := node_bin + "tsup"
7+
tsdown := node_bin + "tsdown"
88
vitest := node_bin + "vitest"
99
typedoc := node_bin + "typedoc"
1010

@@ -36,7 +36,7 @@ fmt:
3636

3737
# Build package
3838
build:
39-
cd package && ../{{tsup}}
39+
cd package && ../{{tsdown}} -c tsdown.config.ts
4040

4141
# Run tests
4242
test:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@apst/biome": "~0.3.0",
55
"@apst/tsconfig": "~0.1.3",
66
"@biomejs/biome": "^2.1.2",
7-
"tsup": "^8.5.0",
7+
"tsdown": "~0.13.0",
88
"typedoc": "~0.28.7",
99
"typedoc-plugin-markdown": "^4.7.1",
1010
"typescript": "^5.8.3"

package/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Next
2+
3+
### What's Changed
4+
5+
- Internal API changes
6+
17
## 0.1.3 (2025-06-12)
28

39
### What's Changed

package/package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@
2929
"import": "./dist/index.mjs",
3030
"require": "./dist/index.js"
3131
},
32-
"./internal": {
33-
"types": "./dist/internal.d.ts",
34-
"import": "./dist/internal.mjs",
35-
"require": "./dist/internal.js"
32+
"./response/common/struct": {
33+
"types": "./dist/response/common/struct.d.ts",
34+
"import": "./dist/response/common/struct.mjs",
35+
"require": "./dist/response/common/struct.js"
36+
},
37+
"./response/json/struct": {
38+
"types": "./dist/response/json/struct.d.ts",
39+
"import": "./dist/response/json/struct.mjs",
40+
"require": "./dist/response/json/struct.js"
41+
},
42+
"./response/headers/merge": {
43+
"types": "./dist/response/headers/merge.d.ts",
44+
"import": "./dist/response/headers/merge.mjs",
45+
"require": "./dist/response/headers/merge.js"
3646
},
3747
"./package.json": "./package.json"
3848
},

package/src/@types/response.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** JSON response error. */
2+
type JsonResponseError = {
3+
/** Error code. */
4+
code: string;
5+
/** Field of the error. */
6+
field?: string;
7+
/** Message of the error. */
8+
message?: string;
9+
};
10+
11+
/** JSON response. */
12+
type JsonResponse<D = unknown> = {
13+
/** Whether the response is successful. */
14+
success: boolean;
15+
/** Data for the response when `success` is `true`. */
16+
data?: D;
17+
/** Error for the response when `success` is `false`. */
18+
error?: JsonResponseError;
19+
};
20+
21+
export type { JsonResponseError, JsonResponse };

package/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export type { CreateResponseOptions } from "#/response";
21
export type {
3-
CreateJsonResponseOptions,
42
JsonResponse,
53
JsonResponseError,
6-
} from "#/response/json";
4+
} from "#/@types/response";
5+
export type { CreateResponseOptions } from "#/response/common";
6+
export type { CreateJsonResponseOptions } from "#/response/json";
77

8-
export { createResponse } from "#/response";
8+
export { createResponse } from "#/response/common";
99
export { createJsonResponse } from "#/response/json";

package/src/internal.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { CreateResponseStructOptions } from "#/response/common/struct";
2+
3+
import { createResponseStruct } from "#/response/common/struct";
4+
5+
/** Options of `createResponse` function. */
6+
type CreateResponseOptions<B extends BodyInit = BodyInit> =
7+
CreateResponseStructOptions<B>;
8+
9+
/**
10+
* Create a response.
11+
*
12+
* ### Examples
13+
*
14+
* Example for creating a basic response:
15+
*
16+
* ```ts
17+
* import { createResponse } from "@jderjs/core";
18+
*
19+
* const route = (): Response => {
20+
* return createResponse();
21+
* };
22+
* ```
23+
*
24+
* Example for creating a response with status, headers, and body:
25+
*
26+
* ```ts
27+
* import { createResponse } from "@jderjs/core";
28+
*
29+
* const route = (): Response => {
30+
* return createResponse({
31+
* status: 404,
32+
* headers: [
33+
* ["Content-Type", "text/plain"],
34+
* ],
35+
* body: "Not Found",
36+
* });
37+
* };
38+
* ```
39+
*/
40+
const createResponse = <B extends BodyInit = BodyInit>(
41+
options?: CreateResponseOptions<B>,
42+
): Response => {
43+
const { status, headers, body } = createResponseStruct(options);
44+
45+
return new Response(body, {
46+
status,
47+
headers,
48+
});
49+
};
50+
51+
export type { CreateResponseOptions };
52+
export { createResponse };
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { mergeHeaders } from "#/response/headers/merge";
2+
3+
type CreateResponseStructOptions<B extends BodyInit = BodyInit> = {
4+
/**
5+
* Status code of the response.
6+
* By default, it is `200`.
7+
*/
8+
status?: number;
9+
/**
10+
* Additional headers of the response.
11+
*/
12+
headers?: HeadersInit;
13+
/**
14+
* Body of the response.
15+
*/
16+
body?: B;
17+
};
18+
19+
/** Response structure. */
20+
type ResponseStruct<B = unknown> = {
21+
/** Status code of the response. */
22+
status: number;
23+
/** Headers of the response. */
24+
headers: [
25+
string,
26+
string,
27+
][];
28+
/** Body of the response. */
29+
body?: B;
30+
};
31+
32+
const createResponseStruct = <B extends BodyInit = BodyInit>(
33+
options?: CreateResponseStructOptions<B>,
34+
): ResponseStruct<B> => {
35+
return {
36+
status: options?.status ?? 200,
37+
headers: mergeHeaders(options?.headers),
38+
body: options?.body,
39+
};
40+
};
41+
42+
export type { CreateResponseStructOptions, ResponseStruct };
43+
export { createResponseStruct };

0 commit comments

Comments
 (0)