Skip to content

Commit

Permalink
fix: few small types in service docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DawidWraga committed Mar 26, 2024
1 parent bdce1ba commit 02a12b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Davstack service provides a structured service builder, decoupling your _service

- **Seamless Integration with tRPC**: Davstack Service is built to complement tRPC. You can easily turn your services into tRPC procedures / routers with 0 boilerplate.

Services also infer the output type from the query/mutation function. This means that output schemas are optional, just like tRPC.

### Installation

```bash
Expand All @@ -36,7 +38,6 @@ import { z } from 'zod';

const getTasks = service()
.input(z.object({ projectId: z.string() }))
.output(z.array(z.object({ id: z.string(), title: z.string() })))
.query(async ({ ctx, input }) => {
// Complex logic to fetch tasks based on projectId
return tasks;
Expand Down Expand Up @@ -84,7 +85,7 @@ export type ServiceContext = {

export const publicService = service<ServiceContext>();

const protectedService = service<Required<ServiceContext>>().use(
export const protectedService = service<Required<ServiceContext>>().use(
async ({ ctx, next }) => {
if (!ctx.user) {
throw new Error('Unauthorized');
Expand All @@ -95,11 +96,11 @@ const protectedService = service<Required<ServiceContext>>().use(
```

```ts filename="usage.ts"
export const publicService = publicService().query(async ({ ctx }) => {
export const publicService = publicService.query(async ({ ctx }) => {
return 'Public data';
});

export const protectedService = protectedService().query(async ({ ctx }) => {
export const protectedService = protectedService.query(async ({ ctx }) => {
return 'Protected data';
});
```
Expand Down
2 changes: 1 addition & 1 deletion packages/service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@davstack/service",
"version": "0.1.1",
"version": "0.1.2",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit 02a12b1

Please sign in to comment.