import { ConstructorOf, Transceiver } from "atom.io/internal"; import { Json } from "atom.io/foundations/json"; import { UList } from "atom.io/transceivers/u-list"; import { AtomFamilyToken, JoinToken, MutableAtomToken, PureSelectorFamilyToken, ReadonlyPureSelectorFamilyToken } from "atom.io"; import { EventsMap as EventsMap$1, GuardedSocket as GuardedSocket$1, Socket as Socket$1 } from "atom.io/realtime"; import { Canonical } from "atom.io/foundations/canonical"; //#region src/realtime/clock.d.ts interface Clock { /** Cancel scheduled work. Returns whether it was still pending. */ cancel(task: number): boolean; /** Return the clock's current timestamp. */ now(): number; /** Schedule work after a non-negative delay. */ schedule(callback: () => void, delay?: number, label?: string): number; } /** * A wall-clock scheduler used by realtime APIs unless a test clock is injected. * * Keeping the small Clock interface in realtime core lets future leases, retry * backoff, and expiry policies use the same deterministic test seam. */ declare class SystemClock implements Clock { #private; now(): number; schedule(callback: () => void, delay?: number, _label?: string): number; cancel(task: number): boolean; } declare const systemClock: Clock; //#endregion //#region src/realtime/employ-socket.d.ts declare function employSocket(socket: GuardedSocket$1, event: K, handleEvent: (...data: Parameters) => void): () => void; declare function employSocket(socket: Socket$1, event: string, handleEvent: (...data: Json.Serializable[]) => void): () => void; //#endregion //#region src/realtime/socket-interface.d.ts type EventListener = (...args: Json.Serializable[]) => void; type EventsMap = { [event: string]: EventListener; }; type ParticularEventListener = (event: E, listener: ListenEvents[E]) => void; type AllEventsListener = (event: E, ...args: Parameters) => void; type EventEmitter = (event: E, ...args: Parameters) => void; interface GuardedSocket extends Socket { id: string | undefined; on: (event: E, listener: ListenEvents[E]) => void; onAny: (listener: (event: E, ...args: Parameters) => void) => void; onAnyOutgoing: (listener: AllEventsListener) => void; off: (event: E, listener?: ListenEvents[E]) => void; offAny: (listener?: (event: E, ...args: Parameters) => void) => void; emit: EventEmitter; } type Socket = { id: string | undefined; on: (event: string, listener: (...args: Json.Serializable[]) => void) => void; onAny: (listener: (event: string, ...args: Json.Serializable[]) => void) => void; onAnyOutgoing: (listener: (event: string, ...args: Json.Serializable[]) => void) => void; off: (event: string, listener?: (...args: Json.Serializable[]) => void) => void; offAny: (listener?: (event: string, ...args: Json.Serializable[]) => void) => void; emit: (event: string, ...args: Json.Serializable[]) => void; }; //#endregion //#region src/realtime/standard-schema.d.ts /** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ export interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Promise> | Result; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ export type Result = FailureResult | SuccessResult; /** The result interface if validation succeeds. */ export interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ export interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ export interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ export interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ export interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ export type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ export type InferOutput = NonNullable["output"]; } //#endregion //#region src/realtime/guard-socket.d.ts type SocketGuard = { [K in keyof ListenEvents]: StandardSchemaV1>; }; declare function guardSocket(socket: Socket, guard: SocketGuard | `TRUST`, logError?: (error: unknown) => void): GuardedSocket; //#endregion //#region src/realtime/mosaic/protocol.d.ts /** The wire protocol version implemented by this release of Mosaic. */ declare const MOSAIC_PROTOCOL_VERSION: 1; /** Stable transport event names shared by every Mosaic atom. */ declare const MOSAIC_EVENTS: { readonly join: "atom.io:mosaic:join"; readonly operation: "atom.io:mosaic:operation"; readonly presence: "atom.io:mosaic:presence"; readonly rejection: "atom.io:mosaic:rejection"; readonly snapshot: "atom.io:mosaic:snapshot"; }; type MosaicProtocolVersion = typeof MOSAIC_PROTOCOL_VERSION; type MosaicModelIdentifier = { /** Exact behavior-affecting configuration for this model variant. */ readonly configuration?: Json.Serializable; readonly key: string; readonly version: number; }; /** The ordinary mutable atom token identity carried over the wire. */ type MosaicAtomAddress = { readonly family?: { readonly key: string; readonly subKey: string; }; readonly key: string; readonly type: `mutable_atom`; }; /** Copy the serializable address from a mutable atom or family-member token. */ declare function mosaicAtomAddress(token: MutableAtomToken): MosaicAtomAddress; /** Stable map/storage key shared by clients, servers, and adapters. */ declare function mosaicAtomAddressKey(address: MosaicAtomAddress): string; /** Metadata generated by one logical client session. */ type MosaicProposalMetadata = { /** * Immediate operation IDs at the proposal's causal frontier. Model-owned IDs * may have been created by transitive ancestors rather than these operations. */ readonly dependencies: readonly string[]; readonly group: string | null; readonly id: string; readonly session: string; }; /** Untrusted operation proposed by a client. Authorship is server-stamped. */ type MosaicOperationProposal = MosaicProposalMetadata & { readonly model: MosaicModelIdentifier; readonly operation: Operation; readonly protocolVersion: MosaicProtocolVersion; readonly atom: MosaicAtomAddress; }; /** An operation whose actor has been authenticated by the server. */ type MosaicOperationEnvelope = MosaicOperationProposal & { readonly actor: string; }; type MosaicOperationMetadata = MosaicProposalMetadata & { readonly actor: string; }; /** A durable checkpoint used for hydration and revision-gap recovery. */ type MosaicSnapshotEnvelope = { /** The subset of the joining client's pending IDs already accepted. */ readonly acceptedPendingOperationIds: readonly string[]; readonly atom: MosaicAtomAddress; /** The current causal frontier from which new local operations depend. */ readonly headOperationIds: readonly string[]; readonly model: MosaicModelIdentifier; readonly protocolVersion: MosaicProtocolVersion; readonly revision: number; /** Correlates the snapshot with the currently active client incarnation. */ readonly session: string; readonly snapshot: Snapshot; }; /** Request to join or resynchronize one mutable-atom stream. */ type MosaicJoinEnvelope = { readonly atom: MosaicAtomAddress; readonly knownRevision: number | null; readonly model: MosaicModelIdentifier; readonly pendingOperationIds: readonly string[]; readonly protocolVersion: MosaicProtocolVersion; readonly session: string; }; /** An accepted operation paired with its server-assigned stream revision. */ type MosaicAcceptedOperationEnvelope = { readonly operation: MosaicOperationEnvelope; readonly revision: number; }; type MosaicRejectionCode = `capacity-exceeded` | `incompatible-version` | `invalid-model-operation` | `invalid-payload` | `missing-dependency` | `operation-id-collision` | `atom-unavailable` | `stale-history` | `unauthorized`; type MosaicRecovery = `discard-operation` | `none` | `resnapshot` | `retry` | `upgrade`; /** A safe, structured rejection of an operation or atom request. */ type MosaicRejectionEnvelope = { readonly code: MosaicRejectionCode; readonly atom: MosaicAtomAddress; readonly operationId: string | null; readonly protocolVersion: MosaicProtocolVersion; readonly reason: string; readonly recovery: MosaicRecovery; /** Correlates join- and operation-level failures with one client incarnation. */ readonly session: string; }; /** Untrusted ephemeral presence proposed by a bound client session. */ type MosaicPresenceProposal = { readonly atom: MosaicAtomAddress; readonly presence: Presence; readonly protocolVersion: MosaicProtocolVersion; readonly session: string; }; /** Ephemeral presence stamped with the authenticated actor. */ type MosaicPresenceEnvelope = MosaicPresenceProposal & { readonly actor: string; }; //#endregion //#region src/realtime/mosaic/transceiver.d.ts /** Metadata available to deterministic validation and reduction. */ type MosaicReduceContext = MosaicOperationMetadata & { /** The server stream order, or null for a provisional local projection. */ readonly revision: number | null; }; /** Local-only context used to translate a friendly intent into an operation. */ type MosaicPrepareContext = MosaicOperationMetadata & { /** Injected clock time. It must never affect accepted reduction semantics. */ readonly now: number; readonly revision: null; }; type MosaicModelDecision = { readonly operation: Operation; readonly status: `accept`; } | { readonly dependencies: readonly string[]; readonly status: `defer`; } | { /** An optional protocol-safe classification supplied by the model. */ readonly code?: MosaicRejectionCode; readonly reason: string; /** An optional recovery policy supplied by the model. */ readonly recovery?: MosaicRecovery; readonly status: `reject`; }; /** * The serializable signal carried by a Mosaic transceiver. The wire protocol * adds the mutable-atom address and model identifier around this signal. */ type MosaicOperationSignal = MosaicReduceContext & { readonly operation: Operation; }; /** * A convergent transceiver held by an ordinary mutable atom. Its readonly view * participates in Atom.io's graph; synchronization remains Store-owned. */ interface MosaicTransceiver) => void) => () => void; }, Intent extends Json.Serializable, Operation extends Json.Serializable, Snapshot extends Json.Serializable> extends Transceiver, Snapshot> { /** Prepare, apply, and publish one provisional local operation. */ change(intent: Intent, context: MosaicPrepareContext): MosaicOperationSignal | null; /** Apply exactly one validated operation, or throw without mutating. */ do(signal: MosaicOperationSignal): null; /** Validate and normalize an untrusted operation against this projection. */ validate(operation: unknown, context: MosaicReduceContext): MosaicModelDecision; } type AnyMosaicTransceiver = MosaicTransceiver; /** A mutable-atom-compatible constructor for one versioned Mosaic model. */ type MosaicTransceiverConstructor = ConstructorOf & { readonly mosaic: MosaicModelIdentifier; readonly timelinePolicy: `append-only`; }; type MosaicView = TransceiverType extends MosaicTransceiver ? View : never; type MosaicIntent = TransceiverType extends MosaicTransceiver ? Intent : never; type MosaicOperation = TransceiverType extends MosaicTransceiver ? Operation : never; type MosaicSnapshot = TransceiverType extends MosaicTransceiver ? Snapshot : never; type MosaicSignal = MosaicOperationSignal>; //#endregion //#region src/realtime/mosaic/text.d.ts type MosaicTextNode = { readonly after: string | null; /** The retained right boundary of the insertion interval. */ readonly before: string | null; readonly createdBy: string; readonly id: string; readonly value: string; }; type MosaicTextInsertedNode = Omit; type MosaicTextEditOperation = { readonly deletedIds: readonly string[]; readonly inserted: readonly MosaicTextInsertedNode[]; readonly type: `edit`; }; type MosaicTextHistoryOperation = { readonly mode: `redo` | `undo`; readonly targetOperationIds: readonly string[]; readonly type: `history`; }; type MosaicTextOperation = MosaicTextEditOperation | MosaicTextHistoryOperation; type MosaicTextIntent = { readonly text: string; readonly type: `replace-text`; } | { readonly type: `redo`; } | { readonly type: `undo`; }; type MosaicTextAppliedOperation = { readonly actor: string; readonly dependencies: readonly string[]; readonly group: string; readonly id: string; readonly operation: MosaicTextOperation; readonly revision: number | null; readonly session: string; }; type MosaicTextState = { readonly actions: readonly MosaicTextAppliedOperation[]; readonly activeEdits: Readonly>; readonly nodes: Readonly>; }; type MosaicTextSnapshot = MosaicTextState; type MosaicTextRelativePosition = { readonly affinity: `left` | `right`; readonly leftId: string | null; readonly rightId: string | null; }; type MosaicTextSelection = { readonly anchor: MosaicTextRelativePosition; readonly head: MosaicTextRelativePosition; }; type MosaicTextHistoryGroup = { readonly group: string; readonly targetOperationIds: readonly string[]; }; type MosaicTextHistory = { readonly redo: readonly MosaicTextHistoryGroup[]; readonly undo: readonly MosaicTextHistoryGroup[]; }; type MosaicTextView = { readonly historyFor: (actor: string) => MosaicTextHistory; readonly length: number; readonly nodes: readonly MosaicTextNode[]; readonly positionAtOffset: (offset: number) => MosaicTextRelativePosition; readonly resolvePosition: (position: MosaicTextRelativePosition) => number; readonly selectionFromOffsets: (anchor: number, head: number) => MosaicTextSelection; readonly subscribe: (key: string, fn: (signal: MosaicOperationSignal) => void) => () => void; readonly text: string; }; interface MosaicTextTransceiver extends MosaicTransceiver, Omit {} type MosaicTextConstructor = MosaicTransceiverConstructor; type MosaicTextOptions = { readonly initialText?: string; readonly maximumGraphemes?: number; }; /** Split text into the Unicode graphemes used by Mosaic Text model version 1. */ declare function splitMosaicText(text: string): string[]; /** Locale-independent ordering required for convergence across runtimes. */ declare function compareMosaicIds(left: string, right: string): number; declare function createEmptyMosaicText(): MosaicTextState; declare function visibleMosaicTextNodes(state: MosaicTextState): MosaicTextNode[]; declare function materializeMosaicText(state: MosaicTextState): string; declare function deriveMosaicTextHistory(state: MosaicTextState, actor: string): MosaicTextHistory; declare function positionAtMosaicTextOffset(state: MosaicTextState, utf16Offset: number): MosaicTextRelativePosition; declare function resolveMosaicTextPosition(state: MosaicTextState, position: MosaicTextRelativePosition): number; /** Create the built-in convergent Unicode text transceiver class. */ declare function mosaicText(options?: MosaicTextOptions): MosaicTextConstructor; //#endregion //#region src/realtime/mutex-store.d.ts type RealtimeLeaseStatus = { state: `idle`; } | { state: `waiting`; position: number; } | { expiresAt: number; generation: number; leaseId: string; renewAfterMs: number; state: `owned`; } | { generation: number; reason: `expired` | `released` | `stale`; state: `released`; }; declare const mutexAtoms: AtomFamilyToken; /** Detailed ownership state for a realtime push lease. */ declare const realtimeLeaseAtoms: AtomFamilyToken; //#endregion //#region src/realtime/realtime-key-types.d.ts type SocketKey = `socket::${string}`; declare const isSocketKey: (key: string) => key is SocketKey; type UserKey = `user::${string}`; declare const isUserKey: (key: string) => key is UserKey; type RoomKey = `room::${string}`; declare const isRoomKey: (key: string) => key is RoomKey; //#endregion //#region src/realtime/shared-room-store.d.ts type RoomSocketInterface = { createRoom: (roomName: RoomNames) => void; joinRoom: (roomKey: RoomKey) => void; deleteRoom: (roomKey: RoomKey) => void; leaveRoom: () => void; }; declare const roomKeysAtom: MutableAtomToken>; type UserInRoomMeta = { enteredAtEpoch: number; }; declare const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta; declare const usersInRooms: JoinToken<`room`, RoomKey, `user`, UserKey, `1:n`>; declare const visibleUsersInRoomsSelectors: PureSelectorFamilyToken<[self: UserKey, ...RoomKey[]], UserKey>; declare const visibilityFromRoomSelectors: PureSelectorFamilyToken<[self: RoomKey, ...UserKey[]], RoomKey>; declare const mutualUsersSelectors: ReadonlyPureSelectorFamilyToken; declare const ownersOfRooms: JoinToken<`user`, UserKey, `room`, RoomKey, `1:n`>; //#endregion export { type AllEventsListener, type AnyMosaicTransceiver, Clock, DEFAULT_USER_IN_ROOM_META, type EventEmitter, type EventListener, type EventsMap, type GuardedSocket, MOSAIC_EVENTS, MOSAIC_PROTOCOL_VERSION, MosaicAcceptedOperationEnvelope, MosaicAtomAddress, type MosaicIntent, MosaicJoinEnvelope, type MosaicModelDecision, MosaicModelIdentifier, type MosaicOperation, MosaicOperationEnvelope, MosaicOperationMetadata, MosaicOperationProposal, type MosaicOperationSignal, type MosaicPrepareContext, MosaicPresenceEnvelope, MosaicPresenceProposal, MosaicProposalMetadata, MosaicProtocolVersion, MosaicRecovery, type MosaicReduceContext, MosaicRejectionCode, MosaicRejectionEnvelope, type MosaicSignal, type MosaicSnapshot, MosaicSnapshotEnvelope, MosaicTextAppliedOperation, MosaicTextConstructor, MosaicTextEditOperation, MosaicTextHistory, MosaicTextHistoryGroup, MosaicTextHistoryOperation, MosaicTextInsertedNode, MosaicTextIntent, MosaicTextNode, MosaicTextOperation, MosaicTextOptions, MosaicTextRelativePosition, MosaicTextSelection, MosaicTextSnapshot, MosaicTextState, MosaicTextTransceiver, MosaicTextView, type MosaicTransceiver, type MosaicTransceiverConstructor, type MosaicView, type ParticularEventListener, RealtimeLeaseStatus, RoomKey, RoomSocketInterface, type Socket, SocketGuard, SocketKey, type StandardSchemaV1, SystemClock, UserInRoomMeta, UserKey, compareMosaicIds, createEmptyMosaicText, deriveMosaicTextHistory, employSocket, guardSocket, isRoomKey, isSocketKey, isUserKey, materializeMosaicText, mosaicAtomAddress, mosaicAtomAddressKey, mosaicText, mutexAtoms, mutualUsersSelectors, ownersOfRooms, positionAtMosaicTextOffset, realtimeLeaseAtoms, resolveMosaicTextPosition, roomKeysAtom, splitMosaicText, systemClock, usersInRooms, visibilityFromRoomSelectors, visibleMosaicTextNodes, visibleUsersInRoomsSelectors }; //# sourceMappingURL=index.d.ts.map