refactor(ui): use asEntityId helper at piece-id boundaries
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
567480a788
commit
9960ea96cf
6 changed files with 79 additions and 7 deletions
|
|
@ -6,7 +6,7 @@ export type {
|
|||
SchemaKind,
|
||||
DefineSchemaOptions,
|
||||
} from "./schema.js";
|
||||
export { defineSchema, fact } from "./schema.js";
|
||||
export { asEntityId, defineSchema, fact } from "./schema.js";
|
||||
|
||||
export type { AttrKey, FactValue } from "./wm.js";
|
||||
export { WorkingMemory } from "./wm.js";
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@
|
|||
*/
|
||||
export type EntityId = number & { readonly __brand: "EntityId" };
|
||||
|
||||
/**
|
||||
* Coerce a raw number to the branded EntityId type. Use ONLY at trust
|
||||
* boundaries where you've already established that `n` came from
|
||||
* `Session.nextId()` or a fact's `id` field (e.g. UI code that carries
|
||||
* a piece's id as `number` because React prop serialization doesn't
|
||||
* preserve branding). Prefer passing `EntityId` through end-to-end when
|
||||
* possible; this helper is the single legitimate cast site.
|
||||
*/
|
||||
export const asEntityId = (n: number): EntityId => n as EntityId;
|
||||
|
||||
/**
|
||||
* Shape of a schema type parameter.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue