File size: 25,291 Bytes
31e8457
e391660
 
 
 
 
 
 
 
 
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
 
 
e391660
 
 
 
 
 
31e8457
 
e391660
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e391660
 
 
 
 
 
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
e391660
 
 
 
 
 
31e8457
 
e391660
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
31e8457
e391660
31e8457
 
 
e391660
 
 
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
 
 
 
 
 
 
 
e391660
31e8457
e391660
 
 
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e391660
31e8457
 
 
 
 
 
 
 
 
 
 
e391660
 
 
 
 
 
 
 
31e8457
 
 
 
 
 
 
 
 
e391660
 
31e8457
 
 
 
e391660
 
 
31e8457
 
 
 
 
 
 
 
e391660
 
 
 
31e8457
 
 
 
e391660
 
 
 
31e8457
 
 
 
 
 
 
 
e391660
 
 
 
 
 
 
 
31e8457
e391660
31e8457
 
 
 
e391660
 
 
 
 
 
 
 
31e8457
 
 
 
 
 
 
 
 
e391660
 
 
 
31e8457
 
 
 
e391660
 
 
31e8457
 
 
 
e391660
 
 
 
 
 
 
 
31e8457
 
 
 
 
 
 
e391660
 
 
 
31e8457
 
 
 
e391660
 
 
 
31e8457
 
 
 
e391660
 
31e8457
e391660
31e8457
 
 
 
e391660
31e8457
e391660
31e8457
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/**
 * Defines schema-backed contracts for individual RPC procedures.
 *
 * An `Rpc` describes one remote procedure by recording its tag, payload schema,
 * success schema, error schema, defect schema, middleware, and annotations.
 * Clients and servers read the same declaration, so the procedure contract is
 * independent of the transport used to call it. This module includes
 * constructors, type helpers for deriving client and handler shapes, exit
 * schemas, and handler wrappers for special execution modes.
 *
 * @since 4.0.0
 */
import type * as Cause from "../../Cause.ts";
import * as Context from "../../Context.ts";
import type { Deferred } from "../../Deferred.ts";
import type { Effect } from "../../Effect.ts";
import type { Exit as Exit_ } from "../../Exit.ts";
import { type Pipeable } from "../../Pipeable.ts";
import type * as Queue from "../../Queue.ts";
import * as Schema from "../../Schema.ts";
import type { Stream } from "../../Stream.ts";
import type * as Struct from "../../Struct.ts";
import type { NoInfer } from "../../Types.ts";
import type { Headers } from "../http/Headers.ts";
import type { RequestId } from "./RpcMessage.ts";
import type * as RpcMiddleware from "./RpcMiddleware.ts";
import * as RpcSchema from "./RpcSchema.ts";
declare const TypeId = "~effect/rpc/Rpc";
/**
 * Returns `true` when the value is an `Rpc` definition.
 *
 * @category guards
 * @since 4.0.0
 */
export declare const isRpc: (u: unknown) => u is Rpc<any, any, any>;
/**
 * Schema for RPC defects.
 *
 * **Details**
 *
 * Defect schemas decode and encode without services and can be constructed from
 * `null`, `undefined`, or an object value.
 *
 * @category models
 * @since 4.0.0
 */
export interface DefectSchema extends Schema.Top {
    readonly Type: unknown;
    make(input: null, options?: Schema.MakeOptions): unknown;
    make(input: undefined, options?: Schema.MakeOptions): unknown;
    make(input: {}, options?: Schema.MakeOptions): unknown;
    readonly DecodingServices: never;
    readonly EncodingServices: never;
}
/**
 * Represents a typed RPC definition.
 *
 * **Details**
 *
 * An RPC is identified by a tag and carries payload, success, error, defect,
 * middleware, and annotation metadata used by RPC clients and servers.
 *
 * @category models
 * @since 4.0.0
 */
export interface Rpc<in out Tag extends string, out Payload extends Schema.Top = Schema.Void, out Success extends Schema.Top = Schema.Void, out Error extends Schema.Top = Schema.Never, out Middleware extends RpcMiddleware.AnyService = never, out Requires = never> extends Pipeable {
    new (_: never): {};
    readonly [TypeId]: typeof TypeId;
    readonly _tag: Tag;
    readonly key: string;
    readonly payloadSchema: Payload;
    readonly successSchema: Success;
    readonly errorSchema: Error;
    readonly defectSchema: Schema.Top;
    readonly annotations: Context.Context<never>;
    readonly middlewares: ReadonlySet<Middleware>;
    readonly "~requires": Requires;
    /**
     * Set the schema for the success response of the rpc.
     */
    setSuccess<S extends Schema.Top>(schema: S): Rpc<Tag, Payload, S, Error, Middleware, Requires>;
    /**
     * Set the schema for the error response of the rpc.
     */
    setError<E extends Schema.Top>(schema: E): Rpc<Tag, Payload, Success, E, Middleware, Requires>;
    /**
     * Set the schema for the payload of the rpc.
     */
    setPayload<P extends Schema.Top | Schema.Struct.Fields>(schema: P): Rpc<Tag, P extends Schema.Struct.Fields ? Schema.Struct<P> : P, Success, Error, Middleware, Requires>;
    /**
     * Add an `RpcMiddleware` to this procedure.
     */
    middleware<M extends RpcMiddleware.AnyService>(middleware: M): Rpc<Tag, Payload, Success, Error, Middleware | M, RpcMiddleware.ApplyServices<M["Identifier"], Requires>>;
    /**
     * Set the schema for the error response of the rpc.
     */
    prefix<const Prefix extends string>(prefix: Prefix): Rpc<`${Prefix}${Tag}`, Payload, Success, Error, Middleware, Requires>;
    /**
     * Add an annotation on the rpc.
     */
    annotate<I, S>(tag: Context.Key<I, S>, value: NoInfer<S>): Rpc<Tag, Payload, Success, Error, Middleware, Requires>;
    /**
     * Merge the annotations of the rpc with the provided annotations.
     */
    annotateMerge<I>(annotations: Context.Context<I>): Rpc<Tag, Payload, Success, Error, Middleware, Requires>;
}
/**
 * Represents server-side metadata for the client associated with an RPC request.
 *
 * **When to use**
 *
 * Use to inspect or annotate the connected client while handling an RPC request
 * on the server.
 *
 * **Details**
 *
 * It stores the client id and request annotations that handlers can read or
 * extend.
 *
 * @category models
 * @since 4.0.0
 */
export declare class ServerClient {
    readonly id: number;
    annotations: Context.Context<never>;
    constructor(id: number);
    annotate<I, S>(tag: Context.Key<I, S>, value: NoInfer<S>): ServerClient;
}
/**
 * Represents the server-side implementation of an RPC.
 *
 * **Details**
 *
 * The handler receives the decoded request plus client, request id, headers,
 * and RPC metadata, and returns either an effectful result or a stream result.
 *
 * @category models
 * @since 4.0.0
 */
export interface Handler<Tag extends string> {
    readonly _: unique symbol;
    readonly tag: Tag;
    readonly handler: (request: any, options: {
        readonly client: ServerClient;
        readonly requestId: RequestId;
        readonly headers: Headers;
        readonly rpc: Any;
    }) => Effect<{} | Deferred<any, any>, any> | Stream<any, any>;
    readonly context: Context.Context<never>;
}
/**
 * An erased RPC definition that preserves the common runtime metadata shared by
 * all RPCs.
 *
 * @category models
 * @since 4.0.0
 */
export interface Any extends Pipeable {
    readonly [TypeId]: typeof TypeId;
    readonly _tag: string;
    readonly key: string;
    readonly annotations: Context.Context<never>;
}
/**
 * An erased RPC definition with all schema, middleware, annotation, and service
 * metadata available.
 *
 * @category models
 * @since 4.0.0
 */
export interface AnyWithProps extends Pipeable {
    readonly [TypeId]: typeof TypeId;
    readonly _tag: string;
    readonly key: string;
    readonly payloadSchema: Schema.Top;
    readonly successSchema: Schema.Top;
    readonly errorSchema: Schema.Top;
    readonly defectSchema: Schema.Top;
    readonly annotations: Context.Context<never>;
    readonly middlewares: ReadonlySet<RpcMiddleware.AnyServiceWithProps>;
    readonly "~requires": any;
}
/**
 * Extracts the tag string from an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type Tag<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Tag : never;
/**
 * Extracts the success schema from an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type SuccessSchema<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Success : never;
/**
 * Extracts the decoded success value type from an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type Success<R> = SuccessSchema<R>["Type"];
/**
 * Extracts the encoded success value type from an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type SuccessEncoded<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Success["Encoded"] : never;
/**
 * Extracts the success schema used in an RPC exit.
 *
 * **Details**
 *
 * For streaming RPCs, this is the stream element schema; otherwise it is the
 * RPC success schema.
 *
 * @category models
 * @since 4.0.0
 */
