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

MessageRouter overview

Added in v0.1.0


Table of contents


combinators

append

Signature

export declare const append: {
  <R1, E1>(
    route: Route<E1, R1>
  ): <E, R>(self: MessageRouter<E, R>) => MessageRouter<E1 | E, R | MessageRouter.ExcludeProvided<R1>>
  <E, R, E1, R1>(
    self: MessageRouter<E, R>,
    route: Route<E1, R1>
  ): MessageRouter<E | E1, R | MessageRouter.ExcludeProvided<R1>>
}

Added in v1.0.0

catchAll

Signature

export declare const catchAll: {
  <E, E2, R2>(
    f: (e: E) => Route.Handler<E2, R2>
  ): <R>(self: MessageRouter<E, R>) => MessageRouter<E2, R | MessageRouter.ExcludeProvided<R2>>
  <E, R, E2, R2>(
    self: MessageRouter<E, R>,
    f: (e: E) => Route.Handler<E2, R2>
  ): MessageRouter<E2, R | MessageRouter.ExcludeProvided<R2>>
}

Added in v0.6.0

catchAllCause

Signature

export declare const catchAllCause: {
  <E, E2, R2>(
    f: (e: Cause.Cause<E>) => Route.Handler<E2, R2>
  ): <R>(self: MessageRouter<E, R>) => MessageRouter<E2, R | MessageRouter.ExcludeProvided<R2>>
  <E, R, E2, R2>(
    self: MessageRouter<E, R>,
    f: (e: Cause.Cause<E>) => Route.Handler<E2, R2>
  ): MessageRouter<E2, R | MessageRouter.ExcludeProvided<R2>>
}

Added in v0.6.0

catchTag

Signature

export declare const catchTag: {
  <K extends E extends { _tag: string } ? E["_tag"] : never, E, E1, R1>(
    k: K,
    f: (e: Extract<E, { _tag: K }>) => Route.Handler<E1, R1>
  ): <R>(
    self: MessageRouter<E, R>
  ) => MessageRouter<E1 | Exclude<E, { _tag: K }>, R | MessageRouter.ExcludeProvided<R1>>
  <E, R, K extends E extends { _tag: string } ? E["_tag"] : never, E1, R1>(
    self: MessageRouter<E, R>,
    k: K,
    f: (e: Extract<E, { _tag: K }>) => Route.Handler<E1, R1>
  ): MessageRouter<E1 | Exclude<E, { _tag: K }>, R | MessageRouter.ExcludeProvided<R1>>
}

Added in v0.6.0

catchTags

Signature

export declare const catchTags: {
  <
    E,
    Cases extends E extends { _tag: string }
      ? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | undefined }
      : {}
  >(
    cases: Cases
  ): <R>(
    self: MessageRouter<E, R>
  ) => MessageRouter<
    | Exclude<E, { _tag: keyof Cases }>
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
      }[keyof Cases],
    | R
    | MessageRouter.ExcludeProvided<
        {
          [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
        }[keyof Cases]
      >
  >
  <
    R,
    E,
    Cases extends E extends { _tag: string }
      ? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | undefined }
      : {}
  >(
    self: MessageRouter<E, R>,
    cases: Cases
  ): MessageRouter<
    | Exclude<E, { _tag: keyof Cases }>
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
      }[keyof Cases],
    | R
    | MessageRouter.ExcludeProvided<
        {
          [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
        }[keyof Cases]
      >
  >
}

Added in v0.6.0

concat

Signature

export declare const concat: {
  <R1, E1>(that: MessageRouter<E1, R1>): <E, R>(self: MessageRouter<E, R>) => MessageRouter<E1 | E, R1 | R>
  <E, R, R1, E1>(self: MessageRouter<E, R>, that: MessageRouter<E1, R1>): MessageRouter<E | E1, R | R1>
}

Added in v1.0.0

concatAll

Signature

export declare const concatAll: <Routers extends ReadonlyArray<MessageRouter<unknown, unknown>>>(
  ...routers: Routers
) => [Routers[number]] extends [MessageRouter<infer E, infer R>] ? MessageRouter<E, R> : never

Added in v1.0.0

provideService

Signature

export declare const provideService: {
  <T extends Context.Tag<any, any>>(
    tag: T,
    service: Context.Tag.Service<T>
  ): <E, R>(self: MessageRouter<E, R>) => MessageRouter<E, Exclude<R, Context.Tag.Identifier<T>>>
  <E, R, T extends Context.Tag<any, any>>(
    self: MessageRouter<E, R>,
    tag: T,
    service: Context.Tag.Service<T>
  ): MessageRouter<E, Exclude<R, Context.Tag.Identifier<T>>>
}

Added in v0.6.0

provideServiceEffect

Signature

