import { type CoValueUniqueness, type CojsonInternalTypes, type RawCoValue } from "cojson"; import { Account, AnonymousJazzAgent, CoValueClassOrSchema, CoValueLoadingState, NotLoadedCoValueState, Group, Loaded, Inaccessible, MaybeLoaded, OnCreateCallback, Settled, RefsToResolve, RefsToResolveStrict, ResolveQuery, ResolveQueryStrict, Resolved, SubscriptionScope, TypeSym, NotLoaded, inspect, LocalValidationMode, CoValueCursor, LoadCoValueCursorOption } from "../internal.js"; import type { BranchDefinition, CoValueErrorState } from "../subscribe/types.js"; import { CoValueHeader } from "cojson"; import { CoreCoValueSchema } from "../implementation/zodSchema/schemaTypes/CoValueSchema.js"; /** @category Abstract interfaces */ export interface CoValueClass { coValueSchema?: Schema; /** @ignore */ new (...args: any[]): Value; } export interface CoValueFromRaw { fromRaw(raw: V["$jazz"]["raw"]): V; } /** @category Abstract interfaces */ export interface CoValue { /** @category Type Helpers */ [TypeSym]: string; $jazz: { /** @category Content */ readonly id: ID; /** @category Content */ loadingState: typeof CoValueLoadingState.LOADED; /** @category Collaboration */ owner?: Group; /** @internal */ readonly loadedAs: Account | AnonymousJazzAgent; /** @category Internals */ raw: RawCoValue; /** @internal */ _subscriptionScope?: SubscriptionScope; isBranched: boolean; branchName: string | undefined; unstable_merge: () => void; cursor: CoValueCursor | undefined; createCursor: () => CoValueCursor; }; /** * Whether the CoValue is loaded. Can be used to distinguish between loaded and {@link NotLoaded} CoValues. * For more information about the CoValue's loading state, use {@link $jazz.loadingState}. */ $isLoaded: true; /** @category Stringifying & Inspection */ toJSON(key?: string, seenAbove?: ID[]): any[] | object | string; /** @category Stringifying & Inspection */ [inspect](): any; } export declare function isCoValue(value: any): value is CoValue; export declare function isCoValueClass(value: any): value is CoValueClass & CoValueFromRaw; /** * IDs are unique identifiers for `CoValue`s. * Can be used with a type argument to refer to a specific `CoValue` type. * * @example * * ```ts * type AccountID = ID; * ``` * * @category CoValues */ export type ID = string; export declare function getUnloadedCoValueWithoutId(loadingState: NotLoadedCoValueState): NotLoaded; export declare function createSettledCoValue(id: ID, loadingState: CoValueErrorState): Settled; export declare function createUnloadedCoValue(id: ID, loadingState: NotLoadedCoValueState): NotLoaded; export declare function loadCoValueWithoutMe = true>(cls: CoValueClass, id: ID, options?: { resolve?: RefsToResolveStrict; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; unstable_branch?: BranchDefinition; cursor?: LoadCoValueCursorOption; }): Promise>>; export declare function loadCoValue>(cls: CoValueClass, id: ID, options: { resolve?: RefsToResolveStrict; loadAs: Account | AnonymousJazzAgent; skipRetry?: boolean; unstable_branch?: BranchDefinition; cursor?: LoadCoValueCursorOption; }): Promise>>; export declare function ensureCoValueLoaded>(existing: V, options?: { resolve?: RefsToResolveStrict; unstable_branch?: BranchDefinition; cursor?: LoadCoValueCursorOption; } | undefined): Promise>; type SubscribeListener> = (value: Resolved, unsubscribe: () => void) => void; export type SubscribeCallback = (value: V, unsubscribe: () => void) => void; export type SubscribeListenerOptions> = { resolve?: RefsToResolveStrict; loadAs?: Account | AnonymousJazzAgent; onError?: (value: NotLoaded) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnauthorized?: (value: NotLoaded) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnavailable?: (value: NotLoaded) => void; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }; export type SubscribeRestArgs> = [options: SubscribeListenerOptions, listener: SubscribeListener] | [listener: SubscribeListener]; export declare function parseSubscribeRestArgs>(args: SubscribeRestArgs): { options: SubscribeListenerOptions; listener: SubscribeListener; }; export declare function subscribeToCoValueWithoutMe = true>(cls: CoValueClass, id: ID, options: SubscribeListenerOptions, listener: SubscribeListener): () => void; export declare function subscribeToCoValue = true>(cls: CoValueClass, id: ID, options: { resolve?: RefsToResolveStrict; loadAs: Account | AnonymousJazzAgent; onError?: (value: Inaccessible) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnavailable?: (value: Inaccessible) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnauthorized?: (value: Inaccessible) => void; syncResolution?: boolean; skipRetry?: boolean; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }, listener: SubscribeListener): () => void; export declare function subscribeToExistingCoValue>(existing: V, options: { resolve?: RefsToResolveStrict; onError?: (value: NotLoaded) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnavailable?: (value: NotLoaded) => void; /** * @deprecated Use `onError` instead. This callback will be removed in a future version. */ onUnauthorized?: (value: NotLoaded) => void; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; } | undefined, listener: SubscribeListener): () => void; export declare function isAccountInstance(instance: unknown): instance is Account; export declare function isAnonymousAgentInstance(instance: unknown): instance is AnonymousJazzAgent; export declare function isAccountOrGroup(instance: unknown): instance is Account | Group; export type CoValueCreateOptions = undefined | Owner | (({ owner: Owner; unique: CoValueUniqueness["uniqueness"]; validation?: LocalValidationMode; } | { owner?: Owner; unique?: undefined; validation?: LocalValidationMode; }) & MoreOptions); export type CoValueCreateOptionsInternal = CoValueCreateOptions<{ onCreate?: OnCreateCallback; firstComesWins?: boolean; restrictDeletion?: boolean; }, Account | Group>; export declare function parseCoValueCreateOptions(options: CoValueCreateOptionsInternal): { owner: Group; uniqueness?: CoValueUniqueness; firstComesWins: boolean; restrictDeletion?: boolean; }; export declare function accountOrGroupToGroup(accountOrGroup: Account | Group): Group; export declare function parseGroupCreateOptions(options: { owner?: Account; name?: string; } | Account | undefined): { owner: Account; name?: string; }; export declare function getIdFromHeader(header: CoValueHeader, loadAs?: Account | AnonymousJazzAgent | Group): `co_z${string}`; export declare function unstable_loadUnique>(schema: S, options: { unique: CoValueUniqueness["uniqueness"]; onCreateWhenMissing?: () => void; onUpdateWhenFound?: (value: Loaded) => void; owner: Account | Group; resolve?: ResolveQueryStrict; }): Promise>>; export type CoValueHeaderType = "comap" | "colist" | "costream" | "coplaintext"; /** * Get the CoValueHeaderType from a CoValue class. * Throws for unsupported types (Group, Account, BinaryCoStream). */ export declare function getUniqueHeaderType(schema: CoValueClassOrSchema): CoValueHeaderType; /** * Generate a unique header for a CoValue class. * Throws for unsupported types (Group, Account, BinaryCoStream). */ export declare function getUniqueHeader(type: CoValueHeaderType, unique: CoValueUniqueness["uniqueness"], ownerID: ID | ID): CoValueHeader; export declare function internalLoadUnique>(cls: CoValueClass, options: { unique: CoValueUniqueness["uniqueness"]; type: CoValueHeaderType; onCreateWhenMissing?: () => void; onUpdateWhenFound?: (value: Resolved) => void; owner: Account | Group; resolve?: RefsToResolveStrict; }): Promise>>; /** * Deeply export a CoValue to a content piece. * * @param cls - The class of the CoValue to export. * @param id - The ID of the CoValue to export. * @param options - The options for the export. * @returns The content pieces that were exported. * * @example * ```ts * const Address = co.map({ * street: z.string(), * city: z.string(), * }); * * const Person = co.map({ * name: z.string(), * address: Address, * }); * * const group = Group.create(); * const address = Address.create( * { street: "123 Main St", city: "New York" }, * group, * ); * const person = Person.create({ name: "John", address }, group); * group.addMember("everyone", "reader"); * * // Export with nested references resolved, values can be serialized to JSON * const exportedWithResolve = await exportCoValue(Person, person.id, { * resolve: { address: true }, * }); * * // In another client or session * // Load the exported content pieces into the node, they will be persisted * importContentPieces(exportedWithResolve); * * // Now the person can be loaded from the node, even offline * const person = await loadCoValue(Person, person.id, { * resolve: { address: true }, * }); * ``` */ export declare function exportCoValue>(cls: S, id: ID, options: { resolve?: ResolveQueryStrict; loadAs: Account | AnonymousJazzAgent; skipRetry?: boolean; bestEffortResolution?: boolean; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }): Promise; export declare function exportCoValueFromSubscription(subscription: SubscriptionScope): ExportedCoValue; export type ExportedID = string & { _exportedID: V; }; export type ExportedCoValue = { id: ExportedID; contentPieces: CojsonInternalTypes.NewContentMessage[]; }; /** * Import content pieces into the node. * * @param contentPieces - The content pieces to import. * @param loadAs - The account to load the content pieces as. */ export declare function importContentPieces(contentPieces: CojsonInternalTypes.NewContentMessage[], loadAs?: Account | AnonymousJazzAgent): void; export declare function unstable_mergeBranch(subscriptionScope: SubscriptionScope): void; export declare function unstable_mergeBranchWithResolve>(cls: S, id: ID, options: { resolve?: ResolveQueryStrict; loadAs?: Account | AnonymousJazzAgent; branch: BranchDefinition; }): Promise; /** * Permanently delete a group of coValues * * This operation is irreversible and will permanently delete the coValues from the local machine and the sync servers. * */ export declare function deleteCoValues>(cls: S, id: ID, options?: { resolve?: ResolveQueryStrict; loadAs?: Account | AnonymousJazzAgent; }): Promise; export {}; //# sourceMappingURL=interfaces.d.ts.map