8000 chore: Fix formatting · aklinker1/zeta@65c907f · GitHub
[go: up one dir, main page]

Skip to content

Commit 65c907f

Browse files
committed
chore: Fix formatting
1 parent cd6f813 commit 65c907f

10 files changed

Lines changed: 137 additions & 145 deletions

‎README.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ const app = createApp()
154154

155155
Internally, Zeta uses [`rou3`](https://www.npmjs.com/package/rou3) to match routes. To add a path parameter, you can use `:name`, `**`, or `**:name`. For type safety, you can use a validation framework to define an object schema for the path parameters.
156156

157-
158-
159157
> Note that path parameters are strings. If your validation framework supports converting strings to other types, like with Zod's [`z.coerce`](https://zod.dev/api?id=coercion) or [`z.stringbool`](https://zod.dev/api?id=stringbool), you can use it to convert the string values to the desired type.
160158
161159
### Query Parameters

‎docs/adding-routes.md‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const app = createApp()
77
.get("/api/users", {}, (ctx) => {})
88
.post("/api/users", {}, (ctx) => {})
99
.put("/api/users/:id", {}, (ctx) => {})
10-
.delete( "/api/users/:id", {}, (ctx) => {})
10+
.delete("/api/users/:id", {}, (ctx) => {})
1111
.method("PATCH", "/api/users/:id", {}, (ctx) => {})
1212
.any("/api/users", {}, (ctx) => {});
1313
```
@@ -24,18 +24,23 @@ All route definitions require 4 things:
2424
Here's a realistic example of what a route definition might look like:
2525

2626
```ts
27-
import { createApp, HttpStatus, ErrorResponse, NotFoundError } from '@aklinker1/zeta';
28-
import { z } from 'zod';
29-
import { addDbPlugin } from './plugins/db';
27+
import {
28+
createApp,
29+
HttpStatus,
30+
ErrorResponse,
31+
NotFoundError,
32+
} from "@aklinker1/zeta";
33+
import { z } from "zod";
34+
import { addDbPlugin } from "./plugins/db";
3035

3136
// Define schema's for validation
3237
const User = z.object({
3338
id: z.string(),
3439
username: z.string(),
3540
email: z.email(),
3641
profileUrl: z.url(),
37-
})
38-
const UpdateUserInput = User.omit({ id: true })
42+
});
43+
const UpdateUserInput = User.omit({ id: true });
3944

4045
const app = createApp()
4146
.use(addDbPlugin)
@@ -51,30 +56,32 @@ const app = createApp()
5156
responses: {
5257
[HttpStatus.Ok]: User,
5358
[HttpStatus.NotFound]: ErrorResponse,
54-
}
59+
},
5560
},
5661
async ({ path, body, status, db }) => {
5762
const updatedUser = await db.update(path.userId, body);
5863
if (!updatedUser) throw new NotFoundError("User not found");
5964

6065
return status(HttpStatus.Ok, updatedUser);
61-
}
62-
)
66+
},
67+
);
6368
```
6469

6570
:::tip Important Comments
6671

6772
- Some [Best Practices](/best-practices) are ignored to keep the example self-contained.
6873

6974
- Zod schemas are used to validate the input/output of our route.
70-
> See the [Validation docs](/validation) to learn more about how schemas are used to validate requests.
75+
76+
> See the [Validation docs](/validation) to learn more about how schemas are used to validate requests.
7177
7278
- This route has multiple responses: a 404 error and a 200 success.
79+
7380
> See the [Error Handling docs](/error-handling) to learn more about throwing the `NoteFoundError`
7481
7582
> See the [Validation docs](/validation) to learn more about how responses are validated.
7683
7784
- `addDb` plugin adds `db` to the handler's `ctx` object.
78-
> See the [Plugin docs](/composing-apps#plugins) for more details about what plugins are and how this is accomplished.
85+
> See the [Plugin docs](/composing-apps#plugins) for more details about what plugins are and how this is accomplished.
7986
8087
:::

‎docs/best-practices.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ I like to create two top-level files for my server:
1212
:::code-group
1313

1414
```ts [app.ts]
15-
import { createApp } from '@aklinker1/zeta'
15+
import { createApp } from "@aklinker1/zeta";
1616

1717
export const app = createApp();
1818
```
1919

2020
```ts [main.ts]
21-
import { app } from './app'
21+
import { app } from "./app";
2222

