{
  "version": 3,
  "sources": ["../../../src/Database.ts", "../../../src/internal/Entity/type-uri.ts", "../../../src/internal/Annotation/annotations.ts", "../../../src/internal/common/types/model-symbols.ts", "../../../src/internal/common/types/typename.ts", "../../../src/internal/Annotation/dictionary.ts", "../../../src/internal/Entity/api.ts", "../../../src/internal/Entity/model.ts", "../../../src/internal/Entity/util.ts"],
  "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Effectable from 'effect/Effectable';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { EffectEx } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId, type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { type AnyProperties, EntityKind, KindId } from './internal/common/types';\n// Deep import (not the `./internal/Entity` barrel) to avoid a cycle:\n// Database → internal/Entity → entity → JsonSchema → Ref → Database.\nimport { isInstanceOf } from './internal/Entity/type-uri';\nimport type { Ref } from './internal/Ref/ref';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as Registry from './Registry';\nimport type * as Type from './Type';\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\nexport interface QueryFn {\n  <Q extends Query.Any>(query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n  <F extends Filter.Any>(filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database, Feed, and Hypergraph.\n */\nexport interface Queryable {\n  query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n  deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n  /**\n   * Where to place the object in the Automerge document tree.\n   * Root document is always loaded with the space.\n   * Linked documents are loaded lazily.\n   * Placing large number of objects in the root document may slow down the initial load.\n   *\n   * @default 'linked-doc'\n   */\n  placeIn?: ObjectPlacement;\n};\n\n/**\n * Rejects Type entities from {@link Database.add} at compile time via their `[KindId]` brand. Used\n * as `T & RejectTypeEntity<T>` to preserve inference of `T`. Bounding `add` on\n * `Obj.Unknown | Relation.Unknown` instead would reject broadly-typed instance adds (e.g.\n * `Entity.Any`, `Obj.OfShape<T>`), forcing casts repo-wide.\n */\nexport type RejectTypeEntity<T> = T extends { readonly [KindId]: EntityKind.Type }\n  ? { __error: 'Type entities must be persisted via db.addType(), not db.add().' }\n  : T;\n\nexport type FlushOptions = {\n  /**\n   * Write any pending changes to disk.\n   * @default true\n   */\n  disk?: boolean;\n\n  /**\n   * Wait for pending index updates.\n   * @default true\n   */\n  indexes?: boolean;\n\n  /**\n   * Flush pending updates to objects and queries.\n   * @default false\n   */\n  updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n  readonly [TypeId]: TypeId;\n\n  get spaceId(): SpaceId;\n\n  get graph(): Hypergraph.Hypergraph;\n\n  /**\n   * Registry for this database. Delegates type lookups to the shared hypergraph registry.\n   * To persist a schema so it replicates to other clients, add the type entity with\n   * {@link addType} (e.g. `await db.addType(Type.makeObjectFromJsonSchema(...))`).\n   */\n  readonly registry: Registry.Registry;\n\n  toJSON(): object;\n\n  /**\n   * Return object by local ID.\n   * @deprecated Use `db.query(Filter.id(id)).runSync()[0]` for a working-set lookup, or resolve via a {@link Ref}.\n   */\n  getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(\n    id: string,\n    opts?: GetObjectByIdOptions,\n  ): T | undefined;\n\n  /**\n   * Query objects.\n   */\n  query: QueryFn;\n\n  /**\n   * Creates a reference to an existing object in the database.\n   *\n   * NOTE: The reference may be dangling if the object is not present in the database.\n   * NOTE: Difference from `Ref.fromURI`\n   * `Ref.fromURI(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n   * `db.makeRef(dxn)` is preferable in cases with access to the database.\n   */\n  makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref<T>;\n\n  /**\n   * Adds an object or relation to the database.\n   *\n   * Only Object and Relation entities are accepted. To persist a Type definition use\n   * {@link addType} — passing a Type entity is rejected at compile time (and at runtime).\n   */\n  add<T extends Entity.Unknown = Entity.Unknown>(obj: T & RejectTypeEntity<T>, opts?: AddOptions): T;\n\n  /**\n   * Persists a Type definition (clones/forks the entity) so it replicates to other peers.\n   *\n   * Runs a conflict query first: if a type with the same typename + version already exists in\n   * this space, the existing persisted entity is returned and no duplicate is created. This is\n   * the only supported way to add Type entities — {@link add} rejects them.\n   */\n  addType<T extends Type.AnyEntity>(type: T): Promise<T>;\n\n  /**\n   * Removes object from the database.\n   */\n  // TODO(burdon): Return true if removed (currently throws if not present).\n  remove(obj: Entity.Unknown): void;\n\n  /**\n   * Wait for all pending changes to be saved to disk.\n   * Optionaly waits for changes to be propagated to indexes and event handlers.\n   */\n  flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n  return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n  Service,\n  {\n    readonly db: Database;\n  }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n  get db(): Database {\n    throw new Error('Database not available');\n  },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n  return {\n    get db() {\n      return db;\n    },\n  };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n  return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n  const { db } = yield* Service;\n  return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n  // No type check.\n  (ref: URI.URI | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n  // Check matches schema.\n  <S extends Type.AnyEntity>(\n    ref: URI.URI | Ref<any>,\n    schema: S,\n  ): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service>;\n} = (<S extends Type.AnyEntity>(\n  ref: URI.URI | Ref<any>,\n  schema?: S,\n): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service> =>\n  Effect.gen(function* () {\n    const { db } = yield* Service;\n    const dxn = typeof ref === 'string' ? ref : ref.uri;\n    const object = yield* EffectEx.promiseWithCauseCapture(() =>\n      db.graph\n        .createRefResolver({\n          context: {\n            space: db.spaceId,\n          },\n        })\n        .resolve(dxn),\n    );\n\n    if (!object) {\n      return yield* Effect.fail(new Err.EntityNotFoundError(dxn));\n    }\n    // `isInstanceOf` uses a conditional generic that TS can't resolve through\n    // the local `S extends Type.AnyEntity` parameter — runtime accepts it fine.\n    invariant(!schema || isInstanceOf(schema as any, object), 'Object type mismatch.');\n    return object as any;\n  }).pipe(Effect.withSpan('Database.resolve'))) as any;\n\n/**\n * Loads an object reference.\n *\n * Catching not found error:\n *\n * ```ts\n * yield* load(ref).pipe(Effect.catchTag('EntityNotFoundError', () => Effect.succeed(undefined)));\n * ```\n *\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.EntityNotFoundError, never> = Effect.fn('Database.load')(\n  function* (ref) {\n    const object = yield* EffectEx.promiseWithCauseCapture(() => ref.tryLoad());\n    if (!object) {\n      return yield* Effect.fail(new Err.EntityNotFoundError(ref.uri));\n    }\n    return object;\n  },\n);\n\n/**\n * Adds an object or relation to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T & RejectTypeEntity<T>): Effect.Effect<T, never, Service> =>\n  Service.pipe(Effect.map(({ db }) => db.add<T>(obj))).pipe(Effect.withSpan('Database.add'));\n\n/**\n * Persists a Type definition to the database.\n * @see {@link Database.addType}\n */\nexport const addType = <T extends Type.AnyEntity>(type: T): Effect.Effect<T, never, Service> =>\n  Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.addType(type)))).pipe(\n    Effect.withSpan('Database.addType'),\n  );\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n  Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan('Database.remove'));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n  Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.flush(opts)))).pipe(\n    Effect.withSpan('Database.flush'),\n  );\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n  <Q extends Query.Any>(query: Q): QueryResult.QueryResultEffect<Query.Type<Q>, never, Service>;\n  <F extends Filter.Any>(filter: F): QueryResult.QueryResultEffect<Filter.Type<F>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n  Service.pipe(\n    Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n    Effect.withSpan('Database.query'),\n    makeQueryResultEffect,\n  );\n\nconst makeQueryResultEffect = <T>(\n  eff: Effect.Effect<QueryResult.QueryResult<T>, never, Service>,\n): QueryResult.QueryResultEffect<T, never, Service> => {\n  return {\n    run: Effect.flatMap(eff, (result) => EffectEx.promiseWithCauseCapture(() => result.run())),\n    first: Effect.flatMap(eff, (result) =>\n      EffectEx.promiseWithCauseCapture(async () => Option.fromNullable(await result.firstOrUndefined())),\n    ),\n\n    // Effect internals\n    ...Effectable.CommitPrototype,\n    commit() {\n      return eff;\n    },\n  } as any;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN, EID, URI } from '@dxos/keys';\n\nimport { getSchemaURI, getTypename } from '../Annotation/annotations';\nimport { type AnyEntity, InstancePhantomId, KindId, TypeId, getStaticTypeSchema } from '../common/types';\nimport { getUri as getUriFromEntity } from './api';\n\n/**\n * @param input schema, `Type.Type` entity, or a type URI (an `echo:` EID or a `dxn:` DXN).\n * @return type identifier URI — see {@link getSchemaURI}. A URI is returned verbatim. For a\n * `Type.Type` entity, the URI of the schema it declares, symmetric with what\n * `Obj.make(typeEntity, ...)` stamps on `system.type`: a static declaration resolves to its\n * typename DXN, a persisted entity to its local `echo:/<objectId>`.\n */\nexport const getTypeURIFromSpecifier = (input: Schema.Schema.All | AnyEntity | URI.URI): URI.URI => {\n  if (Schema.isSchema(input)) {\n    return getSchemaURI(input) ?? raise(new TypeError('Schema has no URI'));\n  }\n  if (typeof input === 'object' && input !== null && KindId in input) {\n    // `Type.Type` entity. Both in-memory and persisted forms expose the schema\n    // they declare via `StaticTypeSchemaSlot`, whose URI is exactly what\n    // `Obj.make` stamps on `system.type` — a static declaration carries\n    // `TypeAnnotation` (→ typename DXN), a persisted entity's rebuilt schema\n    // carries `TypeIdentifierAnnotation` (→ local `echo:/<objectId>`).\n    const schema = getStaticTypeSchema(input);\n    if (schema != null) {\n      // Static types carry TypeAnnotation → DXN; persisted db types carry\n      // TypeIdentifierAnnotation → echo EID. In-memory makeObjectFromJsonSchema\n      // entities have neither (plain JSON Schema), so fall through to the EID path.\n      const uri = getSchemaURI(schema);\n      if (uri != null) {\n        return uri;\n      }\n    }\n    return getUriFromEntity(input as AnyEntity);\n  }\n  // A string specifier is already a branded URI — an `echo:` EID or a `dxn:` DXN.\n  assertArgument(EID.isEID(input) || DXN.isDXN(input), 'input', 'expected a type URI (EID or DXN)');\n  return input;\n};\n\n/**\n * Checks if the object is an instance of the schema.\n * Only typename is compared, the schema version is ignored.\n *\n * The following cases are considered to mean that the object is an instance of the schema:\n *  - Object was created with this exact schema.\n *  - Object was created with a different version of this schema.\n *  - Object was created with a different schema (maybe dynamic) that has the same typename.\n */\n// TODO(burdon): Can we use `Schema.is`?\nexport const isInstanceOf = <S>(\n  schemaOrType: S extends Schema.Schema.AnyNoContext ? S : Schema.Schema.AnyNoContext | AnyEntity,\n  object: any,\n): object is S extends Schema.Schema.AnyNoContext\n  ? Schema.Schema.Type<S>\n  : S extends { readonly [InstancePhantomId]?: infer A }\n    ? A\n    : unknown => {\n  if (object == null) {\n    return false;\n  }\n\n  const schemaURI = getTypeURIFromSpecifier(schemaOrType);\n\n  // `object` is arbitrary input — read TypeId directly (it may be missing on\n  // non-entities) rather than via `getTypeURI` which asserts the URI is set.\n  const type = (object as any)[TypeId];\n  if (URI.isURI(type) && type === schemaURI) {\n    return true;\n  }\n\n  const typename = getTypename(object);\n  if (!typename) {\n    return false;\n  }\n\n  if (!DXN.isDXN(schemaURI)) {\n    // EID-based schema URI — no typename match possible.\n    return false;\n  }\n\n  const parsed = DXN.tryMake(schemaURI);\n  return parsed != null && DXN.getName(parsed) === typename;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { SchemaEx } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, URI } from '@dxos/keys';\nimport { type Primitive } from '@dxos/util';\n\nimport type * as Annotation from '../../Annotation';\nimport { type Mutable } from '../common/proxy';\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';\nimport { createAnnotationHelper } from './util';\n\nconst ANNOTATION_TYPE_ID: Annotation.TypeId = '~@dxos/echo/Annotation' as const;\n\n/**\n * @internal\n */\nexport const FIELD_PATH_ANNOTATION = 'path';\n\n/**\n * Sets the path for the field.\n * @param path Data source path in the json path format. This is the field path in the source object.\n */\n// TODO(burdon): Field, vs. path vs. property.\nexport const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);\n\n//\n// Type\n//\n\n/**\n * ECHO identifier (for a stored schema).\n * Must be an `echo:` URI.\n */\nexport const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');\n\nexport const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>\n  Function.flow(\n    SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),\n    Option.getOrElse(() => undefined),\n  )(schema.ast);\n\n/**\n * @returns The schema's type identifier URI — whichever URI fits.\n *\n * - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride\n *   along with their schema as a strong dependency.\n * - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.\n *\n * This URI is what gets written to an object's `system.type`; queries that filter by\n * type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides\n * stay symmetric without per-schema branching.\n */\nexport const getSchemaURI = (schema: Schema.Schema.All): URI.URI | undefined => {\n  assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');\n  const id = getTypeIdentifierAnnotation(schema);\n  if (id) {\n    return URI.make(id);\n  }\n  const objectAnnotation = getTypeAnnotation(schema);\n  if (objectAnnotation) {\n    return DXN.make(objectAnnotation.typename, objectAnnotation.version);\n  }\n  return undefined;\n};\n\n//\n// TypeAnnotation\n//\n\n/**\n * Fully qualified globally unique typename.\n * Example: `org.dxos.type.message`\n */\n// TODO(wittjosiah): Factor out to DXN spec.\nexport const TypenameSchema = Schema.String.pipe(\n  Schema.pattern(\n    /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/,\n  ),\n).annotations({\n  description: 'Fully qualified globally unique typename in reverse-DNS form.',\n  example: 'org.dxos.type.message',\n});\n\n/**\n * Semantic version format: `major.minor.patch`\n * Example: `1.0.0`\n */\nexport const VersionSchema = Schema.String.pipe(Schema.pattern(/^\\d+.\\d+.\\d+$/)).annotations({\n  description: 'Semantic version format: `major.minor.patch`',\n  example: '1.0.0',\n});\n\nexport const TypeMeta = Schema.Struct({\n  typename: TypenameSchema,\n  version: VersionSchema,\n});\n\nexport interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}\n\n/**\n * Entity type.\n */\nexport const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');\n\n/**\n * Payload stored under {@link TypeAnnotationId}.\n */\nexport const TypeAnnotation = Schema.extend(\n  TypeMeta,\n  Schema.Struct({\n    kind: Schema.Enums(EntityKind),\n\n    /**\n     * If this is a relation, the schema of the source object.\n     * Must be present if entity kind is {@link EntityKind.Relation}.\n     */\n    sourceSchema: Schema.optional(DXN.Schema),\n\n    /**\n     * If this is a relation, the schema of the target object.\n     * Must be present if entity kind is {@link EntityKind.Relation}.\n     */\n    targetSchema: Schema.optional(DXN.Schema),\n  }),\n);\n\nexport interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}\n\n/**\n * @returns {@link TypeAnnotation} from a schema.\n * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.\n */\nexport const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {\n  assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');\n  return Function.flow(\n    SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),\n    Option.getOrElse(() => undefined),\n  )(schema.ast);\n};\n\n/**\n * @returns {@link EntityKind} from a schema.\n */\nexport const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;\n\n/**\n * @internal\n * @returns Schema typename (without dxn: prefix or version number).\n */\nexport const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;\n\n/**\n * @internal\n * @returns Schema version in semver format.\n */\nexport const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;\n\n/**\n * Gets the typename of the object without the version.\n * Returns only the name portion, not the DXN.\n * @example \"org.example.type.contact\"\n *\n * @internal (use Obj.getTypename)\n */\nexport const getTypename = (obj: AnyProperties): string | undefined => {\n  const schema = getSchema(obj);\n  if (schema != null) {\n    // Try to extract typename from DXN.\n    return getSchemaTypename(schema);\n  } else {\n    // `obj` may be an arbitrary value (e.g. from `isInstanceOf`); read TypeId\n    // directly so we return undefined for non-entities instead of throwing.\n    const type = (obj as any)?.[TypeId];\n    // Parse the URI string to extract typename.\n    if (DXN.isDXN(type)) {\n      const parsed = DXN.tryMake(type);\n      return parsed && DXN.getName(parsed);\n    }\n    return undefined;\n  }\n};\n\n/**\n * @internal (use Type.setTypename)\n */\n// TODO(dmaretskyi): Rename setTypeDXN.\nexport const setTypename = (obj: any, typename: URI.URI): void => {\n  assertArgument(typeof typename === 'string', 'typename', 'Invalid type.');\n  Object.defineProperty(obj, TypeId, {\n    value: typename,\n    writable: false,\n    enumerable: false,\n    configurable: false,\n  });\n};\n\n/**\n * @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.\n * @returns undefined if the object has no registered type URI (e.g. unresolved query result).\n * @example `dxn:com.example.type.person:1.0.0`\n * @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)\n *\n * @internal (use Obj.getTypeURI)\n */\nexport const getTypeURI = (obj: AnyProperties): URI.URI | undefined => {\n  if (obj == null) {\n    return undefined;\n  }\n  const type = (obj as any)[TypeId];\n  if (type == null) {\n    return undefined;\n  }\n  invariant(URI.isURI(type), 'Invalid object.');\n  return type;\n};\n\n//\n// PropertyMeta\n//\n\n/**\n * PropertyMeta (metadata for dynamic schema properties).\n * For user-defined annotations.\n */\nexport const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');\n\nexport type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];\n\nexport type PropertyMetaAnnotation = {\n  [name: string]: PropertyMetaValue;\n};\n\n// TODO(wittjosiah): Align with other annotations.\n// TODO(wittjosiah): Why is this separate from FormatAnnotation?\n/**\n * Apply property-level metadata to an Effect schema. Only accepts\n * `Schema.Schema.Any` — apply BEFORE wrapping the schema with\n * `Type.makeObject` / `Type.makeRelation`. To read property meta off a\n * `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.\n */\nexport const PropertyMeta = (name: string, value: PropertyMetaValue) => {\n  return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {\n    const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;\n    return self.annotations({\n      [PropertyMetaAnnotationId]: {\n        ...existingMeta,\n        [name]: value,\n      },\n    });\n  };\n};\n\nexport const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>\n  Function.pipe(\n    SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),\n    Option.map((meta) => meta[name] as T),\n    Option.getOrElse(() => undefined),\n  );\n\n//\n// Reference\n//\n\n/**\n * Schema reference.\n */\nexport const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');\nexport type ReferenceAnnotationValue = TypeAnnotation;\nexport const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);\n\n/**\n * SchemaMeta.\n */\nexport const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');\nexport type SchemaMeta = TypeMeta & { id: string };\n\n/**\n * Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).\n */\nexport const HiddenAnnotationId = Symbol.for('@dxos/schema/annotation/Hidden');\nexport const HiddenAnnotation = createAnnotationHelper<boolean>(HiddenAnnotationId);\n\n/**\n * Identifies label property or JSON path expression.\n * Either a string or an array of strings representing field accessors each matched in priority order.\n */\nexport const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');\nexport const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);\n\n/**\n * Returns the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n * Skips empty strings and whitespace-only strings, continuing to the next field.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getLabelWithSchema = <S extends Schema.Schema.Any>(\n  schema: S,\n  object: Schema.Schema.Type<S>,\n): string | undefined => {\n  const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));\n  for (const accessor of annotation) {\n    assertArgument(\n      typeof accessor === 'string',\n      'accessor',\n      'Label annotation must be a string or an array of strings',\n    );\n    const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n    switch (typeof value) {\n      case 'string': {\n        const trimmed = value.trim();\n        if (trimmed.length > 0) {\n          return value;\n        }\n        continue;\n      }\n      case 'number':\n      case 'boolean':\n      case 'bigint':\n      case 'symbol':\n        return value.toString();\n      case 'undefined':\n      case 'object':\n      case 'function':\n        continue;\n    }\n  }\n\n  return undefined;\n};\n\n/**\n * Sets the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setLabelWithSchema = <S extends Schema.Schema.Any>(\n  schema: S,\n  object: Schema.Schema.Type<S>,\n  label: string,\n) => {\n  const annotation = LabelAnnotation.get(schema).pipe(\n    Option.map((field) => field[0]),\n    Option.getOrElse(() => 'name'),\n  );\n  object[annotation] = label;\n};\n\n/**\n * Identifies description property or JSON path expression.\n * A string representing field accessor.\n */\nexport const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');\nexport const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);\n\n/**\n * Returns the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getDescriptionWithSchema = <S extends Schema.Schema.Any>(\n  schema: S,\n  object: Schema.Schema.Type<S>,\n): string | undefined => {\n  const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n  assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');\n  const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n  switch (typeof value) {\n    case 'string':\n    case 'number':\n    case 'boolean':\n    case 'bigint':\n    case 'symbol':\n      return value.toString();\n    case 'undefined':\n    case 'object':\n    case 'function':\n    default:\n      return undefined;\n  }\n};\n\n/**\n * Sets the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setDescriptionWithSchema = <S extends Schema.Schema.Any>(\n  schema: S,\n  object: Schema.Schema.Type<S>,\n  description: string,\n) => {\n  const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n  object[accessor] = description;\n};\n\n/**\n * Identifies if a property should be included in a form or not.\n * By default, all properties are included in forms, so this is opt-out.\n */\nexport const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');\nexport const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);\n\n/**\n * When set on a `Ref` property, the form renders the referenced object's own\n * fields inline (a nested form bound to the target) instead of a picker.\n */\nexport const FormInlineAnnotationId = Symbol.for('@dxos/schema/annotation/FormInline');\nexport const FormInlineAnnotation = createAnnotationHelper<boolean>(FormInlineAnnotationId);\n\n/**\n * Default field to be used on referenced schema to lookup the value.\n */\nexport const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');\n\n/**\n * Generate test data.\n */\nexport const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');\n\nexport type GeneratorAnnotationValue =\n  | string\n  | {\n      generator: string;\n      args?: any[];\n      probability?: number;\n    };\n\nexport const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);\n\ninterface MakeAnnoationsProps<T> {\n  id: string;\n  schema: Schema.Schema<T, any, never>;\n}\n\n// Annotation ids use the same NSID / reverse-DNS format as TypenameSchema —\n// dot-separated segments, middle segments may be hyphenated, final segment may be camelCase.\n// At least 3 segments are required (e.g. org.dxos.annotation.example).\nexport const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): Annotation.Annotation<T> => {\n  assertArgument(\n    /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){2,}(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)?$/.test(\n      props.id,\n    ),\n    'id',\n    'Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).',\n  );\n\n  const annotation: Annotation.Annotation<T> = {\n    [ANNOTATION_TYPE_ID]: { _Type: {} as T },\n    key: props.id as Annotation.Key,\n    schema: props.schema,\n    get: (schema) => getFromAst(schema.ast, annotation),\n    getFromAst: (ast) => getFromAst(ast, annotation),\n    set: (value) =>\n      PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) => S,\n  };\n\n  return annotation;\n};\n\nconst IconAnnotationSchema = Schema.Struct({\n  /**\n   * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)\n   */\n  icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),\n\n  /**\n   * Color name.\n   *\n   * List of colors:\n   *  - 'red'\n   *  - 'orange'\n   *  - 'amber'\n   *  - 'yellow'\n   *  - 'lime'\n   *  - 'green'\n   *  - 'emerald'\n   *  - 'teal'\n   *  - 'cyan'\n   *  - 'violet'\n   *  - 'purple'\n   *  - 'fuchsia'\n   *  - 'pink'\n   *  - 'rose'\n   */\n  hue: Schema.optional(Schema.String),\n});\n\nexport interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}\n\n/**\n * Icon to render in the UI.\n */\nexport const IconAnnotation = makeUserAnnotation<IconAnnotation>({\n  id: 'org.dxos.annotation.icon',\n  schema: IconAnnotationSchema,\n});\n\n/**\n * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`\n * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that\n * target's schema `IconAnnotation` in place of the static one declared on this schema.\n *\n * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity\n * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).\n */\nexport const IconFromRefAnnotation = makeUserAnnotation<string>({\n  id: 'org.dxos.annotation.icon.from-ref',\n  schema: Schema.String,\n});\n\n/**\n * Options for {@link getLabel}.\n */\nexport type GetLabelOptions = {\n  /**\n   * Strategy for deriving a label when the entity has no `LabelAnnotation` value.\n   * - `'typename'`: use the entity's typename (e.g. `org.dxos.type.table`).\n   *   Useful for Card.Title chrome that must always display something, even\n   *   for unlabeled objects.\n   */\n  fallback?: 'typename';\n};\n\n/**\n * Get the label of an entity.\n * Accepts both reactive entities and snapshots.\n *\n * If `options.fallback === 'typename'` and no label is set, returns the\n * entity's typename instead.\n */\nexport const getLabel = (entity: AnyProperties, options?: GetLabelOptions): string | undefined => {\n  const schema = getSchema(entity);\n  const label = schema != null ? getLabelWithSchema(schema, entity) : undefined;\n  if (label != null) {\n    return label;\n  }\n  if (options?.fallback === 'typename') {\n    return getTypename(entity);\n  }\n  return undefined;\n};\n\n/**\n * Set the label of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setLabel = (entity: Mutable<AnyProperties>, label: string) => {\n  const schema = getSchema(entity);\n  if (schema != null) {\n    setLabelWithSchema(schema, entity, label);\n  }\n};\n\n/**\n * Get the description of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDescription = (entity: AnyProperties): string | undefined => {\n  const schema = getSchema(entity);\n  if (schema != null) {\n    return getDescriptionWithSchema(schema, entity);\n  }\n};\n\n/**\n * Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.\n * Accepts both reactive entities and snapshots.\n *\n * Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon\n * name and the suggested colour. Callers wanting just the icon name typically write\n * `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.\n *\n * Note: this is the \"static\" icon from the object's own schema. It does not follow\n * `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node\n * builders) should resolve the ref themselves.\n */\nexport const getIcon = (entity: AnyProperties): IconAnnotation | undefined => {\n  const schema = getSchema(entity);\n  if (schema == null) {\n    return undefined;\n  }\n  return Option.getOrUndefined(IconAnnotation.get(schema));\n};\n\n/**\n * Set the description of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setDescription = (entity: Mutable<AnyProperties>, description: string) => {\n  const schema = getSchema(entity);\n  if (schema != null) {\n    setDescriptionWithSchema(schema, entity, description);\n  }\n};\n\nexport { Dictionary, Key, getDictionary, setDictionary } from './dictionary';\n\nexport const getFromAst = <T>(ast: SchemaAST.AST, annotation: Annotation.Annotation<T>): Option.Option<T> => {\n  return SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n    Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])),\n    Option.map(Schema.decodeUnknownSync(annotation.schema)),\n  );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(rename): These internal entity-wide symbols/types still use the `Object*` prefix but apply\n// to all entities (objects AND relations). Rename to `Entity*` in a follow-up pass (deferred from the\n// EchoURI→EID / ObjectId→EntityId / ObjectMeta→EntityMeta rename, which covered only public SDK API):\n//   ObjectCore, ObjectInternals, ObjectVersion, ObjectVersionId, ObjectDeletedId, ObjectDatabaseId,\n//   ObjectLoader, ObjectDocumentLoaded, ObjectUnavailable.\n// (ObjectMigration / ObjectMigrationContext intentionally excluded — object-only, not entity-wide.)\n\n/**\n * Internal symbol/string constants for the echo object model.\n * Defined in common/ so proxy/ can use them without importing from Entity/.\n * Entity/ re-exports these for external consumers.\n */\n\n/**\n * Property name for the object's own URI when serialized to JSON.\n */\nexport const ATTR_SELF_URI = '@uri';\n\n/**\n * @deprecated Legacy JSON property name accepted on read for backward compat.\n */\nexport const ATTR_SELF_URI_LEGACY = '@dxn';\n\n/**\n * Symbol carrying the object's own URI on live entities.\n */\nexport const SelfURIId = Symbol.for('@dxos/echo/URI');\n\n/**\n * Property name for deleted when object is serialized to JSON.\n */\nexport const ATTR_DELETED = '@deleted';\n\n/**\n * Deletion marker.\n */\nexport const ObjectDeletedId = Symbol.for('@dxos/echo/Deleted');\n\n/**\n * Object version accessor symbol.\n */\nexport const ObjectVersionId: unique symbol = Symbol.for('@dxos/echo/Version');\n\n/**\n * Object database accessor symbol.\n */\nexport const ObjectDatabaseId = Symbol.for('@dxos/echo/Database');\n\n/**\n * Property name for relation source when object is serialized to JSON.\n */\nexport const ATTR_RELATION_SOURCE = '@relationSource';\n\n/**\n * Used to access relation source ref on live ECHO objects.\n */\nexport const RelationSourceId: unique symbol = Symbol.for('@dxos/echo/RelationSource');\n\n/**\n * Used to access relation source DXN on live ECHO objects.\n */\nexport const RelationSourceDXNId: unique symbol = Symbol.for('@dxos/echo/RelationSourceDXN');\n\n/**\n * Property name for relation target when object is serialized to JSON.\n */\nexport const ATTR_RELATION_TARGET = '@relationTarget';\n\n/**\n * Used to access relation target ref on live ECHO objects.\n */\nexport const RelationTargetId: unique symbol = Symbol.for('@dxos/echo/RelationTarget');\n\n/**\n * Used to access relation target DXN on live ECHO objects.\n */\nexport const RelationTargetDXNId: unique symbol = Symbol.for('@dxos/echo/RelationTargetDXN');\n\n/**\n * Symbol carrying the entity metadata (EntityMeta) on live ECHO entities.\n * Must be importable by both meta.ts (which depends on the Ref schema) and\n * Entity/api.ts (which is transitively imported by the Ref schema), so it\n * cannot live in either of those files without creating an import cycle.\n */\nexport const MetaId = Symbol.for('@dxos/echo/Meta');\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\n/**\n * Property name for typename when object is serialized to JSON.\n */\nexport const ATTR_TYPE = '@type';\n\n/**\n * DXN to the object type.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Type');\n\n/**\n * Reference to the object schema.\n */\nexport const SchemaId = Symbol.for('@dxos/echo/Schema');\n\n/**\n * Property name for parent when object is serialized to JSON.\n */\nexport const ATTR_PARENT = '@parent';\n\n/**\n * Reference to the object parent.\n */\nexport const ParentId = Symbol.for('@dxos/echo/Parent');\n\n/**\n * Reference to the object's type entity (`Type.Obj`, `Type.Relation`, or\n * `Type.Type`). Set at instance creation by `createObject` / `makeObject`\n * when the entity is known. Public read-back via `Obj.getType` / `Relation.getType`\n * / `Entity.getType`.\n */\nexport const TypeEntityId = Symbol.for('@dxos/echo/TypeEntity');\n\n/**\n * Returns the Effect Schema for the given object if one is defined.\n *\n * @internal\n * Internal callers needing schema-side validation read from `SchemaId`.\n * Public callers should use `Type.getSchema(Obj.getType(obj))` instead.\n */\n// TODO(dmaretskyi): For echo objects, this always returns the root schema.\nexport const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {\n  if (obj) {\n    return (obj as any)[SchemaId];\n  }\n};\n\n/**\n * @internal\n */\nexport const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {\n  Object.defineProperty(obj, SchemaId, {\n    value: schema,\n    writable: false,\n    enumerable: false,\n    configurable: false,\n  });\n};\n\n/**\n * Returns the type entity (`Type.AnyEntity`) for the given instance.\n * Set at instance creation; every entity has a type. Defensive: returns\n * undefined for null/undefined input so callers can safely probe arbitrary\n * values via this helper.\n *\n * @internal Re-exported via `Obj.getType` / `Relation.getType` / `Entity.getType`.\n */\nexport const getType = (obj: unknown): unknown => {\n  if (obj == null) {\n    return undefined;\n  }\n  return (obj as any)[TypeEntityId];\n};\n\n/**\n * @internal\n */\nexport const setType = (obj: any, type: unknown): void => {\n  Object.defineProperty(obj, TypeEntityId, {\n    value: type,\n    writable: false,\n    enumerable: false,\n    configurable: true,\n  });\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Types from 'effect/Types';\n\nimport type * as Annotation from '../../Annotation';\n\n/**\n * Unique identifier for an annotation.\n */\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of annotation values stored on entity meta or nested in schemas.\n */\nexport const Dictionary = Schema.Record({ key: Key, value: Schema.Unknown });\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a dictionary.\n */\nexport const getDictionary = <T>(\n  values: Annotation.Dictionary,\n  annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n  if (!(annotation.key in values)) {\n    return Option.none();\n  }\n\n  return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);\n};\n\n/**\n * Set the value of an annotation in a dictionary.\n */\nexport const setDictionary = <T>(\n  values: Types.Mutable<Annotation.Dictionary>,\n  annotation: Annotation.Annotation<T>,\n  value: T,\n): void => {\n  values[annotation.key] = Schema.encodeSync(annotation.schema)(value);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { DXN, EID, URI, type SpaceId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type { AnyEntity } from '../common/types';\nimport { MetaId } from '../common/types/model-symbols';\nimport { type InternalObjectProps, ObjectDatabaseId } from './model';\nimport { getObjectEchoUri } from './util';\n\n/**\n * Controls the URI form returned by `getUri` and the public `*.getURI` helpers.\n *\n * - `'named'`    — Registry key URI (`dxn:<meta.key>`) when the entity has a key in its meta;\n *                  falls back to the default EID.\n * - `'absolute'` — Fully-qualified EID with space id (`echo://<spaceId>/<entityId>`);\n *                  falls back when no space is available.\n * - `'relative'` — Local EID without space id (`echo:/<entityId>`).\n *\n * Omitting `prefer` preserves the existing behaviour.\n */\nexport type GetURIOptions = {\n  prefer?: 'named' | 'absolute' | 'relative';\n};\n\n/**\n * Get the URI of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getUri = (entity: AnyEntity, options?: GetURIOptions): URI.URI => {\n  const prefer = options?.prefer;\n\n  if (prefer === 'named') {\n    const key = (entity as any)[MetaId]?.key;\n    if (key) {\n      return (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;\n    }\n    const uri = getObjectEchoUri(entity);\n    invariant(uri != null, 'Invalid entity.');\n    return uri;\n  }\n\n  if (prefer === 'relative') {\n    const eid = getObjectEchoUri(entity);\n    invariant(eid != null, 'Invalid entity.');\n    const entityId = EID.getEntityId(eid);\n    return entityId ? EID.make({ entityId }) : eid;\n  }\n\n  if (prefer === 'absolute') {\n    const eid = getObjectEchoUri(entity);\n    invariant(eid != null, 'Invalid entity.');\n    const entityId = EID.getEntityId(eid);\n    if (!entityId) {\n      return eid;\n    }\n    assumeType<InternalObjectProps>(entity);\n    const spaceId: SpaceId | undefined = entity[ObjectDatabaseId]?.spaceId ?? EID.getSpaceId(eid);\n    return spaceId ? EID.make({ spaceId, entityId }) : eid;\n  }\n\n  const uri = getObjectEchoUri(entity);\n  invariant(uri != null, 'Invalid entity.');\n  return uri;\n};\n\n/**\n * Get the database the entity belongs to.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDatabase = (entity: AnyEntity): any | undefined => {\n  assumeType<InternalObjectProps>(entity);\n  return entity[ObjectDatabaseId];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { EID, EntityId, type URI } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from '../../Database';\nimport {\n  type ATTR_PARENT,\n  type ATTR_TYPE,\n  ATTR_DELETED,\n  ATTR_RELATION_SOURCE,\n  ATTR_RELATION_TARGET,\n  ATTR_SELF_URI,\n  ATTR_SELF_URI_LEGACY,\n  EntityKind,\n  KindId,\n  ObjectDatabaseId,\n  ObjectDeletedId,\n  ObjectVersionId,\n  type ParentId,\n  RelationSourceDXNId,\n  RelationSourceId,\n  RelationTargetDXNId,\n  RelationTargetId,\n  type SchemaId,\n  SelfURIId,\n  TypeId,\n  type Version,\n} from '../common/types';\nimport { type ATTR_META, type EntityMeta } from '../common/types/meta';\nimport { type MetaId } from '../common/types/model-symbols';\n\nexport {\n  ATTR_DELETED,\n  ATTR_SELF_URI,\n  ATTR_SELF_URI_LEGACY,\n  ObjectDatabaseId,\n  ObjectDeletedId,\n  ObjectVersionId,\n  SelfURIId,\n};\n\n/**\n * Internal runtime representation of an object.\n * The fields are accessed through getter functions.\n */\n// NOTE: Each symbol has a jsdoc describing its purpose.\nexport interface InternalObjectProps {\n  readonly id: EntityId;\n  readonly [SelfURIId]: EID.EID;\n  readonly [KindId]: EntityKind;\n  readonly [SchemaId]: Schema.Schema.AnyNoContext;\n  readonly [TypeId]: URI.URI;\n  readonly [MetaId]?: EntityMeta;\n  [ParentId]?: InternalObjectProps;\n  readonly [ObjectDatabaseId]?: Database.Database;\n  readonly [ObjectDeletedId]?: boolean;\n  readonly [ObjectVersionId]?: Version;\n  readonly [RelationSourceDXNId]?: EID.EID;\n  readonly [RelationTargetDXNId]?: EID.EID;\n  readonly [RelationSourceId]?: InternalObjectProps;\n  readonly [RelationTargetId]?: InternalObjectProps;\n}\n\n/**\n * Entity metadata.\n */\nexport interface EntityMetaJSON {\n  keys: ForeignKey[];\n  tags?: string[];\n  key?: string;\n  version?: string;\n}\n\n/**\n * JSON representation of an object or relation metadata.\n */\nexport interface ObjectJSON {\n  id: EntityId;\n  [ATTR_TYPE]?: URI.URI;\n  [ATTR_SELF_URI]?: EID.EID;\n  [ATTR_PARENT]?: EID.EID; // Encoded reference\n  [ATTR_DELETED]?: boolean;\n  [ATTR_META]?: EntityMetaJSON;\n  [ATTR_RELATION_SOURCE]?: EID.EID;\n  [ATTR_RELATION_TARGET]?: EID.EID;\n\n  /**\n   * Application-specific properties.\n   */\n  [key: string]: unknown;\n}\n\n/**\n * NOTE: Keep as `function` to avoid type inference issues.\n */\nexport function assertObjectModel(obj: unknown): asserts obj is InternalObjectProps {\n  invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');\n  assumeType<InternalObjectProps>(obj);\n  invariant(EntityId.isValid(obj.id), 'Invalid object model: invalid id');\n  invariant(obj[TypeId] === undefined || typeof obj[TypeId] === 'string', 'Invalid object model: invalid type');\n  invariant(\n    obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation || obj[KindId] === EntityKind.Type,\n    'Invalid object model: invalid entity kind',\n  );\n\n  if (obj[KindId] === EntityKind.Relation) {\n    invariant(EID.isEID(obj[RelationSourceDXNId]), 'Invalid object model: invalid relation source');\n    invariant(EID.isEID(obj[RelationTargetDXNId]), 'Invalid object model: invalid relation target');\n    invariant(!EID.isEID(obj[RelationSourceId]), 'Invalid object model: source pointer is a DXN');\n    invariant(!EID.isEID(obj[RelationTargetId]), 'Invalid object model: target pointer is a DXN');\n  }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { EID, EntityId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport { type InternalObjectProps, SelfURIId } from './model';\n\n/**\n * Returns the EID of an object.\n *\n * @internal\n */\nexport const getObjectEchoUri = (object: any): EID.EID | undefined => {\n  invariant(!Schema.isSchema(object), 'schema not allowed in this function');\n  assertArgument(typeof object === 'object' && object != null, 'object', 'expected object');\n  assumeType<InternalObjectProps>(object);\n\n  if (object[SelfURIId]) {\n    invariant(EID.isEID(object[SelfURIId]), 'Invalid object model: invalid self dxn');\n    return EID.parse(object[SelfURIId]);\n  }\n\n  if (!EntityId.isValid(object.id)) {\n    throw new TypeError('Object id is not valid.');\n  }\n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AmB,KAAA,CAAA,WAAA,SAAA,wBAAA,MAAA,OAAA,IAAA,CAAA,CAAA;IACnB,OAAcC,eAAAA,KAAAA,CAAAA,WAAe,SAAA,wBAAA,YAAA,qBAAA,MAAA,OAAA,iBAAA,CAAA,CAAA,CAAA;;OAEpBH;IACT,SAAA;AACF,aAAA;IACF;;;",
  "names": ["TypeId", "Context", "Effect", "Effectable", "Layer", "Option", "Schema", "EffectEx", "invariant", "Schema", "raise", "assertArgument", "DXN", "EID", "URI", "Function", "Option", "Schema", "SchemaAST", "SchemaEx", "assertArgument", "invariant", "DXN", "URI", "ATTR_SELF_URI", "ATTR_SELF_URI_LEGACY", "SelfURIId", "Symbol", "for", "ATTR_DELETED", "ObjectDeletedId", "ObjectVersionId", "ObjectDatabaseId", "ATTR_RELATION_SOURCE", "RelationSourceId", "RelationSourceDXNId", "ATTR_RELATION_TARGET", "RelationTargetId", "RelationTargetDXNId", "MetaId", "ATTR_TYPE", "TypeId", "Symbol", "for", "SchemaId", "ATTR_PARENT", "ParentId", "TypeEntityId", "getSchema", "obj", "setSchema", "schema", "Object", "defineProperty", "value", "writable", "enumerable", "configurable", "getType", "undefined", "setType", "type", "Function", "Option", "Schema", "Key", "String", "pipe", "brand", "Dictionary", "Record", "key", "value", "Unknown", "getDictionary", "values", "annotation", "none", "decodeUnknownSync", "schema", "some", "setDictionary", "encodeSync", "ANNOTATION_TYPE_ID", "id", "getTypeIdentifierAnnotation", "URI", "objectAnnotation", "typename", "undefined", "example", "TypeMeta", "version", "VersionSchema", "Function", "getAnnotation", "schema", "getSchemaTypename", "DXN", "type", "parsed", "Object", "defineProperty", "obj", "TypeId", "writable", "enumerable", "configurable", "invariant", "existingMeta", "self", "annotations", "PropertyMetaAnnotationId", "value", "assertArgument", "SchemaEx", "getField", "annotation", "label", "object", "accessor", "description", "key", "get", "getFromAst", "ast", "set", "PropertyMeta", "Schema", "encodeSync", "IconAnnotationSchema", "getLabelWithSchema", "options", "setLabelWithSchema", "entity", "getDescriptionWithSchema", "Option", "setDescriptionWithSchema", "invariant", "DXN", "EID", "URI", "assumeType", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "ATTR_DELETED", "assumeType", "obj", "invariant", "EntityId", "isValid", "__dxlog_file", "TypeId", "KindId", "EntityKind", "Type", "EID", "isEID", "RelationSourceDXNId", "RelationTargetDXNId", "Schema", "assertArgument", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "assertArgument", "object", "assumeType", "SelfURIId", "invariant", "EID", "EntityId", "isValid", "make", "__dxlog_file", "prefer", "key", "MetaId", "DXN", "tryMake", "uri", "getObjectEchoUri", "entity", "invariant", "eid", "entityId", "getEntityId", "make", "assumeType", "spaceId", "EID", "ObjectDatabaseId", "getTypeURIFromSpecifier", "input", "isSchema", "getSchemaURI", "raise", "TypeError", "KindId", "schema", "getStaticTypeSchema", "uri", "getUriFromEntity", "assertArgument", "EID", "isEID", "DXN", "isDXN", "isInstanceOf", "schemaOrType", "object", "schemaURI", "type", "TypeId", "URI", "isURI", "typename", "getTypename", "parsed", "tryMake", "getName", "__dxlog_file", "obj", "TypeId", "Database", "Schema", "Any", "space", "isDatabase", "db", "spaceId", "dxn", "ref", "object", "EffectEx", "context", "resolve", "Effect", "pipe", "withSpan", "EntityNotFoundError", "uri", "eff", "result", "first", "CommitPrototype"]
}
