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

Entity.ts overview

Since v1.0.0


Exports Grouped by Category


Keep alive

KeepAliveLatch (class)

Signature

declare class KeepAliveLatch

Source

Since v1.0.0

KeepAliveRpc

Signature

declare const KeepAliveRpc: Rpc.Rpc<"Cluster/Entity/keepAlive", typeof Void, typeof Void, typeof Never, never>

Source

Since v1.0.0

keepAlive

Signature

declare const keepAlive: (enabled: boolean) => Effect.Effect<void, never, Sharding | CurrentAddress>

Source

Since v1.0.0

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 Success<R> =
  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

Testing

makeTestClient

Signature

declare const makeTestClient: <Type extends string, Rpcs extends Rpc.Any, LA, LE, LR>(
  entity: Entity<Type, Rpcs>,
  layer: Layer.Layer<LA, LE, LR>
) => Effect.Effect<
  (entityId: string) => Effect.Effect<RpcClient.RpcClient<Rpcs>>,
  LE,
  Scope | ShardingConfig | Exclude<LR, Sharding> | Rpc.MiddlewareClient<Rpcs>
>

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: <const Type extends string, Rpcs extends Rpc.Any>(
  type: Type,
  protocol: RpcGroup.RpcGroup<Rpcs>
) => Entity<Type, 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: <const Type extends string, Rpcs extends ReadonlyArray<Rpc.Any>>(
  type: Type,
  protocol: Rpcs
) => Entity<Type, 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<string, Rpc.Any>

Source

Since v1.0.0

Entity (interface)

Signature

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

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

  /**
   * Get the shard group for the given EntityId.
   */
  getShardGroup(entityId: EntityId): string

  /**
   * Get the ShardId for the given EntityId.
   */
  getShardId(entityId: EntityId): Effect.Effect<ShardId.ShardId, never, Sharding>

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

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

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

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

  /**
   * Create a client for this entity.
   */
  readonly client: Effect.Effect<
    (entityId: string) => RpcClient.RpcClient.From<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
      readonly disableFatalDefects?: boolean | undefined
      readonly defectRetryPolicy?: Schedule.Schedule<any, unknown> | undefined
      readonly spanAttributes?: Record<string, string> | undefined
    }
  ): Layer.Layer<
    never,
    never,
    | Exclude<RX, Scope | CurrentAddress | CurrentRunnerAddress>
    | RpcGroup.HandlersContext<Rpcs, Handlers>
    | Rpc.Context<Rpcs>
    | Rpc.Middleware<Rpcs>
    | Sharding
  >

  of<Handlers extends HandlersFrom<Rpcs>>(handlers: Handlers): Handlers

  /**
   * 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
      readonly disableFatalDefects?: boolean | undefined
      readonly defectRetryPolicy?: Schedule.Schedule<any, unknown> | undefined
      readonly spanAttributes?: Record<string, string> | undefined
    }
  ): Layer.Layer<
    never,
    never,
    Exclude<RX, Scope | CurrentAddress | CurrentRunnerAddress> | 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>
  ) => Rpc.ResultFrom<Current, any> | Rpc.Wrapper<Rpc.ResultFrom<Current, any>>
}

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