import type * as Schema from 'effect/Schema'; import * as SchemaAST from 'effect/SchemaAST'; import { type URI } from '@dxos/keys'; import type * as Entity from './Entity'; import type * as internal from './internal'; import * as refInternal from './internal/Ref'; import type * as Obj from './Obj'; import type * as TypeNs from './Type'; /** * Instance type for a reference. * * Reference can point to any object or relation. * References are lazy loaded. * * `ref.dxn` is the DXN of the referenced object. * * @example * ```ts * const taskRef: Ref = Ref.make(task); * * await taskRef.load(); // Returns Promise * yield* Database.load(taskRef); // Effectful version. * * database.makeRef(dxn); // Create a ref from a DXN. * ``` */ export type Ref = refInternal.Ref; export type Unknown = refInternal.Ref; /** * Factory function to create a Ref schema for the given target schema. * Use this in schema definitions to declare reference fields. * * @example * ```ts * const Task = Schema.Struct({ * assignee: Ref.Ref(Person), // Creates a Ref schema * }).pipe(Type.makeObject(DXN.make('com.example.type.task', '0.1.0'))); * ``` */ export declare const Ref: { (type: S): RefSchema & Obj.Unknown>; >(type: T): RefSchema>; >(schema: S): RefSchema & Obj.Unknown>; }; export declare const Array: Readonly<{ targets: (refs: readonly internal.Ref[]) => T[]; loadAll: (refs: readonly internal.Ref[]) => Promise; removeById: (refs: internal.Ref[], id: import("@dxos/keys").EntityId) => void; }>; /** * TypeScript type for a Ref schema. * This is the type of the SCHEMA itself, not the runtime ref instance. * For the instance type, use `Ref.Ref` from the Ref module. * * @example * ```ts * // Schema type annotation (rarely needed, usually inferred): * const refSchema: Ref.RefSchema = Ref.Ref(Task); * * // Instance type annotation (use Ref.Ref instead): * const refInstance: Ref.Ref = Ref.make(task); * ``` */ export interface RefSchema extends refInternal.RefSchema { } /** * Extract reference target. */ export type Target = R extends refInternal.Ref ? T : never; /** * Reference resolver. */ export type Resolver = refInternal.RefResolver; export declare const isRef: (value: unknown) => value is Unknown; export declare const make: (object: T) => internal.Ref; export declare const fromURI: (uri: URI.URI) => refInternal.Ref; export declare const hasEntityId: (id: import("@dxos/keys").EntityId) => (ref: internal.Ref) => boolean; export declare const isRefType: (ast: SchemaAST.AST) => boolean; //# sourceMappingURL=Ref.d.ts.map