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

Entity.ts overview

Since v1.0.0


Exports Grouped by Category


Replier

Replier (interface)

Signature

export interface Replier<Rpcs extends Rpc.Any> {
  readonly succeed: <R extends Rpcs>(request: Envelope.Request<R>, value: Replier.Success<R>) => Effect.Effect<void>

  readonly fail: <R extends Rpcs>(request: Envelope.Request<R>, error: Rpc.Error<R>) => Effect.Effect<void>

  readonly failCause: <R extends Rpcs>(
    request: Envelope.Request<R>,
    cause: Cause.Cause<Rpc.Error<R>>
  ) => Effect.Effect<void>

  readonly complete: <R extends Rpcs>(
    request: Envelope.Request<R>,
    exit: Exit.Exit<Replier.Success<R>, Rpc.Error<R>>
  ) => Effect.Effect<void>
}

Source

Since v1.0.0

Replier (namespace)

Source

Since v1.0.0

Success (type alias)

Signature

type any =
  Rpc.Success<R> extends Stream.Stream<infer _A, infer _E, infer _R>
    ? Stream.Stream<_A, _E | Rpc.Error<R>, _R> | Mailbox.ReadonlyMailbox<_A, _E | Rpc.Error<R>>
    : Rpc.Success<R>

Source

Since v1.0.0

Request

Request (class)

Signature

declare class Request<Rpc>

Source

Since v1.0.0

constructors

fromRpcGroup

Creates a new Entity of the specified type which will accept messages that adhere to the provided RpcGroup.

Signature

declare const fromRpcGroup: <Rpcs extends Rpc.Any>(type: string, protocol: RpcGroup.RpcGroup<Rpcs>) => Entity<Rpcs>

Source

Since v1.0.0

make

Creates a new Entity of the specified type which will accept messages that adhere to the provided schemas.

Signature

declare const make: <Rpcs extends ReadonlyArray<Rpc.Any>>(type: string, protocol: Rpcs) => Entity<Rpcs[number]>

Source

Since v1.0.0

context

CurrentAddress (class)

A Context.Tag to access the current entity address.

Signature

declare class CurrentAddress

Source

Since v1.0.0

CurrentRunnerAddress (class)

A Context.Tag to access the current Runner address.

Signature

declare class CurrentRunnerAddress

Source

Since v1.0.0

models

Any (type alias)

Signature

type Any = Entity<Rpc.Any>

Source

Since v1.0.0

Entity (interface)

Signature

export interface Entity<in out Rpcs extends Rpc.Any> extends Equal.Equal {
  readonly [TypeId]: TypeId
  /**
   * The name of the entity type.
   */
  readonly type: EntityType

  /**
   * A RpcGroup definition for messages which represents the messaging protocol
   * that the entity is capable of processing.
   */
  readonly protocol: RpcGroup.RpcGroup<Rpcs>

  /**
   * Annotate the entity with a value.
   */
  annotate<I, S>(tag: Context.Tag<I, S>, value: S): Entity<Rpcs>

  /**
   * Annotate the Rpc's above this point with a value.
   */
  annotateRpcs<I, S>(tag: Context.Tag<I, S>, value: S): Entity<Rpcs>

  /**
   * Annotate the entity with a context object.
   */
  annotateContext<S>(context: Context.Context<S>): Entity<Rpcs>

  /**
   * Annotate the Rpc's above this point with a context object.
   */
  annotateRpcsContext<S>(context: Context.Context<S>): Entity<Rpcs>

  /**
   * Create a client for this entity.
   */
  readonly client: Effect.Effect<
    (entityId: string) => RpcClient.RpcClient<Rpcs, MailboxFull | AlreadyProcessingMessage | PersistenceError>,
    never,
    Sharding
  >

  /**
   * Create a Layer from an Entity.
   *
   * It will register the entity with the Sharding service.
   */
  toLayer<Handlers extends HandlersFrom<Rpcs>, RX = never>(
    build: Handlers | Effect.Effect<Handlers, never, RX>,
    options?: {
      readonly maxIdleTime?: DurationInput | undefined
      readonly concurrency?: number | "unbounded" | undefined
      readonly mailboxCapacity?: number | "unbounded" | undefined
    }
  ): Layer.Layer<
    never,
    never,
    | Exclude<RX, Scope | CurrentAddress | CurrentRunnerAddress>
    | RpcGroup.HandlersContext<Rpcs, Handlers>
    | Rpc.Context<Rpcs>
    | Rpc.Middleware<Rpcs>
    | Sharding
  >

  /**
   * Create a Layer from an Entity.
   *
   * It will register the entity with the Sharding service.
   */
  toLayerMailbox<R, RX = never>(
    build:
      | ((
          mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>,
          replier: Replier<Rpcs>
        ) => Effect.Effect<never, never, R>)
      | Effect.Effect<
          (
            mailbox: Mailbox.ReadonlyMailbox<Envelope.Request<Rpcs>>,
            replier: Replier<Rpcs>
          ) => Effect.Effect<never, never, R>,
          never,
          RX
        >,
    options?: {
      readonly maxIdleTime?: DurationInput | undefined
      readonly mailboxCapacity?: number | "unbounded" | undefined
    }
  ): Layer.Layer<
    never,
    never,
    Exclude<RX, Scope | CurrentAddress> | R | Rpc.Context<Rpcs> | Rpc.Middleware<Rpcs> | Sharding
  >
}

Source

Since v1.0.0

HandlersFrom (type alias)

Signature

type HandlersFrom<Rpc> = {
  readonly [Current in Rpc as Current["_tag"]]: (
    envelope: Request<Current>
  ) => RpcGroup.ResultFrom<Current> | Rpc.Fork<RpcGroup.ResultFrom<Current>>
}

Source

Since v1.0.0

refinements

isEntity

Signature

declare const isEntity: (u: unknown) => u is Any

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