// // Copyright 2025 DXOS.org // import { type BaseEchoObject, EntityKind, EntityKindId, RelationSourceId, RelationTargetId, type BaseObject, type RelationSourceTargetRefs, } from '@dxos/echo-schema'; import { invariant } from '@dxos/invariant'; import { type Live } from '@dxos/live-object'; import type { AnyLiveObject } from './echo-handler'; /** * @deprecated Use {@link @dxos/echo#Relation.Any} instead. */ export type AnyLiveRelation = Live & BaseEchoObject & RelationSourceTargetRefs; /** * @deprecated Use {@link @dxos/echo#Relation.isRelation} instead. */ export const isRelation = (object: AnyLiveObject): object is AnyLiveRelation => { const kind = (object as any)[EntityKindId]; if (kind === undefined) { throw new TypeError('Provided value is not a valid ECHO object or relation'); } return kind === EntityKind.Relation; }; /** * @deprecated Use {@link @dxos/echo#Relation.getSource} instead. * @returns Source ref from a relation. * @throws If the object is not a relation. */ export const getSource = (relation: AnyLiveObject): AnyLiveObject => { invariant(isRelation(relation)); const obj = relation[RelationSourceId]; invariant(obj !== undefined); return obj; }; /** * @deprecated Use {@link @dxos/echo#Relation.getTarget} instead. * @returns Target ref from a relation. * @throws If the object is not a relation. */ export const getTarget = (relation: AnyLiveObject): AnyLiveObject => { invariant(isRelation(relation)); const obj = relation[RelationTargetId]; invariant(obj !== undefined); return obj; };