export type SuccessExitSchema<R> = SuccessSchema<R> extends RpcSchema.Stream<infer _A, infer _E> ? _A : SuccessSchema<R>;
/**
 * Extracts the decoded success value carried by an RPC exit.
 *
 * **Details**
 *
 * For streaming RPCs, the immediate exit success is `void` because stream
 * elements are delivered separately.
 *
 * @category models
 * @since 4.0.0
 */
export type SuccessExit<R> = Success<R> extends infer T ? T extends Stream<infer _A, infer _E, infer _Env> ? void : T : never;
/**
 * Extracts the decoded stream element type from a streaming RPC, or `never` for
 * non-streaming RPCs.
 *
 * @category models
 * @since 4.0.0
 */
export type SuccessChunk<R> = Success<R> extends Stream<infer _A, infer _E, infer _Env> ? _A : never;
/**
 * Extracts the RPC error schema, including error schemas contributed by
 * middleware.
 *
 * @category models
 * @since 4.0.0
 */
export type ErrorSchema<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Error | _Middleware["error"] : never;
/**
 * Extracts the decoded error value type from an `Rpc`, including middleware
 * errors.
 *
 * @category models
 * @since 4.0.0
 */
export type Error<R> = Schema.Schema.Type<ErrorSchema<R>>;
/**
 * Extracts the error schema used in an RPC exit.
 *
 * **Details**
 *
 * For streaming RPCs, this includes both the stream error schema and the RPC
 * error schema; otherwise it is the RPC error schema.
 *
 * @category models
 * @since 4.0.0
 */
export type ErrorExitSchema<R> = SuccessSchema<R> extends RpcSchema.Stream<infer _A, infer _E> ? _E | ErrorSchema<R> : ErrorSchema<R>;
/**
 * Extracts the decoded error type used by an RPC exit.
 *
 * **Details**
 *
 * For streaming RPCs, this includes both stream errors and RPC errors.
 *
 * @category models
 * @since 4.0.0
 */
export type ErrorExit<R> = Success<R> extends Stream<infer _A, infer _E, infer _Env> ? _E | Error<R> : Error<R>;
/**
 * The `Exit` type produced for an RPC, using the RPC's exit success and exit
 * error types.
 *
 * @category models
 * @since 4.0.0
 */
export type Exit<R> = Exit_<SuccessExit<R>, ErrorExit<R>>;
/**
 * Extracts the payload constructor input type accepted by the RPC payload
 * schema.
 *
 * @category models
 * @since 4.0.0
 */
export type PayloadConstructor<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Payload["~type.make.in"] : never;
/**
 * Extracts the decoded payload type from an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type Payload<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Payload["Type"] : never;
/**
 * Extracts all schema services required to encode or decode an RPC's payload,
 * success, error, and middleware error schemas.
 *
 * @category models
 * @since 4.0.0
 */
export type Services<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Payload["DecodingServices"] | _Payload["EncodingServices"] | _Success["DecodingServices"] | _Success["EncodingServices"] | _Error["DecodingServices"] | _Error["EncodingServices"] | _Middleware["error"]["DecodingServices"] | _Middleware["error"]["EncodingServices"] : never;
/**
 * Extracts the schema services required on the client side of an RPC.
 *
 * **Details**
 *
 * This includes payload encoding services and success, error, and middleware
 * error decoding services.
 *
 * @category models
 * @since 4.0.0
 */
export type ServicesClient<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] | _Middleware["error"]["DecodingServices"] : never;
/**
 * Extracts the schema services required on the server side of an RPC.
 *
 * **Details**
 *
 * This includes payload decoding services and success, error, and middleware
 * error encoding services.
 *
 * @category models
 * @since 4.0.0
 */
