ShardId
The ShardId module models the address of a shard inside an Effect Cluster shard group. A shard id is made from a string group and numeric id, and the module gives that pair stable equality, hashing, primary-key behavior, schema support, and conversion to and from the group:id string form used by routing and storage boundaries.
Constructors
Converting
Decoding
fromString
Added in v4.0.0
Source
Parses a group:id string into a cached ShardId.
Details
Throws an Error when the string has no colon separator or the id segment is not numeric.
Signature
declare function fromString(s: string): ShardId;fromStringEncoded
Added in v4.0.0
Source
Parses a group:id string into plain shard id parts.
Details
Throws an Error when the string has no colon separator or the id segment is not numeric.
Signature
declare function fromStringEncoded(s: string): {
readonly group: string;
readonly id: number;
};Guards
Models
Identifier for a shard within a shard group, with equality, hashing, and primary key behavior based on the group:id string form.
Signature
interface ShardId extends Equal, Hash, PrimaryKey {
readonly "~effect/cluster/ShardId": "~effect/cluster/ShardId";
readonly group: string;
readonly id: number;
}
Creates or reuses the cached
ShardIdfor the specified shard group and numeric id.When to use
Use to create a
ShardIdwhen the shard group and numeric id are already known, such as after a routing decision or after decoding stored shard-id parts.Details
Repeated calls with the same
groupandidreturn the same cachedShardIdinstance. The returned value stores those fields, compares bygroupandid, formats asgroup:id, and uses that string form for hashing and primary keys.Gotchas
makedoes not compute a shard from an entity id or check whether the shard belongs to the current sharding configuration. Pass the shard group and numeric id produced by the routing or storage layer.See
toStringfor formatting an existing shard id asgroup:idfromStringfor constructing a cached shard id from thegroup:idstring form