EdgeAIG's picture
download
raw
2.74 kB
/**
* The `EntityAddress` module defines the value used to locate an entity within
* a cluster. An address combines the entity type, entity id, and shard id so
* messages, persisted envelopes, workflow executions, and entity managers can
* agree on the same routing target.
*
* @since 4.0.0
*/
import * as Equal from "../../Equal.js";
import * as Hash from "../../Hash.js";
import * as Schema from "../../Schema.js";
import { EntityId } from "./EntityId.js";
import { EntityType } from "./EntityType.js";
import { ShardId } from "./ShardId.js";
const TypeId = "~effect/cluster/EntityAddress";
/**
* Represents the unique address of an entity within the cluster.
*
* @category models
* @since 4.0.0
*/
export class EntityAddress extends /*#__PURE__*/Schema.Class(TypeId)({
shardId: ShardId,
entityType: EntityType,
entityId: EntityId
}) {
/**
* Marks this value as a cluster entity address for runtime guards.
*
* @since 4.0.0
*/
[TypeId] = TypeId;
/**
* Formats the entity type, entity id, and shard id as a readable address.
*
* @since 4.0.0
*/
toString() {
return `EntityAddress(${this.entityType.toString()}, ${this.entityId.toString()}, ${this.shardId.toString()})`;
}
/**
* Compares entity addresses by entity type, entity id, and shard id.
*
* @since 4.0.0
*/
[Equal.symbol](that) {
return this.entityType === that.entityType && this.entityId === that.entityId && Equal.equals(this.shardId, that.shardId);
}
/**
* Computes a structural hash from the entity type, entity id, and shard id.
*
* @since 4.0.0
*/
[Hash.symbol]() {
return Hash.string(`${this.entityType}:${this.entityId}:${this.shardId.toString()}`);
}
}
/**
* Constructs an `EntityAddress` from a shard ID, entity type, and entity ID.
*
* **When to use**
*
* Use to create the routing target for a known entity type and entity id after
* resolving that id to the `ShardId` assigned by the entity's shard group.
*
* **Details**
*
* The returned `EntityAddress` stores the supplied `shardId`, `entityType`, and
* `entityId`. Equality and hashing include all three fields.
*
* **Gotchas**
*
* `make` does not choose the shard for an entity. Use the same shard group
* logic as the entity definition; a different `shardId` makes a different
* address even when the entity type and entity id match.
*
* @see {@link EntityAddress} for the equality, hashing, and string formatting behavior of constructed addresses
* @see {@link ShardId} for the shard identifier included in the address
*
* @category constructors
* @since 4.0.0
*/
export const make = options => new EntityAddress(options, {
disableChecks: true
});
//# sourceMappingURL=EntityAddress.js.map

Xet Storage Details

Size:
2.74 kB
·
Xet hash:
e7f4eefd611e5ea59d2e072548e0d992e72f3a52989520c50dca40e2b416f8bc

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.