export type ServicesServer<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Payload["DecodingServices"] | _Success["EncodingServices"] | _Error["EncodingServices"] | _Middleware["error"]["EncodingServices"] : never;
/**
 * Extracts the service identifiers for middleware attached to an `Rpc`.
 *
 * @category models
 * @since 4.0.0
 */
export type Middleware<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Context.Service.Identifier<_Middleware> : never;
/**
 * Extracts client-side middleware service requirements for middleware marked as
 * required on the client.
 *
 * @category models
 * @since 4.0.0
 */
export type MiddlewareClient<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Middleware extends {
    readonly requiredForClient: true;
} ? RpcMiddleware.ForClient<_Middleware["Identifier"]> : never : never;
/**
 * Returns an RPC type with an additional error schema unioned into its error
 * channel.
 *
 * @category models
 * @since 4.0.0
 */
export type AddError<R extends Any, Error extends Schema.Top> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Rpc<_Tag, _Payload, _Success, _Error | Error, _Middleware, _Requires> : never;
/**
 * Returns an RPC type with additional middleware and the corresponding
 * middleware service requirements applied.
 *
 * @category models
 * @since 4.0.0
 */
export type AddMiddleware<R extends Any, Middleware extends RpcMiddleware.AnyService> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Rpc<_Tag, _Payload, _Success, _Error, _Middleware | Middleware, RpcMiddleware.ApplyServices<Middleware["Identifier"], _Requires>> : never;
/**
 * Converts an RPC definition into the corresponding `Handler` type.
 *
 * @category models
 * @since 4.0.0
 */
export type ToHandler<R extends Any> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Handler<_Tag> : never;
/**
 * The function signature for implementing an RPC handler.
 *
 * **Details**
 *
 * The function receives the decoded payload and request metadata, and returns
 * the RPC result shape, optionally wrapped with `Wrapper` options.
 *
 * @category models
 * @since 4.0.0
 */
export type ToHandlerFn<Current extends Any, R = any> = (payload: Payload<Current>, options: {
    readonly client: ServerClient;
    readonly requestId: RequestId;
    readonly headers: Headers;
    readonly rpc: Current;
}) => WrapperOr<ResultFrom<Current, R>>;
/**
 * Returns `true` when the RPC with the specified tag has a streaming success
 * schema, or `never` otherwise.
 *
 * @category models
 * @since 4.0.0
 */
export type IsStream<R extends Any, Tag extends string> = R extends Rpc<Tag, infer _Payload, RpcSchema.Stream<infer _A, infer _E>, infer _Error, infer _Middleware, infer _Requires> ? true : never;
/**
 * Extracts the RPC with the specified tag from an RPC union.
 *
 * @category models
 * @since 4.0.0
 */
export type ExtractTag<R extends Any, Tag extends string> = R extends Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? R : never;
/**
 * Extracts the services provided by middleware on the RPC with the specified
 * tag.
 *
 * @category models
 * @since 4.0.0
 */
export type ExtractProvides<R extends Any, Tag extends string> = R extends Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? RpcMiddleware.Provides<_Middleware["Identifier"]> : never;
/**
 * Extracts the service requirements of the RPC with the specified tag.
 *
 * @category models
 * @since 4.0.0
 */
export type ExtractRequires<R extends Any, Tag extends string> = R extends Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? _Requires : never;
/**
 * Removes the services provided by middleware for the specified RPC tag from an
 * environment type.
 *
 * @category models
 * @since 4.0.0
 */
export type ExcludeProvides<Env, R extends Any, Tag extends string> = Exclude<Env, ExtractProvides<R, Tag>>;
/**
 * Computes the allowed handler result type for an RPC.
 *
 * **Details**
 *
 * Streaming RPCs may return a stream or an effect that produces a queue. Other
 * RPCs return an effect that succeeds with the success value or a deferred
 * success value.
 *
 * @category models
 * @since 4.0.0
 */
