import type { EntityId, URI } from '@dxos/keys'; import { type RawString } from './automerge'; import type { ForeignKey } from './foreign-key'; import { type EncodedReference } from './reference'; import { type SpaceDocVersion } from './space-doc-version'; export type SpaceState = { rootUrl?: string; }; /** * Array indexes get converted to strings. */ export type EntityProp = string; export type EntityPropPath = EntityProp[]; /** * Link to all documents that hold objects in the space. */ export interface DatabaseDirectory { version?: SpaceDocVersion; access?: { spaceKey: string; }; /** * Objects inlined in the current document. */ objects?: { [id: string]: EntityStructure; }; /** * Object id points to an automerge doc url where the object is embedded. */ links?: { [echoUri: string]: string | RawString; }; /** * @deprecated * For backward compatibility. */ experimental_spaceKey?: string; } export declare const DatabaseDirectory: Readonly<{ /** * @returns Space key in hex of the space that owns the document. In hex format. Without 0x prefix. */ getSpaceKey: (doc: DatabaseDirectory) => string | null; getInlineObject: (doc: DatabaseDirectory, id: EntityId) => EntityStructure | undefined; getLink: (doc: DatabaseDirectory, id: EntityId) => string | undefined; make: ({ spaceKey, objects, links, }: { spaceKey: string; objects?: Record; links?: Record; }) => DatabaseDirectory; }>; /** * Representation of an ECHO object in an AM document. */ export type EntityStructure = { system?: EntitySystem; meta: EntityMeta; /** * User-defined data. * Adheres to schema in `system.type` */ data: Record; }; export declare const EntityStructure: Readonly<{ /** * @throws On invalid object structure. */ getTypeReference: (object: EntityStructure) => EncodedReference | undefined; /** * @throws On invalid object structure. */ getEntityKind: (object: EntityStructure) => 'object' | 'relation' | 'type'; isDeleted: (object: EntityStructure) => boolean; getRelationSource: (object: EntityStructure) => EncodedReference | undefined; getRelationTarget: (object: EntityStructure) => EncodedReference | undefined; getParent: (object: EntityStructure) => EncodedReference | undefined; /** * @returns All references in the data section of the object. */ getAllOutgoingReferences: (object: EntityStructure) => { path: EntityPropPath; reference: EncodedReference; }[]; getTags: (object: EntityStructure) => (EncodedReference | string)[]; makeObject: ({ type, data, keys, }: { type: URI.URI; deleted?: boolean; keys?: ForeignKey[]; data?: unknown; }) => EntityStructure; makeRelation: ({ type, source, target, deleted, keys, data, }: { type: URI.URI; source: EncodedReference; target: EncodedReference; deleted?: boolean; keys?: ForeignKey[]; data?: unknown; }) => EntityStructure; makeType: ({ type, keys, data }: { type: URI.URI; keys?: ForeignKey[]; data?: unknown; }) => EntityStructure; }>; /** * Echo object metadata. */ export type EntityMeta = { /** * Foreign keys. */ keys: ForeignKey[]; /** * Tags. * Encoded references to Tag objects within the space. * * NOTE: Optional for backwards compatibility; legacy data may store bare DXN strings, which are * upgraded to encoded references on read (see `object-core.ts`). */ tags?: (EncodedReference | string)[]; /** * Fully-qualified registry key for the object (FQN format, e.g. `org.example.type.foo`). * Identifies the canonical registry entry the object instance was created from. */ key?: string; /** * Semantic version of the registry entry the object was created from. * Must be a valid semver string (e.g. `1.2.3`). */ version?: string; /** * Dictionary of annotations to this entity. * * NOTE: Optional for backwards compatibility. Values are arbitrary decoded automerge primitives; * typed as `any` so `EntityStructure` stays assignable to `DecodedAutomergePrimaryValue`. */ annotations?: { readonly [key: string]: any; }; }; /** * Automerge object system properties. * (Is automerge specific.) */ export type EntitySystem = { /** * Entity kind. `'type'` covers persisted ECHO type definitions (instances of * the `Type.Type` meta-schema); `'object'` / `'relation'` cover regular ECHO * instances. */ kind?: 'object' | 'relation' | 'type'; /** * Object reference ('protobuf' protocol) type — DXN of the schema this * entity instantiates. * * - For `kind === 'object'` / `'relation'` instances, this is the URI of the * user-defined schema the entity was created from (e.g. `dxn:org.example.Person:1.0.0`). * - For `kind === 'type'` entities (persisted Type.Type meta-instances) this * is always the URI of the `TypeSchema` meta-schema itself * (`dxn:org.dxos.type.schema:0.1.0`). The kind that the meta-instance * _describes_ (object/relation/type) lives in `data.jsonSchema.entityKind`. */ type?: EncodedReference; /** * Deletion marker. */ deleted?: boolean; /** * Object parent. * Objects with no parent are at the top level of the object hierarchy in the space. */ parent?: EncodedReference; /** * Only for relations. */ source?: EncodedReference; /** * Only for relations. */ target?: EncodedReference; /** * Unix ms timestamp recorded at object creation time. * Set once when the ObjectStructure is first written; never modified after that. * Survives compaction / migrations (unlike automerge change timestamps). */ createdAt?: number; }; /** * Id property name. */ export declare const PROPERTY_ID = "id"; /** * Data namespace. * The key on {@link EntityStructure} that contains the user-defined data. */ export declare const DATA_NAMESPACE = "data"; //# sourceMappingURL=document-structure.d.ts.map