2323
app.listen(3000, () => {
24-
console.log('Server started on port 3000');
24+
console.log("Server started on port 3000");
2525
});
2626
```
2727

‎docs/client-side.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ openapi-generator generate \
2020
Zeta provides a type-safe API client out of the box. It only works if your frontend code is in the same project as your backend code.
2121

2222
```ts
23-
import type { app } from '../server/app';
24-
import { createAppClient } from '@aklinker1/zeta/client'
23+
import type { app } from "../server/app";
24+
import { createAppClient } from "@aklinker1/zeta/client";
2525

2626
const client = createAppClient<typeof app>({
2727
// options
28-
})
28+
});
2929
```
3030

3131
It's a basic wrapper around `fetch`.

‎docs/composing-apps.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ There are two approaches to implementing auth in Zeta:
156156
For simplicities sake, this example will cover the first approach.
157157

158158
```ts
159-
const AUTH_HEADER_PATTERN = /^Bearer (?<token>.*)$/
159+
const AUTH_HEADER_PATTERN = /^Bearer (?<token>.*)$/;
160160

161161
export const requireAuthPlugin = createApp()
162162
.onTransform(async ({ headers }) => {
163163
const { token } = headers.match(AUTH_HEADER_PATTERN)?.groups;
164164
if (!token) throw new UnauthorizedHttpError("Bearer token not provided");
165165

166166
const session = await getSessionFromToken(token);
167-
if (!session) throw new UnauthorizedHttpError("Invalid token")
167+
if (!session) throw new UnauthorizedHttpError("Invalid token");
168168

169169
return { session, token };
170170
})

‎docs/get-started.md‎

Expand all lines: docs/get-started.md
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ deno add @aklinker1/zeta
1515
// main.ts
1616
import { createApp } from "@aklinker1/zeta";
1717

18-
const app = createApp().get(
19-
"/",
20-
{},
21-
() => {
22-
return { message: "Hello World!" };
23-
},
24-
);
18+
const app = createApp().get("/", {}, () => {
19+
return { message: "Hello World!" };
20+
});
2521

2622
app.listen(3000);
2723

‎docs/openapi.md‎

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ In order to generate OpenAPI docs, Zeta needs a bit more information about your
1919
Your top-level app needs a `schemaAdapter` passed into it's options:
2020

2121
```ts
22-
import { zodSchemaAdapter } from '@aklinker1/zeta/adapters/zod-schema-adapter';
22+
import { zodSchemaAdapter } from "@aklinker1/zeta/adapters/zod-schema-adapter";
2323

2424
const app = createApp({
25-
schemaAdapter: zodSchemaAdapter
26-
})
25+
schemaAdapter: zodSchemaAdapter,
26+
});
2727
```
2828

2929
:::warning
@@ -45,18 +45,18 @@ The adapter is responsible for several functions not defined in the Standard Sch
4545
Currently, Zeta only provides a schema adapter for:
4646

4747
- Zod
48-
```ts
49-
import { zodSchemaAdapter } from '@aklinker1/zeta/adapters/zod-schema-adapter';
50-
```
48+
```ts
49+
import { zodSchemaAdapter } from "@aklinker1/zeta/adapters/zod-schema-adapter";
50+
```
5151

5252
If your validation library is not supported by Zeta, you just need to implement your own [schema adapter](https://jsr.io/@aklinker1/zeta/doc/types/~/SchemaAdapter):
5353

5454
```ts
55-
import type { SchemaAdapter } from '@aklinker1/zeta/types';
55+
import type { SchemaAdapter } from "@aklinker1/zeta/types";
5656

5757
export const arktypeSchemaAdapter: SchemaAdapter = {
5858
// Implement
59-
}
59+
};
6060
```
6161

6262
Use the [`zodSchemaAdapter`](https://github.com/aklinker1/zeta/blob/main/src/adapters/zod-schema-adapter.ts) for reference.
@@ -68,20 +68,20 @@ This is where you list the version, name, tags, security schema, and more.
6868
```ts
6969
const app = createApp({
7070
openApiInfo: {
71-
title: 'My API',
72-
version: '1.0.0',
73-
description: 'My API description',
71+
title: "My API",
72+
version: "1.0.0",
73+
description: "My API description",
7474
license: {
75-
name: 'MIT',
76-
url: 'https://opensource.org/licenses/MIT',
75+
name: "MIT",
76+
url: "https://opensource.org/licenses/MIT",
7777
},
7878
contact: {
79-
name: 'John Doe',
80-
email: 'john.doe@example.com',
81-
url: 'https://example.com',
79+
name: "John Doe",
80+
email: "john.doe@example.com",
81+
url: "https://example.com",
8282
},
8383
},
84-
})
84+
});
8585
```
8686

8787
## Custom Metadata
@@ -104,7 +104,7 @@ const GetHealthOutput = z
104104
})
105105
.meta({
106106
ref: "GetHealthOutput",
107-
})
107+
});
108108
```
109109

110110
:::
@@ -116,11 +116,9 @@ To change the response content type, add the `contentType` metadata to your obje
116116
:::code-group
117117

118118
```ts [Zod]
119-
const CsvDownloadOutput = z
120-
.string()
121-
.meta({
122-
contentType: "text/csv",
123-
})
119+
const CsvDownloadOutput = z.string().meta({
120+
contentType: "text/csv",
121+
});
124122
```
125123

126124
:::
@@ -156,8 +154,8 @@ import { writeFile } from "node:fs/promises";
156154

157155
const fetch = app.build();
158156

159-
const res = await fetch(new Request("/openapi.json"))
160-
const spec = await res.json()
157+
const res = await fetch(new Request("/openapi.json"));
158+
const spec = await res.json();
161159

162-
await writeFile("openapi.json", JSON.stringify(spec, null, 2))
160+
await writeFile("openapi.json", JSON.stringify(spec, null, 2));
163161
```