export type ResultFrom<R extends Any, Services> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? [_Success] extends [RpcSchema.Stream<infer _SA, infer _SE>] ? Stream<_SA["Type"], _SE["Type"] | _Error["Type"], Services> | Effect<Queue.Dequeue<_SA["Type"], _SE["Type"] | _Error["Type"] | Cause.Done>, _SE["Type"] | Schema.Schema.Type<_Error>, Services> : Effect<_Success["Type"] | Deferred<_Success["Type"], _Error["Type"]>, _Error["Type"], Services> : never;
/**
 * Returns an RPC type with the specified string prefix added to its tag while
 * preserving its payload, success, error, middleware, and requirements.
 *
 * @category models
 * @since 4.0.0
 */
export type Prefixed<Rpcs extends Any, Prefix extends string> = Rpcs extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? Rpc<`${Prefix}${_Tag}`, _Payload, _Success, _Error, _Middleware, _Requires> : never;
/**
 * Creates an RPC definition with the supplied tag and optional schemas.
 *
 * **Details**
 *
 * Payload options can be either a schema or struct fields. `stream: true` wraps
 * the success and error schemas in a stream schema and sets the normal error
 * schema to `Schema.Never`. `primaryKey` creates a payload class with a
 * primary key derived from the payload value.
 *
 * @category constructors
 * @since 4.0.0
 */
export declare const make: <const Tag extends string, Payload extends Schema.Top | Schema.Struct.Fields = Schema.Void, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never, const Stream extends boolean = false>(tag: Tag, options?: {
    readonly payload?: Payload;
    readonly success?: Success;
    readonly error?: Error;
    readonly defect?: DefectSchema;
    readonly stream?: Stream;
    readonly primaryKey?: [Payload] extends [Schema.Struct.Fields] ? ((payload: Payload extends Schema.Struct.Fields ? Struct.Simplify<Schema.Struct<Payload>["Type"]> : Payload["Type"]) => string) : never;
}) => Rpc<Tag, Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload, Stream extends true ? RpcSchema.Stream<Success, Error> : Success, Stream extends true ? typeof Schema.Never : Error>;
/**
 * Creates a custom `Rpc` constructor that can transform the output schemas.
 *
 * **Example** (Paginated RPC constructor)
 *
 * ```ts
 * import { Schema } from "effect"
 * import { Rpc } from "effect/unstable/rpc"
 *
 * // Create a custom Rpc wrapper definition by transforming the success and error
 * // schemas.
 * export interface RpcWithPagination extends Rpc.Custom {
 *   readonly out: Rpc.Custom.Out<
 *     Paginated<this["success"]>,
 *     this["error"]
 *   >
 * }
 *
 * // The type definition for the transformed success schema.
 * export interface Paginated<S extends Schema.Top> extends
 *   Schema.Struct<{
 *     readonly offset: Schema.Number
 *     readonly total: Schema.Number
 *     readonly results: Schema.$Array<S>
 *   }>
 * {}
 *
 * // You can then implement the schema transformation using `Rpc.custom`
 * export const makePaginated = Rpc.custom<RpcWithPagination>((schemas) => ({
 *   ...schemas,
 *   success: Schema.Struct({
 *     offset: Schema.Number,
 *     total: Schema.Number,
 *     results: Schema.Array(schemas.success)
 *   })
 * }))
 *
 * // You can then use the custom constructor in the same way `Rpc.make` is used.
 * export const listAllRpc = makePaginated("listAll", {
 *   success: Schema.String
 * })
 * ```
 *
 * @category constructors
 * @since 4.0.0
 */
export declare const custom: <Def extends Custom>(f: (options: Custom.OutDefault) => (Def & Custom.OutDefault)["out"]) => <const Tag extends string, Payload extends Schema.Top | Schema.Struct.Fields = Schema.Void, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never, const Stream extends boolean = false, Out extends Custom.OutDefault = Custom.Kind<Def, Success, Error>>(tag: Tag, options?: {
    readonly payload?: Payload;
    readonly success?: Success;
    readonly error?: Error;
    readonly defect?: DefectSchema;
    readonly stream?: Stream;
    readonly primaryKey?: [Payload] extends [Schema.Struct.Fields] ? ((payload: Payload extends Schema.Struct.Fields ? Struct.Simplify<Schema.Struct<Payload>["Type"]> : Payload["Type"]) => string) : never;
}) => Rpc<Tag, Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload, Stream extends true ? RpcSchema.Stream<Out["success"], Out["error"]> : Out["success"], Stream extends true ? typeof Schema.Never : Out["error"]>;
/**
 * Defines the type-level contract for an RPC custom constructor.
 *
 * **Details**
 *
 * A custom constructor receives the original success, error, and defect schemas
 * and returns transformed output schemas through `out`.
 *
 * @category constructors
 * @since 4.0.0
 */