export declare const provideServiceEffect: {
  <T extends Context.Tag<any, any>, R1, E1>(
    tag: T,
    effect: Effect.Effect<Context.Tag.Service<T>, E1, R1>
  ): <E, R>(
    self: MessageRouter<E, R>
  ) => MessageRouter<
    E1 | E,
    Exclude<R, Context.Tag.Identifier<T>> | Exclude<MessageRouter.ExcludeProvided<R1>, Context.Tag.Identifier<T>>
  >
  <E, R, T extends Context.Tag<any, any>, R1, E1>(
    self: MessageRouter<E, R>,
    tag: T,
    effect: Effect.Effect<Context.Tag.Service<T>, E1, R1>
  ): MessageRouter<
    E | E1,
    Exclude<R, Context.Tag.Identifier<T>> | Exclude<MessageRouter.ExcludeProvided<R1>, Context.Tag.Identifier<T>>
  >
}

Added in v0.6.0

transform

Signature

export declare const transform: {
  <E, R, R1, E1>(
    f: (self: Route.Handler<E, R>) => App.Default<E1, R1>
  ): (self: MessageRouter<E, R>) => MessageRouter<E1, MessageRouter.ExcludeProvided<R1>>
  <E, R, R1, E1>(
    self: MessageRouter<E, R>,
    f: (self: Route.Handler<E, R>) => App.Default<E1, R1>
  ): MessageRouter<E1, MessageRouter.ExcludeProvided<R1>>
}

Added in v0.6.0

constructors

empty

Signature

export declare const empty: MessageRouter<never, never>

Added in v0.1.0

fromIterable

Signature

export declare const fromIterable: <R extends Route<any, any>>(
  routes: Iterable<R>
) => MessageRouter<R extends Route<infer E, infer _> ? E : never, R extends Route<infer _, infer Env> ? Env : never>

Added in v0.1.0

makeRoute

Signature

export declare const makeRoute: <E, R>(
  topic: Route.Path,
  handler: Route.Handler<E, R>
) => Route<E, MessageRouter.ExcludeProvided<R>>

Added in v0.1.0

models

MessageRouter (interface)

Signature

export interface MessageRouter<E = never, R = never> extends App.Default<E, R>, Inspectable.Inspectable {
  readonly [TypeId]: TypeId
  readonly routes: Chunk.Chunk<Route<E, R>>
}

Added in v0.1.0

Route (interface)

Signature

export interface Route<E = never, R = never> {
  readonly [RouteTypeId]: RouteTypeId
  readonly topic: Route.Path
  readonly handler: Route.Handler<E, R>
}

Added in v0.1.0

routing

subscribe

Signature

export declare const subscribe: {
  <E1, R1>(
    topic: Route.Path,
    handler: Route.Handler<E1, R1>
  ): <E, R>(self: MessageRouter<E, R>) => MessageRouter<E1 | E, R | MessageRouter.ExcludeProvided<R1>>
  <E, R, E1, R1>(
    self: MessageRouter<E, R>,
    topic: Route.Path,
    handler: Route.Handler<E1, R1>
  ): MessageRouter<E | E1, R | MessageRouter.ExcludeProvided<R1>>
}

Added in v0.1.0

tags

Default (class)

Signature

export declare class Default

Added in v0.6.0

Tag

Signature

export declare const Tag: <const Name extends string>(
  id: Name
) => <Self, R = never, E = unknown>() => MessageRouter.TagClass<Self, Name, E, R>

Added in v0.6.0

type ids

RouteTypeId

Signature

export declare const RouteTypeId: typeof RouteTypeId

Added in v0.1.0

RouteTypeId (type alias)

Signature

export type RouteTypeId = typeof RouteTypeId

Added in v0.1.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v0.1.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v0.1.0

utils

MessageRouter (namespace)

Added in v0.1.0

Service (interface)

Signature

export interface Service<E, R> {
  readonly router: Effect.Effect<MessageRouter<E, R>>
  readonly addRoute: (route: Route<E, R>) => Effect.Effect<void>
  readonly subscribe: (path: Route.Path, handler: Route.Handler<E, R | Provided>) => Effect.Effect<void>
  readonly concat: (router: MessageRouter<E, R>) => Effect.Effect<void>
}

Added in v0.1.0

TagClass (interface)

Signature

export interface TagClass<Self, Name extends string, E, R> extends Context.Tag<Self, Service<E, R>> {
  readonly Live: Layer.Layer<Self>
  readonly router: Effect.Effect<MessageRouter<E, R>, never, Self>
  readonly use: <XA, XE, XR>(f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>) => Layer.Layer<never, XE, XR>
  readonly useScoped: <XA, XE, XR>(
    f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>
  ) => Layer.Layer<never, XE, Exclude<XR, Scope.Scope>>
  readonly unwrap: <XA, XE, XR>(f: (router: MessageRouter<E, R>) => Layer.Layer<XA, XE, XR>) => Layer.Layer<XA, XE, XR>
  new (_: never): Context.TagClassShape<Name, Service<E, R>>
}

Added in v0.1.0

ExcludeProvided (type alias)

Signature

export type ExcludeProvided<A> = Exclude<A, Provided>

Added in v0.1.0

Provided (type alias)

Signature

export type Provided = ConsumerRecord.ConsumerRecord | Scope.Scope

Added in v0.1.0

Route (namespace)

Added in v0.1.0

Handler (type alias)

Signature

export type Handler<E, R> = App.Default<E, R>

Added in v0.1.0

Path (type alias)

Signature

export type Path = string | RegExp

Added in v0.2.0