Rpc.ts overview
Since v1.0.0
Exports Grouped by Category
- Fork
- constructors
- guards
- models
- AddError (type alias)
- AddMiddleware (type alias)
- Any (interface)
- AnyWithProps (interface)
- Context (type alias)
- Error (type alias)
- ErrorEncoded (type alias)
- ErrorExit (type alias)
- ErrorExitEncoded (type alias)
- ErrorSchema (type alias)
- ExcludeProvides (type alias)
- Exit (type alias)
- ExitEncoded (type alias)
- ExtractProvides (type alias)
- ExtractTag (type alias)
- From (interface)
- Handler (interface)
- IsStream (type alias)
- Middleware (type alias)
- MiddlewareClient (type alias)
- Payload (type alias)
- PayloadConstructor (type alias)
- Rpc (interface)
- Success (type alias)
- SuccessChunk (type alias)
- SuccessChunkEncoded (type alias)
- SuccessEncoded (type alias)
- SuccessExit (type alias)
- SuccessExitEncoded (type alias)
- Tag (type alias)
- ToHandler (type alias)
- type ids
Fork
Fork (interface)
Signature
export interface Fork<A> {
readonly [ForkTypeId]: ForkTypeId
readonly value: A
}
Since v1.0.0
ForkTypeId
Signature
declare const ForkTypeId: unique symbol
Since v1.0.0
ForkTypeId (type alias)
Signature
type ForkTypeId = typeof ForkTypeId
Since v1.0.0
fork
You can use fork
to wrap a response Effect or Stream, to ensure that the response is executed concurrently regardless of the RpcServer concurrency setting.
Signature
declare const fork: <A>(value: A) => Fork<A>
Since v1.0.0
isFork
Signature
declare const isFork: (u: object) => u is Fork<any>
Since v1.0.0
constructors
AnyStructSchema (interface)
Signature
export interface AnyStructSchema extends Pipeable {
readonly [Schema.TypeId]: any
readonly make: any
readonly Type: any
readonly Encoded: any
readonly Context: any
readonly ast: AST.AST
readonly fields: Schema.Struct.Fields
readonly annotations: any
}
Since v1.0.0
AnyTaggedRequestSchema (interface)
Signature
export interface AnyTaggedRequestSchema extends AnyStructSchema {
readonly _tag: string
readonly success: Schema.Schema.Any
readonly failure: Schema.Schema.All
}
Since v1.0.0
exitSchema
Signature
declare const exitSchema: <R extends Any>(self: R) => Schema.Schema<Exit<R>, ExitEncoded<R>, Context<R>>
Since v1.0.0
fromTaggedRequest
Signature
declare const fromTaggedRequest: <S extends AnyTaggedRequestSchema>(schema: S) => From<S>
Since v1.0.0
make
Signature
declare const make: <
const Tag extends string,
Payload extends AnyStructSchema | Schema.Struct.Fields = Schema.Struct<{}>,
Success extends Schema.Schema.Any = any,
Error extends Schema.Schema.All = any,
const Stream extends boolean = false
>(
tag: Tag,
options?: { readonly payload?: Payload; readonly success?: Success; readonly error?: Error; readonly stream?: Stream }
) => 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
>
Since v1.0.0
guards
isRpc
Signature
declare const isRpc: (u: unknown) => u is Rpc<any, any, any>
Since v1.0.0
models
AddError (type alias)
Signature
type AddError<R, Error> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? Rpc<_Tag, _Payload, _Success, _Error | Error, _Middleware>
: never
Since v1.0.0
AddMiddleware (type alias)
Signature
type AddMiddleware<R, Middleware> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? Rpc<_Tag, _Payload, _Success, _Error, _Middleware | Middleware>
: never
Since v1.0.0
Any (interface)
Signature
export interface Any extends Pipeable {
readonly [TypeId]: TypeId
readonly _tag: string
readonly key: string
}
Since v1.0.0
AnyWithProps (interface)
Signature
export interface AnyWithProps {
readonly [TypeId]: TypeId
readonly _tag: string
readonly key: string
readonly payloadSchema: AnyStructSchema
readonly successSchema: Schema.Schema.Any
readonly errorSchema: Schema.Schema.All
readonly annotations: Context_.Context<never>
readonly middlewares: ReadonlySet<RpcMiddleware.TagClassAnyWithProps>
}
Since v1.0.0
Context (type alias)
Signature
type Context<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? _Payload["Context"] | _Success["Context"] | _Error["Context"]
: never
Since v1.0.0
Error (type alias)
Signature
type Schema.Schema.Type<ErrorSchema<R>> = Schema.Schema.Type<ErrorSchema<R>>
Since v1.0.0
ErrorEncoded (type alias)
Signature
type Schema.Schema.Encoded<ErrorSchema<R>> = Schema.Schema.Encoded<ErrorSchema<R>>
Since v1.0.0
ErrorExit (type alias)
Signature
type ErrorExit<R> = Success<R> extends Stream<infer _A, infer _E, infer _Env> ? _E | Error<R> : Error<R>
Since v1.0.0
ErrorExitEncoded (type alias)
Signature
type ErrorExitEncoded<R> =
SuccessEncoded<R> extends Stream<infer _A, infer _E, infer _Env> ? _E | ErrorEncoded<R> : ErrorEncoded<R>
Since v1.0.0
ErrorSchema (type alias)
Signature
type ErrorSchema<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? _Error | _Middleware
: never
Since v1.0.0
ExcludeProvides (type alias)
Signature
type ExcludeProvides<Env, R, Tag> = Exclude<Env, ExtractProvides<R, Tag>>
Since v1.0.0
Exit (type alias)
Signature
type Exit_<SuccessExit<R>, ErrorExit<R>> = Exit_<SuccessExit<R>, ErrorExit<R>>
Since v1.0.0
ExitEncoded (type alias)
Signature
type Schema.ExitEncoded<SuccessExitEncoded<R>, ErrorExitEncoded<R>, Defect> = Schema.ExitEncoded<SuccessExitEncoded<R>, ErrorExitEncoded<R>, Defect>
Since v1.0.0
ExtractProvides (type alias)
Signature
type ExtractProvides<R, Tag> =
R extends Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? _Middleware extends {
readonly provides: Context_.Tag<infer _I, infer _S>
}
? _I
: never
: never
Since v1.0.0
ExtractTag (type alias)
Signature
type ExtractTag<R, Tag> =
R extends Rpc<Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? R : never
Since v1.0.0
From (interface)
Signature
export interface From<S extends AnyTaggedRequestSchema> extends Rpc<S["_tag"], S, S["success"], S["failure"]> {}
Since v1.0.0
Handler (interface)
Represents an implemented rpc.
Signature
export interface Handler<Tag extends string> {
readonly _: unique symbol
readonly tag: Tag
readonly handler: (request: any, headers: Headers) => Effect<any, any> | Stream<any, any>
readonly context: Context<never>
}
Since v1.0.0
IsStream (type alias)
Signature
type IsStream<R, Tag> =
R extends Rpc<Tag, infer _Payload, RpcSchema.Stream<infer _A, infer _E>, infer _Error, infer _Middleware>
? true
: never
Since v1.0.0
Middleware (type alias)
Signature
type Middleware<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? Context_.Tag.Identifier<_Middleware>
: never
Since v1.0.0
MiddlewareClient (type alias)
Signature
type MiddlewareClient<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? _Middleware extends { readonly requiredForClient: true }
? RpcMiddleware.ForClient<Context_.Tag.Identifier<_Middleware>>
: never
: never
Since v1.0.0
Payload (type alias)
Signature
type Payload<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? _Payload["Type"] : never
Since v1.0.0
PayloadConstructor (type alias)
Signature
type PayloadConstructor<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? Schema.Struct.Constructor<_Payload["fields"]> extends infer T
? [keyof T] extends [never]
? void | {}
: Schema.Simplify<T>
: never
: never
Since v1.0.0
Rpc (interface)
Represents an API endpoint. An API endpoint is mapped to a single route on the underlying HttpRouter
.
Signature
export interface Rpc<
out Tag extends string,
out Payload extends AnyStructSchema = Schema.Struct<{}>,
out Success extends Schema.Schema.Any = typeof Schema.Void,
out Error extends Schema.Schema.All = typeof Schema.Never,
out Middleware extends RpcMiddleware.TagClassAny = never
> extends Pipeable {
readonly [TypeId]: TypeId
readonly _tag: Tag
readonly key: string
readonly payloadSchema: Payload
readonly successSchema: Success
readonly errorSchema: Error
readonly annotations: Context_.Context<never>
readonly middlewares: ReadonlySet<Middleware>
/**
* Set the schema for the success response of the rpc.
*/
setSuccess<S extends Schema.Schema.Any>(schema: S): Rpc<Tag, Payload, S, Error, Middleware>
/**
* Set the schema for the error response of the rpc.
*/
setError<E extends Schema.Schema.Any>(schema: E): Rpc<Tag, Payload, Success, E, Middleware>
/**
* Set the schema for the payload of the rpc.
*/
setPayload<P extends Schema.Struct<any> | Schema.Struct.Fields>(
schema: P
): Rpc<
Tag,
P extends Schema.Struct<infer _> ? P : P extends Schema.Struct.Fields ? Schema.Struct<P> : never,
Success,
Error,
Middleware
>
/**
* Add an `RpcMiddleware` to this procedure.
*/
middleware<M extends RpcMiddleware.TagClassAny>(middleware: M): Rpc<Tag, Payload, Success, Error, Middleware | M>
/**
* Add an annotation on the rpc.
*/
annotate<I, S>(tag: Context_.Tag<I, S>, value: S): Rpc<Tag, Payload, Success, Error, Middleware>
/**
* Merge the annotations of the rpc with the provided context.
*/
annotateContext<I>(context: Context_.Context<I>): Rpc<Tag, Payload, Success, Error, Middleware>
}
Since v1.0.0
Success (type alias)
Signature
type Success<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? _Success["Type"] : never
Since v1.0.0
SuccessChunk (type alias)
Signature
type SuccessChunk<R> = Success<R> extends Stream<infer _A, infer _E, infer _Env> ? _A : never
Since v1.0.0
SuccessChunkEncoded (type alias)
Signature
type SuccessChunkEncoded<R> = SuccessEncoded<R> extends Stream<infer _A, infer _E, infer _Env> ? _A : never
Since v1.0.0
SuccessEncoded (type alias)
Signature
type SuccessEncoded<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware>
? _Success["Encoded"]
: never
Since v1.0.0
SuccessExit (type alias)
Signature
type SuccessExit<R> = Success<R> extends infer T ? (T extends Stream<infer _A, infer _E, infer _Env> ? void : T) : never
Since v1.0.0
SuccessExitEncoded (type alias)
Signature
type SuccessExitEncoded<R> =
SuccessEncoded<R> extends infer T ? (T extends Stream<infer _A, infer _E, infer _Env> ? void : T) : never
Since v1.0.0
Tag (type alias)
Signature
type Tag<R> = R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? _Tag : never
Since v1.0.0
ToHandler (type alias)
Signature
type ToHandler<R> =
R extends Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? Handler<_Tag> : never
Since v1.0.0
type ids
TypeId
Signature
declare const TypeId: unique symbol
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v1.0.0