‎docs/request-life-cycle.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ There are two types of hooks: global and isolated.
3535

3636
- **Global**
3737

38-
These hooks are registered on the final, top-level app, regardless of where they are defined on a top-level or child app. They always run for every request that hits the server. Use these for cross-cutting concerns like logging or authentication.
38+
These hooks are registered on the final, top-level app, regardless of where they are defined on a top-level or child app. They always run for every request that hits the server. Use these for cross-cutting concerns like logging or authentication.
3939

4040
- **Isolated**
4141

42-
These hooks only apply to routes defined on the _same app instance_, _after_ the hook is added. They are perfect for setting up context or running middleware specific to a group of routes (e.g., a [plugin](/composing-apps#plugins)).
42+
These hooks only apply to routes defined on the _same app instance_, _after_ the hook is added. They are perfect for setting up context or running middleware specific to a group of routes (e.g., a [plugin](/composing-apps#plugins)).
4343

4444
## Hooks
4545

4646
### `onGlobalRequest`
4747

4848
Called as soon as a request is made to the app.
4949

50-
5150
Return value is shallow merged into the `ctx` object for future callbacks.
5251

5352
### `onTransform`

‎docs/testing.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ The basic idea of testing a Zeta app is to build a server-side `fetch` function
55
## Basic Usage
66

77
```ts
8-
import { test, expect } from 'vitest';
9-
import { app } from '../app';
8+
import { test, expect } from "vitest";
9+
import { app } from "../app";
1010

1111
const fetch = app.build();
1212

@@ -16,7 +16,7 @@ test('/api/health should return 200 OK { "status": "up" }', () => {
1616
const body = await response.json();
1717

1818
expect(response.status).toBe(200);
19-
expect(body).toEqual({ status: 'up' });
19+
expect(body).toEqual({ status: "up" });
2020
});
2121
```
2222

@@ -29,23 +29,23 @@ Consider using Zeta's test client or your generated API client instead.
2929
:::code-group
3030

3131
```ts [Zeta's Test Client]
32-
import { test, expect } from 'vitest';
33-
import { app } from '../app';
34-
import { createTestAppClient } from '@aklinker1/zeta/client';
32+
import { test, expect } from "vitest";
33+
import { app } from "../app";
34+
import { createTestAppClient } from "@aklinker1/zeta/client";
3535

3636
const client = createTestAppClient(app);
3737

3838
test('/api/health should return 200 OK { "status": "up" }', () => {
3939
const body = await client.fetch("GET", "/api/health", {});
4040

41-
expect(body).toEqual({ status: 'up' });
41+
expect(body).toEqual({ status: "up" });
4242
});
4343
```
4444

4545
```ts [Custom]
46-
import { test, expect } from 'vitest';
47-
import { app } from '../app';
48-
import { MyApiClient } from '../generated-client';
46+
import { test, expect } from "vitest";
47+
import { app } from "../app";
48+
import { MyApiClient } from "../generated-client";
4949

5050
const serverSideFetch = app.build();
5151
const client = new MyApiClient({
@@ -57,6 +57,6 @@ const client = new MyApiClient({
5757
test('/api/health should return 200 OK { "status": "up" }', () => {
5858
const body = await client.getHealth();
5959

60-
expect(body).toEqual({ status: 'up' });
60+
expect(body).toEqual({ status: "up" });
6161
});
6262
```

0 commit comments

Comments
 (0)
0