@orpc/experimental-effect 2.0.0-beta.31 → 2.0.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <a href="https://codecov.io/gh/middleapi/orpc">
5
5
  <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
6
6
  </a>
7
- <a href="https://npmx.dev/package/@orpc/experimental-effect">
7
+ <a href="https://www.npmjs.com/package/@orpc/experimental-effect">
8
8
  <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fexperimental-effect?logo=npm" />
9
9
  </a>
10
10
  <a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
@@ -29,44 +29,54 @@ You can read the documentation [here](https://orpc.dev).
29
29
 
30
30
  **Core**
31
31
 
32
- - [@orpc/contract](https://npmx.dev/package/@orpc/contract): Define API contract as the single source of truth.
33
- - [@orpc/server](https://npmx.dev/package/@orpc/server): Build APIs or implement contracts.
34
- - [@orpc/client](https://npmx.dev/package/@orpc/client): Consume APIs with end-to-end type safety.
35
- - [@orpc/openapi](https://npmx.dev/package/@orpc/openapi): Add OpenAPI compatibility to APIs.
32
+ | Package | Purpose | Docs |
33
+ | -------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
34
+ | [@orpc/contract](https://www.npmjs.com/package/@orpc/contract) | Define API contract as the single source of truth. | [Procedure Contract](https://orpc.dev/docs/contract/procedure), [Contract Router](https://orpc.dev/docs/contract/router), [Implementation](https://orpc.dev/docs/contract/implementation), [Generate from OpenAPI](https://orpc.dev/docs/contract/generate-from-openapi) |
35
+ | [@orpc/server](https://www.npmjs.com/package/@orpc/server) | Build APIs or implement contracts. | [Procedure](https://orpc.dev/docs/procedure), [Router](https://orpc.dev/docs/router), [Middleware](https://orpc.dev/docs/middleware), [Context](https://orpc.dev/docs/context), [RPC Handler](https://orpc.dev/docs/rpc/handler) |
36
+ | [@orpc/client](https://www.npmjs.com/package/@orpc/client) | Consume APIs with end-to-end type safety. | [Client-Side Clients](https://orpc.dev/docs/client/client-side), [Server-Side Clients](https://orpc.dev/docs/client/server-side), [RPC Link](https://orpc.dev/docs/rpc/link), [Error Handling](https://orpc.dev/docs/client/error-handling) |
37
+ | [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi) | Add OpenAPI compatibility to APIs. | [OpenAPI Handler](https://orpc.dev/docs/openapi/handler), [OpenAPI Link](https://orpc.dev/docs/openapi/link), [Specification](https://orpc.dev/docs/openapi/specification), [Scalar](https://orpc.dev/docs/openapi/scalar) |
36
38
 
37
39
  **Schema validation**
38
40
 
39
- - [@orpc/zod](https://npmx.dev/package/@orpc/zod): Integrate with [Zod](https://zod.dev/).
40
- - [@orpc/valibot](https://npmx.dev/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
41
- - [@orpc/arktype](https://npmx.dev/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
41
+ | Package | Purpose | Docs |
42
+ | ------------------------------------------------------------ | ----------------------------------------------- | ----------------------------------------------------- |
43
+ | [@orpc/zod](https://www.npmjs.com/package/@orpc/zod) | Integrate with [Zod](https://zod.dev/). | [Zod](https://orpc.dev/docs/integrations/zod) |
44
+ | [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot) | Integrate with [Valibot](https://valibot.dev/). | [Valibot](https://orpc.dev/docs/integrations/valibot) |
45
+ | [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype) | Integrate with [ArkType](https://arktype.io/). | [ArkType](https://orpc.dev/docs/integrations/arktype) |
42
46
 
43
47
  **Built-in features**
44
48
 
45
- - [@orpc/publisher](https://npmx.dev/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
46
- - [@orpc/ratelimit](https://npmx.dev/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
47
- - [@orpc/hibernation](https://npmx.dev/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api).
48
- - [@orpc/json-schema](https://npmx.dev/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
49
+ | Package | Purpose | Docs |
50
+ | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
51
+ | [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
52
+ | [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
53
+ | [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
54
+ | [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
49
55
 
50
56
  **Framework & ecosystem integrations**
51
57
 
52
- - [@orpc/next](https://npmx.dev/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
53
- - [@orpc/ai-sdk](https://npmx.dev/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
54
- - [@orpc/tanstack-query](https://npmx.dev/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
55
- - [@orpc/pinia-colada](https://npmx.dev/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
56
- - [@orpc/swr](https://npmx.dev/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
57
- - [@orpc/experimental-msw](https://npmx.dev/package/@orpc/experimental-msw): Mock procedures with [Mock Service Worker](https://mswjs.io/).
58
- - [@orpc/experimental-effect](https://npmx.dev/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
59
- - [@orpc/nest](https://npmx.dev/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
60
- - [@orpc/node](https://npmx.dev/package/@orpc/node): [Node.js](https://nodejs.org/) plugins for static file serving and large uploads.
61
- - [@orpc/bun](https://npmx.dev/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
62
- - [@orpc/cloudflare](https://npmx.dev/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
63
- - [@orpc/trpc](https://npmx.dev/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
58
+ | Package | Purpose | Docs |
59
+ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
60
+ | [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
61
+ | [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
62
+ | [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
63
+ | [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
64
+ | [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
65
+ | [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
66
+ | [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
67
+ | [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
68
+ | [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
69
+ | [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
70
+ | [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
71
+ | [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
64
72
 
65
73
  **Observability**
66
74
 
67
- - [@orpc/opentelemetry](https://npmx.dev/package/@orpc/opentelemetry): Integrate with [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
68
- - [@orpc/pino](https://npmx.dev/package/@orpc/pino): Integrate with [Pino](https://getpino.io/) for logging.
69
- - [@orpc/evlog](https://npmx.dev/package/@orpc/evlog): Integrate with [Evlog](https://evlog.dev/) for logging.
75
+ | Package | Purpose | Docs |
76
+ | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
77
+ | [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry) | Integrate with [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. | [OpenTelemetry](https://orpc.dev/docs/integrations/opentelemetry) |
78
+ | [@orpc/pino](https://www.npmjs.com/package/@orpc/pino) | Integrate with [Pino](https://getpino.io/) for logging. | [Pino](https://orpc.dev/docs/integrations/pino) |
79
+ | [@orpc/evlog](https://www.npmjs.com/package/@orpc/evlog) | Integrate with [Evlog](https://evlog.dev/) for logging. | [Evlog](https://orpc.dev/docs/integrations/evlog) |
70
80
 
71
81
  ## Sponsors
72
82
 
@@ -76,6 +86,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
76
86
  <tr>
77
87
  <td width="2000"><a href="https://screenshotone.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener" title="The screenshot API for developers"><img src="https://avatars.githubusercontent.com/u/97035603?v=4" width="64" align="left" hspace="12" alt="ScreenshotOne.com"/><b>ScreenshotOne.com</b></a><br /><sub>The screenshot API for developers</sub></td>
78
88
  </tr>
89
+ <tr>
90
+ <td width="2000"><a href="https://yuzu.health/careers?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="We&#39;re hiring NYC based engineers"><img src="https://avatars.githubusercontent.com/u/102488956?v=4" width="64" align="left" hspace="12" alt="Yuzu"/><b>Yuzu</b></a><br /><sub>We&#39;re hiring NYC based engineers</sub></td>
91
+ </tr>
79
92
  <tr>
80
93
  <td width="2000"><a href="https://misskey.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Decentralized microblogging SNS born on Earth"><img src="https://github.com/MisskeyIO.png" width="64" align="left" hspace="12" alt="MisskeyHQ"/><b>MisskeyHQ</b></a><br /><sub>Decentralized microblogging SNS born on Earth</sub></td>
81
94
  </tr>
@@ -113,6 +126,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
113
126
  <td align="center"><a href="https://github.com/itigoore01?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="139" alt="shota"/><br />shota</a></td>
114
127
  <td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&amp;v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
115
128
  <td align="center"><a href="https://github.com/hoangbn?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&amp;v=4" width="139" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
129
+ <td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="139" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
116
130
  </tr>
117
131
  </table>
118
132
 
@@ -121,30 +135,32 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
121
135
  <table>
122
136
  <tr>
123
137
  <td align="center"><a href="https://github.com/rhinodavid?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&amp;v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td>
138
+ <td align="center"><a href="https://github.com/IPv4Addr?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="IPv4Addr"><img src="https://avatars.githubusercontent.com/u/100147665?u=59996b72f69bb53063cb7e9ff8b8f898616cd94d&amp;v=4" width="119" alt="IPv4Addr"/><br />IPv4Addr</a></td>
124
139
  <td align="center"><a href="https://robbevaes.be/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&amp;v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
125
140
  <td align="center"><a href="https://github.com/aidansunbury?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
126
141
  <td align="center"><a href="https://github.com/soonoo?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&amp;v=4" width="119" alt="soonoo"/><br />soonoo</a></td>
127
142
  <td align="center"><a href="https://kevinporten.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&amp;v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td>
128
143
  <td align="center"><a href="https://github.com/pumpkinlink?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="119" alt="Denis"/><br />Denis</a></td>
129
- <td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
130
144
  </tr>
131
145
  <tr>
146
+ <td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
132
147
  <td align="center"><a href="http://ballingt.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
133
148
  <td align="center"><a href="https://lee-sam.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="119" alt="Sam"/><br />Sam</a></td>
134
149
  <td align="center"><a href="https://github.com/Titoine?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="119" alt="Titoine"/><br />Titoine</a></td>
135
150
  <td align="center"><a href="https://rigtch.fm/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td>
136
151
  <td align="center"><a href="https://blog.cwang.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&amp;v=4" width="119" alt="hanayashiki"/><br />hanayashiki</a></td>
137
152
  <td align="center"><a href="https://dubinets.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&amp;v=4" width="119" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
138
- <td align="center"><a href="https://bika.ai/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
139
153
  </tr>
140
154
  <tr>
155
+ <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
141
156
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td>
157
+ <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="119" alt="PaulSenon"/><br />PaulSenon</a></td>
142
158
  <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="119" alt="Alex"/><br />Alex</a></td>
143
159
  <td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&amp;v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
144
160
  </tr>
145
161
  </table>
146
162
 
147
- With thanks to [37 past sponsors](https://htmlpreview.github.io/?https://github.com/middleapi/static/blob/main/sponsors.svg) who helped get oRPC here.
163
+ With thanks to [36 past sponsors](https://htmlpreview.github.io/?https://github.com/middleapi/static/blob/main/sponsors.svg) who helped get oRPC here.
148
164
 
149
165
  ## References
150
166
 
@@ -1,25 +1,25 @@
1
1
  import { ErrorMap, InferSchemaOutput, InitialInputSchema, Schema, AnySchema, InferSchemaInput } from '@orpc/contract';
2
2
  import { Context, ORPCErrorConstructorMap, DecoratedProcedure, AnyORPCError, MergedContext, ImplementedProcedure } from '@orpc/server';
3
3
  import { Effect } from 'effect';
4
- import { WithEffectContext, HandlerGen, InferYieldError } from '../index.mjs';
4
+ import { InferEffectServices, HandlerGen, InferYieldError } from '../index.mjs';
5
5
 
6
6
  declare module '@orpc/server' {
7
7
  interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
8
- effect<TYield extends Effect.Effect<any, any, TInitialContext extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<TInitialContext, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
8
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<TInitialContext>>, TReturn>(handler: HandlerGen<TInitialContext, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
9
9
  }
10
10
  interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
11
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
11
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
12
12
  }
13
13
  interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
14
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
14
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
15
15
  }
16
16
  interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
17
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
17
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
18
18
  }
19
19
  interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
20
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
20
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
21
21
  }
22
22
  interface ProcedureImplementer<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
23
- effect(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, AnyORPCError | InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ImplementedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
23
+ effect(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, AnyORPCError | InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ImplementedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
24
24
  }
25
25
  }
@@ -1,25 +1,25 @@
1
1
  import { ErrorMap, InferSchemaOutput, InitialInputSchema, Schema, AnySchema, InferSchemaInput } from '@orpc/contract';
2
2
  import { Context, ORPCErrorConstructorMap, DecoratedProcedure, AnyORPCError, MergedContext, ImplementedProcedure } from '@orpc/server';
3
3
  import { Effect } from 'effect';
4
- import { WithEffectContext, HandlerGen, InferYieldError } from '../index.js';
4
+ import { InferEffectServices, HandlerGen, InferYieldError } from '../index.js';
5
5
 
6
6
  declare module '@orpc/server' {
7
7
  interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
8
- effect<TYield extends Effect.Effect<any, any, TInitialContext extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<TInitialContext, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
8
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<TInitialContext>>, TReturn>(handler: HandlerGen<TInitialContext, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
9
9
  }
10
10
  interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
11
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
11
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
12
12
  }
13
13
  interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
14
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
14
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<Exclude<TReturn, AnyORPCError>>, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
15
15
  }
16
16
  interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
17
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
17
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
18
18
  }
19
19
  interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
20
- effect<TYield extends Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
20
+ effect<TYield extends Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, TReturn extends InferSchemaInput<TOutputSchema> | AnyORPCError>(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, TYield, TReturn, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, Extract<TReturn | InferYieldError<TYield>, AnyORPCError>>;
21
21
  }
22
22
  interface ProcedureImplementer<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
23
- effect(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, Effect.Effect<any, any, MergedContext<TInitialContext, TInjectedContext> extends WithEffectContext<infer S> ? S : never>, AnyORPCError | InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ImplementedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
23
+ effect(handler: HandlerGen<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, Effect.Effect<any, any, InferEffectServices<MergedContext<TInitialContext, TInjectedContext>>>, AnyORPCError | InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ImplementedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
24
24
  }
25
25
  }
package/dist/index.d.mts CHANGED
@@ -1,8 +1,24 @@
1
- export { H as HandlerGen, I as InferYieldError, W as WithEffectContext, h as handlerGen } from './shared/experimental-effect.BupPDCRJ.mjs';
2
- import { AnySchema, Schema as Schema$1 } from '@orpc/contract';
3
- import { JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
4
- import { AnyORPCError, ORPCError, ORPCErrorCode } from '@orpc/server';
1
+ import { AnyNestedClient, Client, ClientRest } from '@orpc/client';
5
2
  import { Effect, Schema } from 'effect';
3
+ import { I as InferEffectServices } from './shared/experimental-effect.DTnbcz7i.mjs';
4
+ export { H as HandlerGen, a as InferYieldError, W as WithEffectContext, h as handlerGen } from './shared/experimental-effect.DTnbcz7i.mjs';
5
+ import { AnySchema, ErrorMap, Schema as Schema$1 } from '@orpc/contract';
6
+ import { JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
7
+ import { AnyORPCError, ORPCError, ORPCErrorCode, Context, ORPCErrorConstructorMap, MiddlewareOptions, MiddlewareNextOptions, MiddlewareResult, MiddlewareDone, Middleware } from '@orpc/server';
8
+ import { MaybeOptionalOptions } from '@orpc/shared';
9
+
10
+ type EffectClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Effect.Effect<UOutput, UError> : {
11
+ [K in keyof T]: T[K] extends AnyNestedClient ? EffectClient<T[K]> : never;
12
+ };
13
+ /**
14
+ * Creates a client whose procedures return lazy effects instead of promises,
15
+ * so you can `yield*` calls inside Effect generators. Errors are captured in
16
+ * the error channel with their original types preserved, and interrupting an
17
+ * effect aborts the underlying call.
18
+ *
19
+ * @see {@link https://orpc.dev/docs/integrations/effect#client-calls | Effect Integration - Client Calls}
20
+ */
21
+ declare function createEffectClient<T extends AnyNestedClient>(client: T): EffectClient<T>;
6
22
 
7
23
  /**
8
24
  * A JSON Schema converter for Effect Schema, built on top of
@@ -19,7 +35,9 @@ declare class EffectSchemaToJsonSchemaConverter implements JsonSchemaConverter {
19
35
 
20
36
  /**
21
37
  * Recovers from `ORPCError` failures in the error channel of an effect.
22
- * Other failures re-fail with their original cause.
38
+ * Other failures re-fail with their original cause. Because failure types
39
+ * like `Error` can also hold `ORPCError` instances at runtime, the handler
40
+ * can also receive such hidden errors with unknown code and data.
23
41
  *
24
42
  * Supports both data-first `catchORPCError(effect, handler)` and data-last
25
43
  * `effect.pipe(catchORPCError(handler))` styles.
@@ -36,13 +54,15 @@ declare class EffectSchemaToJsonSchemaConverter implements JsonSchemaConverter {
36
54
  * @see {@link https://orpc.dev/docs/integrations/effect#catching-orpcerrors | Effect Integration - Catching ORPCErrors}
37
55
  */
38
56
  declare const catchORPCError: {
39
- <E, A2, E2, R2>(f: (error: Extract<E, AnyORPCError>) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
40
- <A, E, R, A2, E2, R2>(self: Effect.Effect<A, E, R>, f: (error: Extract<E, AnyORPCError>) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
57
+ <E, A2, E2, R2>(f: (error: E extends AnyORPCError ? E : AnyORPCError extends E ? ORPCError<ORPCErrorCode, unknown> : never) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
58
+ <A, E, R, A2, E2, R2>(self: Effect.Effect<A, E, R>, f: (error: E extends AnyORPCError ? E : AnyORPCError extends E ? ORPCError<ORPCErrorCode, unknown> : never) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
41
59
  };
42
60
  /**
43
61
  * Recovers from `ORPCError` failures with a matching code in the error channel of an effect.
44
62
  * Other failures re-fail with their original cause. The `code` argument is
45
- * suggested and restricted to the codes present in the error channel.
63
+ * suggested and restricted to the codes present in the error channel, and is
64
+ * unrestricted when the channel contains failure types like `Error` that can
65
+ * hold hidden `ORPCError` instances, whose data is unknown.
46
66
  *
47
67
  * Supports both data-first `catchORPCErrorCode(effect, code, handler)` and
48
68
  * data-last `effect.pipe(catchORPCErrorCode(code, handler))` styles.
@@ -51,7 +71,7 @@ declare const catchORPCError: {
51
71
  * ```ts
52
72
  * declare const program: Effect.Effect<
53
73
  * string,
54
- * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined> | TypeError
74
+ * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined>
55
75
  * >
56
76
  *
57
77
  * const recovered = program.pipe(
@@ -62,14 +82,15 @@ declare const catchORPCError: {
62
82
  * @see {@link https://orpc.dev/docs/integrations/effect#catching-orpcerrors | Effect Integration - Catching ORPCErrors}
63
83
  */
64
84
  declare const catchORPCErrorCode: {
65
- <const TCode extends E extends ORPCError<infer TCode, any> ? TCode : never, E, A2, E2, R2>(code: TCode, f: (error: Extract<E, ORPCError<TCode, any>>) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
66
- <A, E, R, const TCode extends E extends ORPCError<infer TCode, any> ? TCode : never, A2, E2, R2>(self: Effect.Effect<A, E, R>, code: TCode, f: (error: Extract<E, ORPCError<TCode, any>>) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
85
+ <const TCode extends E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never, E, A2, E2, R2>(code: TCode, f: (error: E extends AnyORPCError ? Extract<E, ORPCError<TCode, any>> : AnyORPCError extends E ? ORPCError<TCode, unknown> : never) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
86
+ <A, E, R, const TCode extends E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never, A2, E2, R2>(self: Effect.Effect<A, E, R>, code: TCode, f: (error: E extends AnyORPCError ? Extract<E, ORPCError<TCode, any>> : AnyORPCError extends E ? ORPCError<TCode, unknown> : never) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
67
87
  };
68
88
  /**
69
89
  * Recovers from `ORPCError` failures using a map of codes to handlers in the
70
90
  * error channel of an effect. Other failures re-fail with their original
71
91
  * cause. The keys are suggested and restricted to the codes present in the
72
- * error channel.
92
+ * error channel, and are unrestricted when the channel contains failure types
93
+ * like `Error` that can hold hidden `ORPCError` instances, whose data is unknown.
73
94
  *
74
95
  * Supports both data-first `catchORPCErrorCodes(effect, cases)` and data-last
75
96
  * `effect.pipe(catchORPCErrorCodes(cases))` styles.
@@ -78,7 +99,7 @@ declare const catchORPCErrorCode: {
78
99
  * ```ts
79
100
  * declare const program: Effect.Effect<
80
101
  * string,
81
- * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined> | TypeError
102
+ * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined>
82
103
  * >
83
104
  *
84
105
  * const recovered = program.pipe(
@@ -93,10 +114,10 @@ declare const catchORPCErrorCode: {
93
114
  */
94
115
  declare const catchORPCErrorCodes: {
95
116
  <E, Cases extends {
96
- [K in Extract<E, AnyORPCError>['code']]?: (error: Extract<E, ORPCError<K, any>>) => Effect.Effect<any, any, any>;
97
- } & (unknown extends E ? object : {
98
- [K in Exclude<keyof Cases, Extract<E, AnyORPCError>['code']>]: never;
99
- })>(cases: Cases): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | {
117
+ [K in E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never]?: string extends K ? (error: never) => Effect.Effect<any, any, any> : K extends infer C extends ORPCErrorCode ? (error: E extends AnyORPCError ? Extract<E, ORPCError<C, any>> : AnyORPCError extends E ? ORPCError<C, unknown> : never) => Effect.Effect<any, any, any> : never;
118
+ } & {
119
+ [K in Exclude<keyof Cases, E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never>]: never;
120
+ }>(cases: Cases): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | {
100
121
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<infer A2, any, any> ? A2 : never;
101
122
  }[keyof Cases], Exclude<E, ORPCError<keyof Cases & ORPCErrorCode, any>> | {
102
123
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, infer E2, any> ? E2 : never;
@@ -104,10 +125,10 @@ declare const catchORPCErrorCodes: {
104
125
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, any, infer R2> ? R2 : never;
105
126
  }[keyof Cases]>;
106
127
  <A, E, R, Cases extends {
107
- [K in Extract<E, AnyORPCError>['code']]?: (error: Extract<E, ORPCError<K, any>>) => Effect.Effect<any, any, any>;
108
- } & (unknown extends E ? object : {
109
- [K in Exclude<keyof Cases, Extract<E, AnyORPCError>['code']>]: never;
110
- })>(self: Effect.Effect<A, E, R>, cases: Cases): Effect.Effect<A | {
128
+ [K in E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never]?: string extends K ? (error: never) => Effect.Effect<any, any, any> : K extends infer C extends ORPCErrorCode ? (error: E extends AnyORPCError ? Extract<E, ORPCError<C, any>> : AnyORPCError extends E ? ORPCError<C, unknown> : never) => Effect.Effect<any, any, any> : never;
129
+ } & {
130
+ [K in Exclude<keyof Cases, E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never>]: never;
131
+ }>(self: Effect.Effect<A, E, R>, cases: Cases): Effect.Effect<A | {
111
132
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<infer A2, any, any> ? A2 : never;
112
133
  }[keyof Cases], Exclude<E, ORPCError<keyof Cases & ORPCErrorCode, any>> | {
113
134
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, infer E2, any> ? E2 : never;
@@ -116,6 +137,26 @@ declare const catchORPCErrorCodes: {
116
137
  }[keyof Cases]>;
117
138
  };
118
139
 
140
+ interface MiddlewareGenNext<TOutput> {
141
+ <U extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<U>>): Effect.Effect<Awaited<MiddlewareResult<U, TOutput>>, unknown>;
142
+ }
143
+ interface MiddlewareGenOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Omit<MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap>, 'next'> {
144
+ next: MiddlewareGenNext<TOutput>;
145
+ }
146
+ interface MiddlewareGen<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TYield extends Effect.Effect<any, any, InferEffectServices<TInContext>>, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
147
+ (opts: MiddlewareGenOptions<TInContext, TOutput, TErrorConstructorMap>, input: TInput, done: MiddlewareDone<TOutput>): Generator<TYield, MiddlewareResult<TOutContext, TOutput>, never>;
148
+ }
149
+ type AnyMiddlewareGen = MiddlewareGen<any, any, any, any, any, any>;
150
+ /**
151
+ * Creates an oRPC middleware from an Effect generator function.
152
+ * Inside the generator you can yield Effect operations and `yield* next()`
153
+ * to continue the chain, and `middlewareGen` handles the execution and
154
+ * error handling for you.
155
+ *
156
+ * @see {@link https://orpc.dev/docs/integrations/effect#effectful-middleware | Effect Integration - Effectful Middleware}
157
+ */
158
+ declare function middlewareGen<TInContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap, TYield extends Effect.Effect<any, any, InferEffectServices<TInContext>>, TOutContext extends Context = object>(middleware: MiddlewareGen<TInContext, TOutContext, TInput, TOutput, TYield, ORPCErrorConstructorMap<TErrorMap>>): Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>;
159
+
119
160
  interface RunPromiseOptions {
120
161
  signal?: undefined | AbortSignal;
121
162
  }
@@ -126,5 +167,5 @@ declare function runPromise<T>(effect: Effect.Effect<T, unknown>, options?: RunP
126
167
 
127
168
  declare function toStandardSchema<S extends Schema.ConstraintDecoder<any>>(schema: S): Schema$1<S['Encoded'], S['Type']> & S;
128
169
 
129
- export { EffectSchemaToJsonSchemaConverter, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes, runPromise, toStandardSchema };
130
- export type { RunPromiseOptions };
170
+ export { EffectSchemaToJsonSchemaConverter, InferEffectServices, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes, createEffectClient, middlewareGen, runPromise, toStandardSchema };
171
+ export type { AnyMiddlewareGen, EffectClient, MiddlewareGen, MiddlewareGenNext, MiddlewareGenOptions, RunPromiseOptions };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,24 @@
1
- export { H as HandlerGen, I as InferYieldError, W as WithEffectContext, h as handlerGen } from './shared/experimental-effect.BupPDCRJ.js';
2
- import { AnySchema, Schema as Schema$1 } from '@orpc/contract';
3
- import { JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
4
- import { AnyORPCError, ORPCError, ORPCErrorCode } from '@orpc/server';
1
+ import { AnyNestedClient, Client, ClientRest } from '@orpc/client';
5
2
  import { Effect, Schema } from 'effect';
3
+ import { I as InferEffectServices } from './shared/experimental-effect.DTnbcz7i.js';
4
+ export { H as HandlerGen, a as InferYieldError, W as WithEffectContext, h as handlerGen } from './shared/experimental-effect.DTnbcz7i.js';
5
+ import { AnySchema, ErrorMap, Schema as Schema$1 } from '@orpc/contract';
6
+ import { JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
7
+ import { AnyORPCError, ORPCError, ORPCErrorCode, Context, ORPCErrorConstructorMap, MiddlewareOptions, MiddlewareNextOptions, MiddlewareResult, MiddlewareDone, Middleware } from '@orpc/server';
8
+ import { MaybeOptionalOptions } from '@orpc/shared';
9
+
10
+ type EffectClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Effect.Effect<UOutput, UError> : {
11
+ [K in keyof T]: T[K] extends AnyNestedClient ? EffectClient<T[K]> : never;
12
+ };
13
+ /**
14
+ * Creates a client whose procedures return lazy effects instead of promises,
15
+ * so you can `yield*` calls inside Effect generators. Errors are captured in
16
+ * the error channel with their original types preserved, and interrupting an
17
+ * effect aborts the underlying call.
18
+ *
19
+ * @see {@link https://orpc.dev/docs/integrations/effect#client-calls | Effect Integration - Client Calls}
20
+ */
21
+ declare function createEffectClient<T extends AnyNestedClient>(client: T): EffectClient<T>;
6
22
 
7
23
  /**
8
24
  * A JSON Schema converter for Effect Schema, built on top of
@@ -19,7 +35,9 @@ declare class EffectSchemaToJsonSchemaConverter implements JsonSchemaConverter {
19
35
 
20
36
  /**
21
37
  * Recovers from `ORPCError` failures in the error channel of an effect.
22
- * Other failures re-fail with their original cause.
38
+ * Other failures re-fail with their original cause. Because failure types
39
+ * like `Error` can also hold `ORPCError` instances at runtime, the handler
40
+ * can also receive such hidden errors with unknown code and data.
23
41
  *
24
42
  * Supports both data-first `catchORPCError(effect, handler)` and data-last
25
43
  * `effect.pipe(catchORPCError(handler))` styles.
@@ -36,13 +54,15 @@ declare class EffectSchemaToJsonSchemaConverter implements JsonSchemaConverter {
36
54
  * @see {@link https://orpc.dev/docs/integrations/effect#catching-orpcerrors | Effect Integration - Catching ORPCErrors}
37
55
  */
38
56
  declare const catchORPCError: {
39
- <E, A2, E2, R2>(f: (error: Extract<E, AnyORPCError>) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
40
- <A, E, R, A2, E2, R2>(self: Effect.Effect<A, E, R>, f: (error: Extract<E, AnyORPCError>) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
57
+ <E, A2, E2, R2>(f: (error: E extends AnyORPCError ? E : AnyORPCError extends E ? ORPCError<ORPCErrorCode, unknown> : never) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
58
+ <A, E, R, A2, E2, R2>(self: Effect.Effect<A, E, R>, f: (error: E extends AnyORPCError ? E : AnyORPCError extends E ? ORPCError<ORPCErrorCode, unknown> : never) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, AnyORPCError>, R | R2>;
41
59
  };
42
60
  /**
43
61
  * Recovers from `ORPCError` failures with a matching code in the error channel of an effect.
44
62
  * Other failures re-fail with their original cause. The `code` argument is
45
- * suggested and restricted to the codes present in the error channel.
63
+ * suggested and restricted to the codes present in the error channel, and is
64
+ * unrestricted when the channel contains failure types like `Error` that can
65
+ * hold hidden `ORPCError` instances, whose data is unknown.
46
66
  *
47
67
  * Supports both data-first `catchORPCErrorCode(effect, code, handler)` and
48
68
  * data-last `effect.pipe(catchORPCErrorCode(code, handler))` styles.
@@ -51,7 +71,7 @@ declare const catchORPCError: {
51
71
  * ```ts
52
72
  * declare const program: Effect.Effect<
53
73
  * string,
54
- * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined> | TypeError
74
+ * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined>
55
75
  * >
56
76
  *
57
77
  * const recovered = program.pipe(
@@ -62,14 +82,15 @@ declare const catchORPCError: {
62
82
  * @see {@link https://orpc.dev/docs/integrations/effect#catching-orpcerrors | Effect Integration - Catching ORPCErrors}
63
83
  */
64
84
  declare const catchORPCErrorCode: {
65
- <const TCode extends E extends ORPCError<infer TCode, any> ? TCode : never, E, A2, E2, R2>(code: TCode, f: (error: Extract<E, ORPCError<TCode, any>>) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
66
- <A, E, R, const TCode extends E extends ORPCError<infer TCode, any> ? TCode : never, A2, E2, R2>(self: Effect.Effect<A, E, R>, code: TCode, f: (error: Extract<E, ORPCError<TCode, any>>) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
85
+ <const TCode extends E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never, E, A2, E2, R2>(code: TCode, f: (error: E extends AnyORPCError ? Extract<E, ORPCError<TCode, any>> : AnyORPCError extends E ? ORPCError<TCode, unknown> : never) => Effect.Effect<A2, E2, R2>): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
86
+ <A, E, R, const TCode extends E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never, A2, E2, R2>(self: Effect.Effect<A, E, R>, code: TCode, f: (error: E extends AnyORPCError ? Extract<E, ORPCError<TCode, any>> : AnyORPCError extends E ? ORPCError<TCode, unknown> : never) => Effect.Effect<A2, E2, R2>): Effect.Effect<A | A2, E2 | Exclude<E, ORPCError<TCode, any>>, R | R2>;
67
87
  };
68
88
  /**
69
89
  * Recovers from `ORPCError` failures using a map of codes to handlers in the
70
90
  * error channel of an effect. Other failures re-fail with their original
71
91
  * cause. The keys are suggested and restricted to the codes present in the
72
- * error channel.
92
+ * error channel, and are unrestricted when the channel contains failure types
93
+ * like `Error` that can hold hidden `ORPCError` instances, whose data is unknown.
73
94
  *
74
95
  * Supports both data-first `catchORPCErrorCodes(effect, cases)` and data-last
75
96
  * `effect.pipe(catchORPCErrorCodes(cases))` styles.
@@ -78,7 +99,7 @@ declare const catchORPCErrorCode: {
78
99
  * ```ts
79
100
  * declare const program: Effect.Effect<
80
101
  * string,
81
- * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined> | TypeError
102
+ * ORPCError<'NOT_FOUND', { id: string }> | ORPCError<'CONFLICT', undefined>
82
103
  * >
83
104
  *
84
105
  * const recovered = program.pipe(
@@ -93,10 +114,10 @@ declare const catchORPCErrorCode: {
93
114
  */
94
115
  declare const catchORPCErrorCodes: {
95
116
  <E, Cases extends {
96
- [K in Extract<E, AnyORPCError>['code']]?: (error: Extract<E, ORPCError<K, any>>) => Effect.Effect<any, any, any>;
97
- } & (unknown extends E ? object : {
98
- [K in Exclude<keyof Cases, Extract<E, AnyORPCError>['code']>]: never;
99
- })>(cases: Cases): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | {
117
+ [K in E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never]?: string extends K ? (error: never) => Effect.Effect<any, any, any> : K extends infer C extends ORPCErrorCode ? (error: E extends AnyORPCError ? Extract<E, ORPCError<C, any>> : AnyORPCError extends E ? ORPCError<C, unknown> : never) => Effect.Effect<any, any, any> : never;
118
+ } & {
119
+ [K in Exclude<keyof Cases, E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never>]: never;
120
+ }>(cases: Cases): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | {
100
121
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<infer A2, any, any> ? A2 : never;
101
122
  }[keyof Cases], Exclude<E, ORPCError<keyof Cases & ORPCErrorCode, any>> | {
102
123
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, infer E2, any> ? E2 : never;
@@ -104,10 +125,10 @@ declare const catchORPCErrorCodes: {
104
125
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, any, infer R2> ? R2 : never;
105
126
  }[keyof Cases]>;
106
127
  <A, E, R, Cases extends {
107
- [K in Extract<E, AnyORPCError>['code']]?: (error: Extract<E, ORPCError<K, any>>) => Effect.Effect<any, any, any>;
108
- } & (unknown extends E ? object : {
109
- [K in Exclude<keyof Cases, Extract<E, AnyORPCError>['code']>]: never;
110
- })>(self: Effect.Effect<A, E, R>, cases: Cases): Effect.Effect<A | {
128
+ [K in E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never]?: string extends K ? (error: never) => Effect.Effect<any, any, any> : K extends infer C extends ORPCErrorCode ? (error: E extends AnyORPCError ? Extract<E, ORPCError<C, any>> : AnyORPCError extends E ? ORPCError<C, unknown> : never) => Effect.Effect<any, any, any> : never;
129
+ } & {
130
+ [K in Exclude<keyof Cases, E extends ORPCError<infer TCode, any> ? TCode : AnyORPCError extends E ? ORPCErrorCode : never>]: never;
131
+ }>(self: Effect.Effect<A, E, R>, cases: Cases): Effect.Effect<A | {
111
132
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<infer A2, any, any> ? A2 : never;
112
133
  }[keyof Cases], Exclude<E, ORPCError<keyof Cases & ORPCErrorCode, any>> | {
113
134
  [K in keyof Cases]: Cases[K] extends (...args: any[]) => Effect.Effect<any, infer E2, any> ? E2 : never;
@@ -116,6 +137,26 @@ declare const catchORPCErrorCodes: {
116
137
  }[keyof Cases]>;
117
138
  };
118
139
 
140
+ interface MiddlewareGenNext<TOutput> {
141
+ <U extends Context = object>(...rest: MaybeOptionalOptions<MiddlewareNextOptions<U>>): Effect.Effect<Awaited<MiddlewareResult<U, TOutput>>, unknown>;
142
+ }
143
+ interface MiddlewareGenOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Omit<MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap>, 'next'> {
144
+ next: MiddlewareGenNext<TOutput>;
145
+ }
146
+ interface MiddlewareGen<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TYield extends Effect.Effect<any, any, InferEffectServices<TInContext>>, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
147
+ (opts: MiddlewareGenOptions<TInContext, TOutput, TErrorConstructorMap>, input: TInput, done: MiddlewareDone<TOutput>): Generator<TYield, MiddlewareResult<TOutContext, TOutput>, never>;
148
+ }
149
+ type AnyMiddlewareGen = MiddlewareGen<any, any, any, any, any, any>;
150
+ /**
151
+ * Creates an oRPC middleware from an Effect generator function.
152
+ * Inside the generator you can yield Effect operations and `yield* next()`
153
+ * to continue the chain, and `middlewareGen` handles the execution and
154
+ * error handling for you.
155
+ *
156
+ * @see {@link https://orpc.dev/docs/integrations/effect#effectful-middleware | Effect Integration - Effectful Middleware}
157
+ */
158
+ declare function middlewareGen<TInContext extends Context, TInput, TOutput, TErrorMap extends ErrorMap, TYield extends Effect.Effect<any, any, InferEffectServices<TInContext>>, TOutContext extends Context = object>(middleware: MiddlewareGen<TInContext, TOutContext, TInput, TOutput, TYield, ORPCErrorConstructorMap<TErrorMap>>): Middleware<TInContext, TOutContext, TInput, TOutput, TErrorMap>;
159
+
119
160
  interface RunPromiseOptions {
120
161
  signal?: undefined | AbortSignal;
121
162
  }
@@ -126,5 +167,5 @@ declare function runPromise<T>(effect: Effect.Effect<T, unknown>, options?: RunP
126
167
 
127
168
  declare function toStandardSchema<S extends Schema.ConstraintDecoder<any>>(schema: S): Schema$1<S['Encoded'], S['Type']> & S;
128
169
 
129
- export { EffectSchemaToJsonSchemaConverter, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes, runPromise, toStandardSchema };
130
- export type { RunPromiseOptions };
170
+ export { EffectSchemaToJsonSchemaConverter, InferEffectServices, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes, createEffectClient, middlewareGen, runPromise, toStandardSchema };
171
+ export type { AnyMiddlewareGen, EffectClient, MiddlewareGen, MiddlewareGenNext, MiddlewareGenOptions, RunPromiseOptions };
package/dist/index.mjs CHANGED
@@ -1,11 +1,45 @@
1
+ import { RECURSIVE_CLIENT_UNWRAP_KEYS, resolveClientRest } from '@orpc/client';
2
+ import { isTypescriptObject, anyAbortSignal, getOwn } from '@orpc/shared';
3
+ import { Effect, Schema, Function, Context } from 'effect';
1
4
  import { StandardJsonSchemaConverter } from '@orpc/json-schema';
2
- import { Schema, Function, Effect } from 'effect';
3
5
  import { ORPCError } from '@orpc/server';
4
- import { getOwn } from '@orpc/shared';
5
- export { h as handlerGen, r as runPromise } from './shared/experimental-effect.C9oJcd5q.mjs';
6
+ import { r as runPromise } from './shared/experimental-effect.C9oJcd5q.mjs';
7
+ export { h as handlerGen } from './shared/experimental-effect.C9oJcd5q.mjs';
6
8
  export { t as toStandardSchema } from './shared/experimental-effect.YQKompVf.mjs';
7
9
  import '@orpc/contract';
8
10
 
11
+ function callAsEffect(client, ...rest) {
12
+ const [input, options] = resolveClientRest(rest);
13
+ return Effect.tryPromise({
14
+ try: (signal) => client(input, {
15
+ ...options,
16
+ signal: anyAbortSignal([options.signal, signal])
17
+ }),
18
+ catch: (error) => error
19
+ });
20
+ }
21
+ function createEffectClient(client) {
22
+ const cache = /* @__PURE__ */ new Map();
23
+ const proxy = new Proxy((...rest) => callAsEffect(client, ...rest), {
24
+ get(target, prop) {
25
+ if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
26
+ return Reflect.get(target, prop);
27
+ }
28
+ let effectClient = cache.get(prop);
29
+ if (effectClient === void 0) {
30
+ const value = client[prop];
31
+ if (!isTypescriptObject(value)) {
32
+ return value;
33
+ }
34
+ effectClient = createEffectClient(value);
35
+ cache.set(prop, effectClient);
36
+ }
37
+ return effectClient;
38
+ }
39
+ });
40
+ return proxy;
41
+ }
42
+
9
43
  class EffectSchemaToJsonSchemaConverter {
10
44
  converter = new StandardJsonSchemaConverter();
11
45
  condition(schema, _direction) {
@@ -40,4 +74,24 @@ const catchORPCErrorCodes = Function.dual(
40
74
  )
41
75
  );
42
76
 
43
- export { EffectSchemaToJsonSchemaConverter, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes };
77
+ function middlewareGen(middleware) {
78
+ const mid = (opts, input, done) => {
79
+ const next = (...rest) => Effect.tryPromise({
80
+ try: async () => opts.next(...rest),
81
+ catch: (error) => error
82
+ });
83
+ let ef = Effect.gen(() => middleware({ ...opts, next }, input, done));
84
+ if (Context.isContext(opts.context["effect/context"])) {
85
+ ef = ef.pipe(Effect.provide(opts.context["effect/context"]));
86
+ }
87
+ if (typeof opts.context["effect/wrap"] === "function") {
88
+ const intercept = opts.context["effect/wrap"];
89
+ ef = intercept(ef, opts);
90
+ }
91
+ return runPromise(ef, { signal: opts.signal });
92
+ };
93
+ Object.defineProperty(mid, "name", { value: middleware.name });
94
+ return mid;
95
+ }
96
+
97
+ export { EffectSchemaToJsonSchemaConverter, catchORPCError, catchORPCErrorCode, catchORPCErrorCodes, createEffectClient, middlewareGen, runPromise };
@@ -1,5 +1,5 @@
1
- import { AnyProcedure, Context as Context$1, ORPCErrorConstructorMap, ProcedureHandlerOptions, ProcedureHandler, AnyORPCError } from '@orpc/server';
2
- import { Context, Effect } from 'effect';
1
+ import { Context, AnyProcedure, ORPCErrorConstructorMap, ProcedureHandlerOptions, ProcedureHandler, AnyORPCError } from '@orpc/server';
2
+ import { Context as Context$1, Effect } from 'effect';
3
3
 
4
4
  /**
5
5
  * A context shape that provides Effect services to effectful handlers
@@ -25,7 +25,7 @@ interface WithEffectContext<Services> {
25
25
  * }
26
26
  * ```
27
27
  */
28
- ['effect/context']: Context.Context<Services>;
28
+ ['effect/context']: Context$1.Context<Services>;
29
29
  /**
30
30
  * An optional hook to wrap any effect before it is executed within this oRPC context.
31
31
  * Useful for adding observability, tracing, or error handling.
@@ -53,9 +53,15 @@ interface WithEffectContext<Services> {
53
53
  signal?: undefined | AbortSignal;
54
54
  }) => Effect.Effect<A, E>;
55
55
  }
56
+ /**
57
+ * Infers the Effect services available in an oRPC context that extends `WithEffectContext`.
58
+ *
59
+ * @see {@link https://orpc.dev/docs/integrations/effect#effect-services | Effect Integration - Effect Services}
60
+ */
61
+ type InferEffectServices<T extends Context> = T extends WithEffectContext<infer Services> ? Services : never;
56
62
 
57
63
  type InferYieldError<Eff> = [Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never;
58
- interface HandlerGen<TCurrentContext extends Context$1, TInput, TYield extends Effect.Effect<any, any, TCurrentContext extends WithEffectContext<infer S> ? S : never>, TReturn, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
64
+ interface HandlerGen<TCurrentContext extends Context, TInput, TYield extends Effect.Effect<any, any, InferEffectServices<TCurrentContext>>, TReturn, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
59
65
  (opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Generator<TYield, TReturn, never>;
60
66
  }
61
67
  /**
@@ -65,7 +71,7 @@ interface HandlerGen<TCurrentContext extends Context$1, TInput, TYield extends E
65
71
  *
66
72
  * @see {@link https://orpc.dev/docs/integrations/effect#effectful-handlers | Effect Integration - Effectful Handlers}
67
73
  */
68
- declare function handlerGen<TCurrentContext extends Context$1, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TYield extends Effect.Effect<any, any, TCurrentContext extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<TCurrentContext, TInput, TYield, TReturn, TErrorConstructorMap>): ProcedureHandler<TCurrentContext, TInput, TReturn | Extract<InferYieldError<TYield>, AnyORPCError>, TErrorConstructorMap>;
74
+ declare function handlerGen<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TYield extends Effect.Effect<any, any, InferEffectServices<TCurrentContext>>, TReturn>(handler: HandlerGen<TCurrentContext, TInput, TYield, TReturn, TErrorConstructorMap>): ProcedureHandler<TCurrentContext, TInput, TReturn | Extract<InferYieldError<TYield>, AnyORPCError>, TErrorConstructorMap>;
69
75
 
70
76
  export { handlerGen as h };
71
- export type { HandlerGen as H, InferYieldError as I, WithEffectContext as W };
77
+ export type { HandlerGen as H, InferEffectServices as I, WithEffectContext as W, InferYieldError as a };
@@ -1,5 +1,5 @@
1
- import { AnyProcedure, Context as Context$1, ORPCErrorConstructorMap, ProcedureHandlerOptions, ProcedureHandler, AnyORPCError } from '@orpc/server';
2
- import { Context, Effect } from 'effect';
1
+ import { Context, AnyProcedure, ORPCErrorConstructorMap, ProcedureHandlerOptions, ProcedureHandler, AnyORPCError } from '@orpc/server';
2
+ import { Context as Context$1, Effect } from 'effect';
3
3
 
4
4
  /**
5
5
  * A context shape that provides Effect services to effectful handlers
@@ -25,7 +25,7 @@ interface WithEffectContext<Services> {
25
25
  * }
26
26
  * ```
27
27
  */
28
- ['effect/context']: Context.Context<Services>;
28
+ ['effect/context']: Context$1.Context<Services>;
29
29
  /**
30
30
  * An optional hook to wrap any effect before it is executed within this oRPC context.
31
31
  * Useful for adding observability, tracing, or error handling.
@@ -53,9 +53,15 @@ interface WithEffectContext<Services> {
53
53
  signal?: undefined | AbortSignal;
54
54
  }) => Effect.Effect<A, E>;
55
55
  }
56
+ /**
57
+ * Infers the Effect services available in an oRPC context that extends `WithEffectContext`.
58
+ *
59
+ * @see {@link https://orpc.dev/docs/integrations/effect#effect-services | Effect Integration - Effect Services}
60
+ */
61
+ type InferEffectServices<T extends Context> = T extends WithEffectContext<infer Services> ? Services : never;
56
62
 
57
63
  type InferYieldError<Eff> = [Eff] extends [never] ? never : [Eff] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never;
58
- interface HandlerGen<TCurrentContext extends Context$1, TInput, TYield extends Effect.Effect<any, any, TCurrentContext extends WithEffectContext<infer S> ? S : never>, TReturn, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
64
+ interface HandlerGen<TCurrentContext extends Context, TInput, TYield extends Effect.Effect<any, any, InferEffectServices<TCurrentContext>>, TReturn, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
59
65
  (opts: ProcedureHandlerOptions<TCurrentContext, TInput, TErrorConstructorMap>, input: TInput): Generator<TYield, TReturn, never>;
60
66
  }
61
67
  /**
@@ -65,7 +71,7 @@ interface HandlerGen<TCurrentContext extends Context$1, TInput, TYield extends E
65
71
  *
66
72
  * @see {@link https://orpc.dev/docs/integrations/effect#effectful-handlers | Effect Integration - Effectful Handlers}
67
73
  */
68
- declare function handlerGen<TCurrentContext extends Context$1, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TYield extends Effect.Effect<any, any, TCurrentContext extends WithEffectContext<infer S> ? S : never>, TReturn>(handler: HandlerGen<TCurrentContext, TInput, TYield, TReturn, TErrorConstructorMap>): ProcedureHandler<TCurrentContext, TInput, TReturn | Extract<InferYieldError<TYield>, AnyORPCError>, TErrorConstructorMap>;
74
+ declare function handlerGen<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TYield extends Effect.Effect<any, any, InferEffectServices<TCurrentContext>>, TReturn>(handler: HandlerGen<TCurrentContext, TInput, TYield, TReturn, TErrorConstructorMap>): ProcedureHandler<TCurrentContext, TInput, TReturn | Extract<InferYieldError<TYield>, AnyORPCError>, TErrorConstructorMap>;
69
75
 
70
76
  export { handlerGen as h };
71
- export type { HandlerGen as H, InferYieldError as I, WithEffectContext as W };
77
+ export type { HandlerGen as H, InferEffectServices as I, WithEffectContext as W, InferYieldError as a };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/experimental-effect",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.31",
4
+ "version": "2.0.0-beta.33",
5
5
  "description": "Effect integration for oRPC: build typesafe procedures with Effect",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -51,16 +51,16 @@
51
51
  "effect": ">=4.0.0-beta.90"
52
52
  },
53
53
  "dependencies": {
54
- "@orpc/contract": "2.0.0-beta.31",
55
- "@orpc/server": "2.0.0-beta.31",
56
- "@orpc/json-schema": "2.0.0-beta.31",
57
- "@orpc/shared": "2.0.0-beta.31"
54
+ "@orpc/client": "2.0.0-beta.33",
55
+ "@orpc/contract": "2.0.0-beta.33",
56
+ "@orpc/json-schema": "2.0.0-beta.33",
57
+ "@orpc/server": "2.0.0-beta.33",
58
+ "@orpc/shared": "2.0.0-beta.33"
58
59
  },
59
60
  "devDependencies": {
60
- "effect": "4.0.0-rc.109"
61
+ "effect": "4.0.0-rc.112"
61
62
  },
62
63
  "scripts": {
63
- "build": "unbuild",
64
64
  "type:check": "tsc -b"
65
65
  }
66
66
  }