You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/action/README.md
+42-17Lines changed: 42 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
#DavstackService
1
+
#DavstackAction
2
2
3
-
DavstackService is simple and flexible library for building backend services with TypeScript.
3
+
DavstackAction is simple and flexible library for building backend services with TypeScript.
4
4
5
-
###Why Use DavstackService?
5
+
###Why Use DavstackAction?
6
6
7
7
- 🏠 Simple and familiar syntax - middleware, input and outputs inspired by trpc procedures
8
8
- 🧩 Flexible - Works well with next js server actions as well as trpc
@@ -14,22 +14,47 @@ Davstack Service is simple and flexible library for building backend services wi
14
14
npm install zod @davstack/service
15
15
```
16
16
17
-
Visit the[DavStackService Docs](https://davstack.com/service/overview) for more information and examples, such as this[trpc usage example](https://davstack.com/service/trpc-usage-example).
17
+
Visit the[DavStackAction Docs](https://davstack.com/service/overview) for more information and examples, such as this[trpc usage example](https://davstack.com/service/trpc-usage-example).
18
18
19
19
##Demo Usage
20
20
21
21
- The service definition replaces tRPC procedures, but the syntax is very similar.
22
22
- Once the service is integrated into tRPC routers, the API is the same as any other tRPC router.
23
23
24
+
##directly calling service example
25
+
26
+
```tsx
27
+
exportconst generatePdf=authedAction
28
+
.input(z.object({ html:z.string() }))
29
+
.query(async ({ctx,input })=> {
30
+
// complex business logic here
31
+
returnpdf;
32
+
});
33
+
34
+
/**
35
+
* safe call eg from front end (usign nextjs server actions)
36
+
* - will run authed middleware
37
+
* - will parse inputs/outputs if defined
38
+
*/
39
+
const pdf=awaitgeneratePdf({ html:'...' });
40
+
41
+
/**
42
+
* raw call eg from backend such inside another action
Unlike tRPC procedures, services can be called directly from anywhere in your backend, including within other services.
160
185
@@ -209,7 +234,7 @@ NOTE: it is recommended to use the `* as yourServicesName` syntax. Otherwise, ct
209
234
210
235
Davstack Store has been heavily inspired by[tRPC](https://trpc.io/), a fantastic library for building type-safe APIs. A big shout-out to the tRPC team for their amazing work.
211
236
212
-
Nick-Lucas, a tRPC contributor, inspired the creation of DavstackService with his[github comment](https://github.com/trpc/trpc/discussions/4839#discussioncomment-8224476). He suggested "making controllers minimal" and "to separate your business logic from the API logic", which is exactly what DavstackService aims to do.
237
+
Nick-Lucas, a tRPC contributor, inspired the creation of DavstackAction with his[github comment](https://github.com/trpc/trpc/discussions/4839#discussioncomment-8224476). He suggested "making controllers minimal" and "to separate your business logic from the API logic", which is exactly what DavstackAction aims to do.