export interface Custom {
    readonly out: Custom.OutDefault;
    readonly success: Schema.Top;
    readonly error: Schema.Top;
    readonly defect: DefectSchema;
}
/**
 * Helper types for defining RPC custom constructors.
 *
 * @since 4.0.0
 */
export declare namespace Custom {
    /**
     * The transformed schemas produced by a custom RPC constructor.
     *
     * @category constructors
     * @since 4.0.0
     */
    interface Out<Success extends Schema.Top, Error extends Schema.Top> {
        readonly success: Success;
        readonly error: Error;
        readonly defect: DefectSchema;
    }
    /**
     * The default custom-constructor output shape for arbitrary success and error
     * schemas.
     *
     * @category constructors
     * @since 4.0.0
     */
    type OutDefault = Out<Schema.Top, Schema.Top>;
    /**
     * Applies a custom constructor definition to concrete success and error
     * schemas and returns its transformed output schema type.
     *
     * @category constructors
     * @since 4.0.0
     */
    type Kind<Def extends Custom, Success extends Schema.Top, Error extends Schema.Top> = (Def & {
        readonly success: Success;
        readonly error: Error;
    })["out"];
}
/**
 * Builds the `Schema.Exit` used to encode and decode RPC results.
 *
 * **Details**
 *
 * The failure side includes the RPC error schema, middleware error schemas, and
 * stream error schema for streaming RPCs. Streaming RPCs use `Schema.Void` for
 * the exit success value. The schema is cached per RPC definition.
 *
 * @category constructors
 * @since 4.0.0
 */
export declare const exitSchema: <R extends Any>(self: R) => Schema.Exit<SuccessExitSchema<R>, ErrorExitSchema<R>, DefectSchema>;
declare const WrapperTypeId = "~effect/rpc/Rpc/Wrapper";
/**
 * Wraps a handler result with execution options for the RPC server.
 *
 * **Details**
 *
 * `fork` requests concurrent execution, and `uninterruptible` requests
 * uninterruptible execution.
 *
 * @category wrapping
 * @since 4.0.0
 */
export interface Wrapper<A> {
    readonly [WrapperTypeId]: typeof WrapperTypeId;
    readonly value: A;
    readonly fork: boolean;
    readonly uninterruptible: boolean;
}
/**
 * A value that may be returned directly or wrapped with RPC server execution
 * options.
 *
 * @category wrapping
 * @since 4.0.0
 */
export type WrapperOr<A> = A | Wrapper<A>;
/**
 * Returns `true` when the value is an RPC `Wrapper`.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const isWrapper: (u: object) => u is Wrapper<any>;
/**
 * Wraps a handler result with RPC server execution options.
 *
 * **Details**
 *
 * When the value is already wrapped, unspecified options are inherited from the
 * existing wrapper.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const wrap: (options: {
    readonly fork?: boolean | undefined;
    readonly uninterruptible?: boolean | undefined;
}) => <A extends object>(value: A) => Wrapper<A>;
/**
 * Returns the wrapped response value when the input is an RPC `Wrapper`, or the
 * input itself when it is already unwrapped.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const unwrap: <A extends object>(value: WrapperOr<A>) => A;
/**
 * Maps the value inside an RPC wrapper, preserving wrapper options such as
 * `fork` and `uninterruptible`; unwrapped values are mapped directly.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const wrapMap: <A extends object, B extends object>(self: WrapperOr<A>, f: (value: A) => B) => WrapperOr<B>;
/**
 * Wraps a response Effect or Stream so the RPC server executes it concurrently
 * regardless of the server concurrency setting.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const fork: <A extends object>(value: A) => Wrapper<A>;
/**
 * Wraps a response Effect or Stream so the RPC server runs it in an uninterruptible region.
 *
 * @category wrapping
 * @since 4.0.0
 */
export declare const uninterruptible: <A extends object>(value: A) => Wrapper<A>;
export {};
//# sourceMappingURL=Rpc.d.ts.map