Dotyc
API Reference

createWiring

Register consumers with declarative match criteria — tags, events, not — for pure parallel fan-out.

Creates the wiring: the registry that decides which consumers receive which events. You don't write an event-to-adapter table — you register consumers with match criteria, and every ingested event fans out to all consumers that match.

import { createWiring } from 'dotyc/ingest'

Signature

function createWiring<C extends Catalog>(catalog: C): Wiring<C>

interface Wiring<C> {
  use(
    consumer: DotycAdapter,
    match?: {
      tags?: readonly TagOf<C>[]
      events?: readonly EventNameOf<C>[]
      not?: { tags?: readonly TagOf<C>[]; events?: readonly EventNameOf<C>[] }
    }
  ): Wiring<C> // chainable
}

Match criteria

CriterionDescription
tagsMatch events whose definition carries any of these tags. Typed against the literal union of tags inferred from the catalog — a typo is a compile error.
eventsMatch by event name. Typed against the inferred union of event names.
notExclusions, same shape (tags / events).
(none)No criteria at all means the consumer receives every event.

Matchers are 100% declarative — there is no predicate function. This keeps the routing serializable and introspectable, so routing documentation can be generated from it.

Return value

A Wiring object; .use() returns it, so registrations chain. Pass it to createDispatcher.

Example

import { createWiring } from 'dotyc/ingest'
import { posthog } from '@dotyc/posthog'

const wiring = createWiring(catalog)
  .use(posthog({ apiKey: env.POSTHOG_KEY }), { tags: ['feature', 'marketing'] })
  .use(usageCounter, { events: ['feature_used'] })
  .use(traceLogger, { tags: ['trace'], not: { events: ['heartbeat'] } })
  .use(debugLog) // no criteria = everything

Notes

  • Fan-out is pure, parallel, and isolated. Every matching consumer receives the event; there is no ordered chain, no inter-consumer transformation, no blocking. A consumer that throws affects neither the other consumers nor the emitter (see onError on the dispatcher).
  • The wiring scales by intent, not by event. A new event tagged feature is automatically consumed by everything listening on feature — zero wiring edits.
  • Per-environment wiring is just JavaScript. There is no dedicated feature: an if (env) around a use() call, or two wiring files, is the pattern.
  • Unmatched events produce a warning in development and are silent in production; set strict: true on the dispatcher to turn them into errors.

See also

On this page