Skip to main content Link Search Menu Expand Document (external link)

Rpc.ts overview

Since v1.0.0


Exports Grouped by Category


Fork

Fork (interface)

Signature

export interface Fork<A> {
  readonly [ForkTypeId]: ForkTypeId
  readonly value: A
}

Source

Since v1.0.0

ForkTypeId

Signature

declare const ForkTypeId: unique symbol

Source

Since v1.0.0

ForkTypeId (type alias)

Signature

type ForkTypeId = typeof ForkTypeId

Source

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>

Source

Since v1.0.0

isFork

Signature

declare const isFork: (u: object) => u is Fork<any>

Source

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
}

Source

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
}

Source

Since v1.0.0

exitSchema

Signature

declare const exitSchema: <R extends Any>(self: R) => Schema.Schema<Exit<R>, ExitEncoded<R>, Context<R>>

Source

Since v1.0.0

fromTaggedRequest

Signature

declare const fromTaggedRequest: <S extends AnyTaggedRequestSchema>(schema: S) => From<S>

Source

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
>

Source

Since v1.0.0

guards

isRpc

Signature

declare const isRpc: (u: unknown) => u is Rpc<any, any, any>

Source

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

Source

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

Source

Since v1.0.0

Any (interface)

Signature

export interface Any extends Pipeable {
  readonly [TypeId]: TypeId
  readonly _tag: string
  readonly key: string
}

Source

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>
}

Source

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

Source

Since v1.0.0

Error (type alias)

Signature

type Schema.Schema.Type<ErrorSchema<R>> = Schema.Schema.Type<ErrorSchema<R>>

Source

Since v1.0.0

ErrorEncoded (type alias)

Signature

type Schema.Schema.Encoded<ErrorSchema<R>> = Schema.Schema.Encoded<ErrorSchema<R>>

Source

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>

Source

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>

Source

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

Source

Since v1.0.0

ExcludeProvides (type alias)

Signature

type ExcludeProvides<Env, R, Tag> = Exclude<Env, ExtractProvides<R, Tag>>

Source

Since v1.0.0

Exit (type alias)

Signature

type Exit_<SuccessExit<R>, ErrorExit<R>> = Exit_<SuccessExit<R>, ErrorExit<R>>

Source

Since v1.0.0

ExitEncoded (type alias)

Signature

type Schema.ExitEncoded<SuccessExitEncoded<R>, ErrorExitEncoded<R>, Defect> = Schema.ExitEncoded<SuccessExitEncoded<R>, ErrorExitEncoded<R>, Defect>

Source

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

Source

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

Source

Since v1.0.0

From (interface)

Signature

export interface From<S extends AnyTaggedRequestSchema> extends Rpc<S["_tag"], S, S["success"], S["failure"]> {}

Source

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>
}

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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>
}

Source

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

Source

Since v1.0.0

SuccessChunk (type alias)

Signature

type SuccessChunk<R> = Success<R> extends Stream<infer _A, infer _E, infer _Env> ? _A : never

Source

Since v1.0.0

SuccessChunkEncoded (type alias)

Signature

type SuccessChunkEncoded<R> = SuccessEncoded<R> extends Stream<infer _A, infer _E, infer _Env> ? _A : never

Source

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

Source

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

Source

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

Source

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

Source

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

Source

Since v1.0.0

type ids

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v1.0.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v1.0.0