| 1 | /** |
| 2 | * The `EntityId` module defines the branded string used to identify one entity |
| 3 | * instance within an entity type. The value is the routing key that sharding |
| 4 | * hashes, stores in entity addresses, and uses when sending messages to a |
| 5 | * running entity. |
| 6 | * |
| 7 | * @stability unstable |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | import * as Schema from "../Schema.ts" |
| 11 | |
| 12 | /** |
| 13 | * Schema for branded string entity identifiers used inside the cluster. |
| 14 | * |
| 15 | * @stability unstable |
| 16 | * @category constructors |
| 17 | * @since 4.0.0 |
| 18 | */ |
| 19 | export const EntityId = Schema.String.pipe(Schema.brand("~effect/cluster/EntityId")) |
| 20 | |
| 21 | /** |
| 22 | * Branded string type representing the ID of an entity instance. |
| 23 | * |
| 24 | * @stability unstable |
| 25 | * @category models |
| 26 | * @since 4.0.0 |
| 27 | */ |
| 28 | export type EntityId = typeof EntityId.Type |
| 29 | |
| 30 | /** |
| 31 | * Brands a string as an `EntityId`. |
| 32 | * |
| 33 | * **When to use** |
| 34 | * |
| 35 | * Use to turn a trusted, stable entity routing key into an `EntityId` before |
| 36 | * passing it to cluster APIs. |
| 37 | * |
| 38 | * **Details** |
| 39 | * |
| 40 | * The branded value is the original string at runtime. |
| 41 | * |
| 42 | * **Gotchas** |
| 43 | * |
| 44 | * `make` does not validate, normalize, or make the value unique. Choose |
| 45 | * deterministic strings because cluster routing hashes the exact entity id |
| 46 | * value. |
| 47 | * |
| 48 | * @see {@link EntityId} for the schema that validates and encodes branded entity identifiers |
| 49 | * |
| 50 | * @stability unstable |
| 51 | * @category constructors |
| 52 | * @since 4.0.0 |
| 53 | */ |
| 54 | export const make = (id: string): EntityId => id as EntityId |