1/**
2 * The `ShardingRegistrationEvent` module models the live notifications emitted
3 * by `Sharding` when the local runner registers an entity handler or singleton.
4 * Consumers can use these events to wait for registrations during startup,
5 * inspect which capabilities a runner made available, or assert registration
6 * behavior in tests.
7 *
8 * @stability unstable
9 * @since 4.0.0
10 */
11import * as Data from "../Data.ts"
12import type { Entity } from "./Entity.ts"
13import type { SingletonAddress } from "./SingletonAddress.ts"
14
15/**
16 * Represents events that can occur when a runner registers entities or singletons.
17 *
18 * @stability unstable
19 * @category models
20 * @since 4.0.0
21 */
22export type ShardingRegistrationEvent =
23 | EntityRegistered
24 | SingletonRegistered
25
26/**
27 * Represents an event that occurs when a new entity is registered with a runner.
28 *
29 * @stability unstable
30 * @category models
31 * @since 4.0.0
32 */
33export interface EntityRegistered {
34 readonly _tag: "EntityRegistered"
35 readonly entity: Entity<any, any>
36}
37
38/**
39 * Represents an event that occurs when a new singleton is registered with a
40 * runner.
41 *
42 * @stability unstable
43 * @category models
44 * @since 4.0.0
45 */
46export interface SingletonRegistered {
47 readonly _tag: "SingletonRegistered"
48 readonly address: SingletonAddress
49}
50
51/**
52 * Constructors and matchers for sharding registration events.
53 *
54 * @stability unstable
55 * @category pattern matching
56 * @since 4.0.0
57 */
58export const {
59 /**
60 * Pattern matches on a sharding registration event and dispatches to the
61 * matching variant handler.
62 *
63 * @stability unstable
64 * @category pattern matching
65 * @since 4.0.0
66 */
67 $match: match,
68 /**
69 * Creates an event for an entity registered by the local runner.
70 *
71 * @stability unstable
72 * @category constructors
73 * @since 4.0.0
74 */
75 EntityRegistered,
76 /**
77 * Creates an event for a singleton registered by the local runner.
78 *
79 * @stability unstable
80 * @category constructors
81 * @since 4.0.0
82 */
83 SingletonRegistered
84} = Data.taggedEnum<ShardingRegistrationEvent>()