Skip to content

Commit d1f9421

Browse files
Adapt ArkType as a core technology (#213)
### Description <!-- Provide a comprehensive description here about what your PR aims to solve. --> <!-- You may also add additional context --> Migrate from TypeBox to ArkType, TypeScript's 1:1 validator. --- ### PR Checklist <!-- Please do not remove this section --> <!-- Mark each item with an "x" ([ ] becomes [x]) --> - [x] Read the Developer's Guide in [CONTRIBUTING.md](https://github.com/bedtime-coders/bedstack/blob/main/CONTRIBUTING.md) - [x] Use a concise title to represent the changes introduced in this PR - [x] Provide a detailed description of the changes introduced in this PR, and, if necessary, some screenshots - [x] Reference an issue or discussion where the feature or changes have been previously discussed - [x] Add a failing test that passes with the changes introduced in this PR, or explain why it's not feasible - [x] Add documentation for the feature or changes introduced in this PR to the docs; you can run them with `bun docs` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Switched project validation/type system to ArkType, updating runtime/type exports. * **Bug Fixes** * Improved validation error formatting and path/message handling for clearer, more robust errors. * **Documentation** * Updated Bun links to bun.com; added ArkType and Biome to docs, badges, and setup guidance; refreshed overview and getting-started content. * **Chores** * Updated dependencies to add ArkType/arkregex and remove legacy validator; minor package description tweak. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a6d29e4 commit d1f9421

31 files changed

+258
-272
lines changed

CODE_OF_CONDUCT.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Contributor Covenant Code of Conduct
22

3-
## Our Pledge
3+
## Pledge
44

5-
We as members, contributors, and leaders pledge to make participation in our
5+
Members, contributors, and leaders pledge to make participation in the
66
community a harassment-free experience for everyone, regardless of age, body
77
size, visible or invisible disability, ethnicity, sex characteristics, gender
88
identity and expression, level of experience, education, socio-economic status,
99
nationality, personal appearance, race, religion, or sexual identity
1010
and orientation.
1111

12-
We pledge to act and interact in ways that contribute to an open, welcoming,
12+
The pledge is to act and interact in ways that contribute to an open, welcoming,
1313
diverse, inclusive, and healthy community.
1414

15-
## Our Standards
15+
## Standards
1616

1717
Examples of behavior that contributes to a positive environment for our
1818
community include:
1919

2020
- Demonstrating empathy and kindness toward other people
2121
- Being respectful of differing opinions, viewpoints, and experiences
2222
- Giving and gracefully accepting constructive feedback
23-
- Accepting responsibility and apologizing to those affected by our mistakes,
23+
- Accepting responsibility and apologizing to those affected by mistakes,
2424
and learning from the experience
25-
- Focusing on what is best not just for us as individuals, but for the
25+
- Focusing on what is best not just for individuals, but for the
2626
overall community
2727

2828
Examples of unacceptable behavior include:
@@ -38,7 +38,7 @@ Examples of unacceptable behavior include:
3838

3939
## Enforcement Responsibilities
4040

41-
Community leaders are responsible for clarifying and enforcing our standards of
41+
Community leaders are responsible for clarifying and enforcing standards of
4242
acceptable behavior and will take appropriate and fair corrective action in
4343
response to any behavior that they deem inappropriate, threatening, offensive,
4444
or harmful.
@@ -52,15 +52,14 @@ decisions when appropriate.
5252

5353
This Code of Conduct applies within all community spaces, and also applies when
5454
an individual is officially representing the community in public spaces.
55-
Examples of representing our community include using an official e-mail address,
55+
Examples of representing the community include using an official e-mail address,
5656
posting via an official social media account, or acting as an appointed
5757
representative at an online or offline event.
5858

5959
## Enforcement
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62-
reported to the community leaders responsible for enforcement by contacting the maintainer team
63-
.
62+
reported to community leaders responsible for enforcement by contacting the maintainer.
6463
All complaints will be reviewed and investigated promptly and fairly.
6564

6665
All community leaders are obligated to respect the privacy and security of the

CONTRIBUTING.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Developer's Guide
22

3-
Hey there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great and we truly appreciate your time and effort.
3+
Hey there! Contributing to this project is highly encouraged. Community help is essential for maintaining its quality, and every effort is appreciated.
44

55
> [!IMPORTANT]
66
> Before submitting your contribution, please take a moment and read through the following guidelines.
77
88
## 👨‍💻 Repository Setup
99

10-
This project uses [Bun](https://bun.sh) as a runtime as well as a package manager. It's a modern, fast, and lightweight alternative to [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/). To install Bun on POSIX systems (like Ubuntu or macOS), run the following command:
10+
This project uses [Bun](https://bun.com) as a runtime as well as a package manager. It's a modern, fast, and lightweight alternative to [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/). To install Bun on POSIX systems (like Ubuntu or macOS), run the following command:
1111

1212
```sh
13-
curl -fsSL https://bun.sh/install | bash
13+
curl -fsSL https://bun.com/install | bash
1414
```
1515

16-
Otherwise, visit the [Bun installation page](https://bun.sh/docs/installation) for installation options.
16+
Otherwise, visit the [Bun installation page](https://bun.com/docs/installation) for installation options.
1717

1818
## 💡 Commands
1919

@@ -27,7 +27,7 @@ Build the project for production. The result is under `dist/`.
2727

2828
### `bun check`
2929

30-
We use [Biome](https://biomejs.dev/) for **both linting and formatting**. It is an ultra-fast, Rust based linter and formatter.
30+
Biome is used for **both linting and formatting**. It is an ultra-fast, Rust based linter and formatter.
3131
It also lints JSON.
3232

3333
You can also run `bun fix` to apply any safe fixes automatically.
@@ -54,7 +54,7 @@ For typo fixes, it's recommended to batch multiple typo fixes into one pull requ
5454

5555
### Pull Request
5656

57-
If you don't know how to send a Pull Request, we recommend reading [the guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
57+
If you don't know how to send a Pull Request, it is recommended to read [the guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
5858

5959
If your PR fixes or resolves an existing issue, please add the following line in your PR description according to the following example:
6060

@@ -75,19 +75,21 @@ Replacing:
7575

7676
This will let GitHub know the issues are linked, and automatically close them once the PR gets merged. Learn more at [the guide](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword).
7777

78-
It's ok to have multiple commits in a single PR, you don't need to rebase or force push for your changes as we will use `Squash and Merge` to squash the commits into one commit when merging.
78+
It's ok to have multiple commits in a single PR; changes do not need to be rebased or force pushed, as Squash and Merge will be used to combine the commits into one when merging.
7979

8080
## 📖 References
8181

8282
### Lint
8383

84-
We use [Biome](https://biomejs.dev/) for both linting and formatting with [a few custom rules](./biome.jsonc). It is an ultra-fast, Rust based linter and formatter.
84+
Biome is used for both linting and formatting with [a few custom rules](./biome.jsonc). It is an ultra-fast, Rust based linter and formatter.
8585

8686
<table><tr><td>
8787

8888
#### IDE Setup
8989

90-
We recommend using [VS Code](https://code.visualstudio.com/) along with the [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome).
90+
[Visual Studio Code](https://code.visualstudio.com/) is recommended for the best experience along with:
91+
- [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) for linting and formatting.
92+
- [ArkType extension](https://marketplace.visualstudio.com/items?itemName=arktypeio.arkdark) for syntax highlighting and type-safe regex support.
9193

9294
With the settings on the right, you can have auto fix and formatting when you save the code you are editing.
9395

GOVERNANCE.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
<img src="apps/www/public/logo-mini.png" alt="Logo for Bedstack RealWorld example" width=200>
44
<h1>Bedstack</h1>
55

6-
[![Tests Status](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml/badge.svg?event=push&branch=main&)](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml?query=branch%3Amain+event%3Apush) [![Discord](https://img.shields.io/discord/1164270344115335320?label=Chat&color=5865f4&logo=discord&labelColor=121214)](https://discord.gg/8UcP9QB5AV) [![License](https://custom-icon-badges.demolab.com/github/license/bedtime-coders/bedstack?label=License&color=blue&logo=law&labelColor=0d1117)](https://github.com/bedtime-coders/bedstack/blob/main/LICENSE) [![Bun](https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df)](https://bun.sh/) [![ElysiaJS](https://custom-icon-badges.demolab.com/badge/ElysiaJS-0f172b.svg?logo=elysia)](https://elysiajs.com/) [![Drizzle](https://img.shields.io/badge/Drizzle-C5F74F?logo=drizzle&logoColor=000)](https://drizzle.team/) [![Biome](https://img.shields.io/badge/Biome-24272f?logo=biome&logoColor=f6f6f9)](https://biomejs.dev/) [![Scalar](https://img.shields.io/badge/Scalar-080808?logo=scalar&logoColor=e7e7e7)](https://scalar.com/) [![Star](https://custom-icon-badges.demolab.com/github/stars/bedtime-coders/bedstack?logo=star&logoColor=373737&label=Star)](https://github.com/bedtime-coders/bedstack/stargazers/)
6+
[![Tests Status](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml/badge.svg?event=push&branch=main&)](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml?query=branch%3Amain+event%3Apush) [![Discord](https://img.shields.io/discord/1164270344115335320?label=Chat&color=5865f4&logo=discord&labelColor=121214)](https://discord.gg/8UcP9QB5AV) [![License](https://custom-icon-badges.demolab.com/github/license/bedtime-coders/bedstack?label=License&color=blue&logo=law&labelColor=0d1117)](https://github.com/bedtime-coders/bedstack/blob/main/LICENSE) [![Bun](https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df)](https://bun.com/) [![ElysiaJS](https://custom-icon-badges.demolab.com/badge/ElysiaJS-0f172b.svg?logo=elysia)](https://elysiajs.com/) [![Drizzle](https://img.shields.io/badge/Drizzle-C5F74F?logo=drizzle&logoColor=000)](https://drizzle.team/) [![ArkType](https://custom-icon-badges.demolab.com/badge/ArkType-0d1526?logo=arktype2&logoColor=e9eef9)](https://arktype.io/) [![Biome](https://img.shields.io/badge/Biome-24272f?logo=biome&logoColor=f6f6f9)](https://biomejs.dev/) [![Scalar](https://img.shields.io/badge/Scalar-080808?logo=scalar&logoColor=e7e7e7)](https://scalar.com/) [![Star](https://custom-icon-badges.demolab.com/github/stars/bedtime-coders/bedstack?logo=star&logoColor=373737&label=Star)](https://github.com/bedtime-coders/bedstack/stargazers/)
77

8-
[Bun](https://bun.sh/) + [ElysiaJS](https://elysiajs.com/) + [Drizzle](https://orm.drizzle.team/) = the stack you don't want to sleep on
8+
[Bun](https://bun.com/) + [ElysiaJS](https://elysiajs.com/) + [Drizzle](https://orm.drizzle.team/) = the stack you don't want to sleep on
99

1010
[bedstack.js.org](https://bedstack.js.org)
1111

1212
</div>
1313

1414
> [!TIP]
15-
> **New!** Our Prisma-based alternative to Bedstack was just approved on CodebaseShow. Check it out: [Bepstack](https://github.com/bedtime-coders/bepstack)
16-
17-
> [!TIP]
18-
> **New!** We've added support for [Drizzle v1 Beta](https://orm.drizzle.team/roadmap) in _Bedstack (Stripped)_. Check it out: [`drizzle-v1` branch](https://github.com/bedtime-coders/bedstack-stripped/tree/drizzle-v1)
15+
> ⚡ Bedstack supports [Drizzle v1 Beta](https://orm.drizzle.team/roadmap)! Check it out: [`drizzle-v1` branch](https://github.com/bedtime-coders/bedstack-stripped/tree/drizzle-v1)
1916
2017
<br/>
2118
<br/>

SUPPORT.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ This article explains where to get help with Bedstack.
44
Please read through the following guidelines.
55

66
> [!WARNING]
7-
> Before participating in our community, please read our
7+
> Before participating in the community, please read the
88
> [code of conduct](CODE_OF_CONDUCT.md).
99
> By interacting with this repository, organization, or community you agree to
1010
> abide by its terms.
1111
1212
## Asking quality questions
1313

14-
Questions can go to our [Discord server](https://discord.gg/8UcP9QB5AV) or [GitHub discussions](https://github.com/bedtime-coders/bedstack/discussions).
14+
Questions can go to the [Discord server](https://discord.gg/8UcP9QB5AV) or [GitHub discussions](https://github.com/bedtime-coders/bedstack/discussions).
1515

16-
Help us help you!
16+
Clear questions are easier to answer.
1717
Spend time framing questions and add links and resources.
1818
Spending the extra time up front can help save everyone time in the long run.
1919
Here are some tips:
@@ -29,7 +29,7 @@ Here are some tips:
2929
* Provide sample code, such as a [CodeSandbox](https://codesandbox.io/) or video, if possible
3030
* Screenshots can help, but if there’s important text such as code or error
3131
messages in them, please also provide those as text
32-
* The more time you put into asking your question, the better we can help you
32+
* The more time put into asking a question, the better the community can provide assistance
3333

3434
## Contributions
3535

apps/conduit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img src="../www/public/logo-mini.png" alt="Logo for Bedstack RealWorld example" width=200>
44
<h1>Conduit - Bedstack real world example</h1>
55

6-
[![Tests Status](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml/badge.svg?event=push&branch=main&)](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml?query=branch%3Amain+event%3Apush) [![Discord](https://img.shields.io/discord/1164270344115335320?label=Chat&color=5865f4&logo=discord&labelColor=121214)](https://discord.gg/8UcP9QB5AV) [![License](https://custom-icon-badges.demolab.com/github/license/bedtime-coders/bedstack?label=License&color=blue&logo=law&labelColor=0d1117)](https://github.com/bedtime-coders/bedstack/blob/main/LICENSE) [![Bun](https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df)](https://bun.sh/) [![ElysiaJS](https://custom-icon-badges.demolab.com/badge/ElysiaJS-0f172b.svg?logo=elysia)](https://elysiajs.com/) [![Drizzle](https://img.shields.io/badge/Drizzle-C5F74F?logo=drizzle&logoColor=000)](https://orm.drizzle.team/) [![Biome](https://img.shields.io/badge/Biome-24272f?logo=biome&logoColor=f6f6f9)](https://biomejs.dev/) [![Scalar](https://img.shields.io/badge/Scalar-080808?logo=scalar&logoColor=e7e7e7)](https://scalar.com/) [![Star](https://custom-icon-badges.demolab.com/github/stars/bedtime-coders/bedstack?logo=star&logoColor=373737&label=Star)](https://github.com/bedtime-coders/bedstack/stargazers/)
6+
[![Tests Status](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml/badge.svg?event=push&branch=main&)](https://github.com/bedtime-coders/bedstack/actions/workflows/tests.yml?query=branch%3Amain+event%3Apush) [![Discord](https://img.shields.io/discord/1164270344115335320?label=Chat&color=5865f4&logo=discord&labelColor=121214)](https://discord.gg/8UcP9QB5AV) [![License](https://custom-icon-badges.demolab.com/github/license/bedtime-coders/bedstack?label=License&color=blue&logo=law&labelColor=0d1117)](https://github.com/bedtime-coders/bedstack/blob/main/LICENSE) [![Bun](https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df)](https://bun.com/) [![ElysiaJS](https://custom-icon-badges.demolab.com/badge/ElysiaJS-0f172b.svg?logo=elysia)](https://elysiajs.com/) [![Drizzle](https://img.shields.io/badge/Drizzle-C5F74F?logo=drizzle&logoColor=000)](https://orm.drizzle.team/) [![Biome](https://img.shields.io/badge/Biome-24272f?logo=biome&logoColor=f6f6f9)](https://biomejs.dev/) [![Scalar](https://img.shields.io/badge/Scalar-080808?logo=scalar&logoColor=e7e7e7)](https://scalar.com/) [![Star](https://custom-icon-badges.demolab.com/github/stars/bedtime-coders/bedstack?logo=star&logoColor=373737&label=Star)](https://github.com/bedtime-coders/bedstack/stargazers/)
77

88
[RealWorld](https://realworld-docs.netlify.app/) example app for [Bedstack](https://bedstack.js.org/)
99
</div>

apps/conduit/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
"@elysiajs/bearer": "^1.4.2",
3737
"@elysiajs/jwt": "^1.4.0",
3838
"@elysiajs/swagger": "^1.3.1",
39-
"@sinclair/typebox": "0.34.47",
4039
"@yolk-oss/elysia-env": "^3.0.0",
40+
"arkregex": "0.0.5",
41+
"arktype": "^2.1.29",
4142
"chalk": "^5.6.2",
4243
"drizzle-orm": "^0.45.1",
4344
"elysia": "^1.4.21",
@@ -54,8 +55,5 @@
5455
"drizzle-seed": "^0.3.1",
5556
"pg": "^8.16.3",
5657
"typescript": "catalog:"
57-
},
58-
"overrides": {
59-
"@sinclair/typebox": "0.34.34"
6058
}
6159
}

apps/conduit/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const setupApp = () => {
2828
set.status = error.status;
2929
return pick(error, ['errors']);
3030
}
31-
// Elysia validation errors (TypeBox based)
31+
// Elysia validation errors (ArkType based)
3232
if (error instanceof ValidationError) {
3333
return formatValidationError(error);
3434
}

apps/conduit/src/articles/articles.controller.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Elysia, t } from 'elysia';
1+
import { type } from 'arktype';
2+
import { Elysia } from 'elysia';
23
import { StatusCodes } from 'http-status-codes';
34
import { setupArticles } from '@/articles/articles.module';
45
import { DEFAULT_LIMIT, DEFAULT_OFFSET } from '@/shared/constants';
@@ -173,9 +174,7 @@ export const articlesController = new Elysia().use(setupArticles).group(
173174
{
174175
beforeHandle: app.store.authService.requireLogin,
175176
response: {
176-
[StatusCodes.NO_CONTENT]: t.Void({
177-
description: 'No content',
178-
}),
177+
[StatusCodes.NO_CONTENT]: type('undefined'),
179178
},
180179
detail: {
181180
summary: 'Delete Article',
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { t } from 'elysia';
1+
import { type } from 'arktype';
22
import {
33
DEFAULT_LIMIT,
44
DEFAULT_OFFSET,
@@ -13,22 +13,9 @@ import {
1313
* - limit: number of items per request (default: DEFAULT_LIMIT, min: MIN_LIMIT, max: MAX_LIMIT)
1414
* - offset: number of items to skip (default: DEFAULT_OFFSET, min: MIN_OFFSET)
1515
*/
16-
export const ArticleFeedQueryDto = t.Object({
17-
limit: t.Optional(
18-
t.Integer({
19-
minimum: MIN_LIMIT,
20-
maximum: MAX_LIMIT,
21-
default: DEFAULT_LIMIT,
22-
description: `Number of items per request (between ${MIN_LIMIT} and ${MAX_LIMIT}, defaults to ${DEFAULT_LIMIT})`,
23-
}),
24-
),
25-
offset: t.Optional(
26-
t.Integer({
27-
minimum: MIN_OFFSET,
28-
default: DEFAULT_OFFSET,
29-
description: `Number of items to skip (at least ${MIN_OFFSET}, defaults to ${DEFAULT_OFFSET})`,
30-
}),
31-
),
16+
export const ArticleFeedQueryDto = type({
17+
limit: `${MIN_LIMIT} <= number.integer <= ${MAX_LIMIT} = ${DEFAULT_LIMIT}`,
18+
offset: `number.integer >= ${MIN_OFFSET} = ${DEFAULT_OFFSET}`,
3219
});
3320

34-
export type ArticleFeedQueryDto = typeof ArticleFeedQueryDto.static;
21+
export type ArticleFeedQueryDto = typeof ArticleFeedQueryDto.infer;

0 commit comments

Comments
 (0)