import type { DocumentLiveMap, LiveMap, LiveMapCoreSchemaApi, LiveMapDocumentAttributeValue, LiveMapDocumentAttrs, LiveMapDocumentContent, LiveMapDocumentCommitTarget, LiveMapDataLibraryInput, LiveMapGraphOp, HsonSchemaValue, LiveMapLibraries, LiveMapLibrariesInput, LiveMapAnyOp, LiveMapCommit, LiveMapAuthority, LiveMapDocumentApi, LiveMapPathArrayApi, LiveMapPathHandle, LiveMapPathObjectApi, LiveMapPathValue, LiveMapSetValue, LiveMapWriteValue, LivePath } from "./livemap.types.js"; import type { JsonValue } from "../core/types.js"; import type { HsonData } from "../api/data/hson-data.js"; import type { LocusCanonicalCommit, LocusCanonicalHistoryOptions, LocusCanonicalStream, LocusSnapshotEnvelope } from "./locus.representation.types.js"; import type { LocusActionAuthorizer, LocusActionOrigin, LocusActionPayloads, LocusActionStatusState, LocusActionTerminalOutcome, LocusClientActionResult, LocusClientActionMessage, LocusConnectionContext, LocusDocumentActionFn, LocusDocumentRetryActionFn, LocusSchema, LocusServerEventMessage, LocusServerMessage, LocusSessionRejectCode, LocusRecoveryCaughtUp, LocusRecoveryRejection, LocusRecoverySnapshotReason, LocusSocketLike } from "./locus.protocol.types.js"; import type { LocusActionRequestId, LocusConnectionEpoch, LocusDisposer, LocusClientId, LocusIncarnationId, LocusLogicalMapId, LocusSessionCredential, LocusSessionId, LocusSeq } from "./locus.shared.types.js"; import type { LiveTraceSink } from "./live.trace.types.js"; /** Wire-safe representation of a data value that may be absent. */ export type LocusRecoveryRequest = Readonly<{ logicalMapId: LocusLogicalMapId; incarnationId?: LocusIncarnationId; lastAppliedRev?: number; }>; export type LocusRecoveryOptions = Readonly<{ maxTailCommits?: number; maxTailBytes?: number; }>; /** Deterministic planning barriers for race-focused tests and diagnostics. */ export type LocusRecoveryHooks = Readonly<{ beforeCut?: () => void; duringSnapshotCapture?: () => void; afterCut?: (headRev: number) => void; }>; export type LocusRecoveryRuntimeErrorCode = "LOCUS_RECOVERY_TAIL_OVERFLOW" | "LOCUS_RECOVERY_TAIL_GAP" | "LOCUS_RECOVERY_DISPOSED" | "LOCUS_RECOVERY_COMPLETED" | "LOCUS_RECOVERY_SNAPSHOT_FAILED" | "LOCUS_RECOVERY_REPLAY_FAILED" | "LOCUS_RECOVERY_OBSERVER_FAILED" | "LOCUS_RECOVERY_NEGOTIATION_FAILED" | "LOCUS_RECOVERY_PLANNING_FAILED"; export type LocusRecoveryBodyItem = Readonly<{ kind: "commit"; commit: LocusCanonicalCommit; }> | Readonly<{ kind: "snapshot"; snapshot: LocusSnapshotEnvelope; }>; export type LocusRecoveryBodyObserver = (item: LocusRecoveryBodyItem) => void; export type LocusRecoveryCompletion = Readonly<{ caughtUp: LocusRecoveryCaughtUp; tail: readonly LocusCanonicalCommit[]; }>; export type LocusRecoveryAttemptState = "active" | "completed" | "disposed" | "aborted"; export type LocusRecoveryAttemptDiagnostics = Readonly<{ state: LocusRecoveryAttemptState; outcome: "current" | "replay" | "snapshot"; headRev: number; queuedTailCommits: number; queuedTailBytes: number; maxTailCommits: number; maxTailBytes: number; errorCode?: LocusRecoveryRuntimeErrorCode; }>; export type LocusRecoveryAttemptBase = Readonly<{ logicalMapId: LocusLogicalMapId; incarnationId: LocusIncarnationId; headRev: number; complete: (observer?: LocusRecoveryBodyObserver) => LocusRecoveryCompletion; dispose: LocusDisposer; debug: () => LocusRecoveryAttemptDiagnostics; }>; export type LocusRecoveryCurrentPlan = LocusRecoveryAttemptBase & Readonly<{ outcome: "current"; body: readonly []; }>; export type LocusRecoveryReplayPlan = LocusRecoveryAttemptBase & Readonly<{ outcome: "replay"; body: readonly LocusCanonicalCommit[]; }>; export type LocusRecoverySnapshotPlan = LocusRecoveryAttemptBase & Readonly<{ outcome: "snapshot"; reason: LocusRecoverySnapshotReason; body: LocusSnapshotEnvelope; }>; export type LocusRecoveryRejectPlan = Readonly<{ outcome: "reject"; error: LocusRecoveryRejection; }>; export type LocusRecoveryPlan = LocusRecoveryCurrentPlan | LocusRecoveryReplayPlan | LocusRecoverySnapshotPlan | LocusRecoveryRejectPlan; export type LocusRecoveryPlannerDiagnostics = Readonly<{ activeAttemptCount: number; currentPlanCount: number; replayPlanCount: number; snapshotPlanCount: number; rejectPlanCount: number; completedAttemptCount: number; disposedAttemptCount: number; abortedAttemptCount: number; overflowCount: number; }>; export type LocusRecoveryPlanner = Readonly<{ plan: (request: LocusRecoveryRequest, hooks?: LocusRecoveryHooks) => LocusRecoveryPlan; debug: () => LocusRecoveryPlannerDiagnostics; dispose: LocusDisposer; }>; export type LocusActionContext> = Readonly<{ map: LocusReadonlyMap; mutate: (mutation: (draft: LocusMutationDraft) => LiveMapCommit) => Promise>; seq: LocusSeq; origin: LocusActionOrigin; emitEvent: (event: string, payload: JsonValue) => boolean; }>; type LocusDataMutationDraft = Omit; type LocusDocumentMutationDraft = Omit; /** Ephemeral mutation surface used only inside Locus-owned staged callbacks. */ export type LocusMutationDraft = TMap extends DocumentLiveMap ? LocusDocumentMutationDraft : LocusDataMutationDraft; type ReadonlyHostedDocumentApi = Readonly<{ root: LiveMapDocumentApi["root"]; byQuid: LiveMapDocumentApi["byQuid"]; content: () => ReturnType; attrs: Pick; }>; type LocusReadonlyPathObjectApi = Pick, "is" | "toObject" | "pick" | "omit" | "hasKey" | "getKey" | "keys" | "isEmpty" | "size" | "values" | "entries">; type LocusReadonlyPathArrayApi = Pick, "is" | "toArray" | "slice" | "take" | "drop" | "takeLast" | "dropLast" | "length" | "isEmpty" | "at" | "first" | "last" | "includes" | "indexOf">; type LocusReadonlyPathHandle = Pick, "rev" | "path" | "snap" | "feed" | "watch"> & Readonly<{ at: (path: TPath & ([LiveMapPathValue] extends [never] ? never : unknown)) => LocusReadonlyPathHandle>; array: LocusReadonlyPathArrayApi; object: LocusReadonlyPathObjectApi; }>; type LocusReadonlyDataMap> = Pick & Readonly<{ schema: Pick, "get">; at: (path: TPath & ([LiveMapPathValue] extends [never] ? never : unknown)) => LocusReadonlyPathHandle>; }>; /** Read and observation surface exposed by a hosted authority. */ export type LocusReadonlyMap = TMap extends LiveMap ? LocusReadonlyDataMap : TMap extends DocumentLiveMap ? Pick & Readonly<{ document: ReadonlyHostedDocumentApi; }> : Pick; export type LocusActionHandler, TActions extends LocusActionPayloads = LocusActionPayloads> = (ctx: LocusActionContext, payload: HsonData | undefined, message: LocusClientActionMessage) => unknown | void | Promise; export type LocusActions> = Readonly<{ [TName in keyof TActions & string]: LocusActionHandler; }>; export type LocusMapValue = TMap extends LiveMap ? TValue : TMap extends DocumentLiveMap ? undefined : never; type LocusSharedOptions = Readonly<{ actions?: Partial>; schema?: LocusSchema, TActions>; sessionId?: LocusSessionId | (() => LocusSessionId); logicalMapId?: LocusLogicalMapId; incarnationId?: LocusIncarnationId; history?: LocusCanonicalHistoryOptions; recovery?: LocusRecoveryOptions; sessions?: LocusSessionOptions; actionDedupe?: LocusActionDedupeOptions; authorizeAction?: LocusActionAuthorizer; trace?: LiveTraceSink; }>; export type DataLocusOptions = LocusSharedOptions, TActions> & Readonly<{ state?: TState; map?: never; }>; export type LocusOptions = LocusSharedOptions & Readonly<{ map: TMap; state?: never; }>; type MultiLibraryDataMutationHandle = Readonly<{ at: (path: TPath & ([LiveMapPathValue] extends [never] ? never : unknown)) => MultiLibraryDataMutationHandle>; set: (value: LiveMapSetValue) => void; replace: (value: LiveMapWriteValue) => void; delete: () => void; }>; type MultiLibraryDataMutationDraft = Readonly<{ at: (path: TPath & ([LiveMapPathValue] extends [never] ? never : unknown)) => MultiLibraryDataMutationHandle>; }>; type MultiLibraryDataMutationDraftForInput = TInput extends LiveMapDataLibraryInput ? MultiLibraryDataMutationDraft> : never; type MultiLibraryBroadDataMutationDraft = Readonly<{ at: (path: LivePath) => Readonly<{ set: (value: JsonValue) => void; replace: (value: JsonValue) => void; delete: () => void; }>; }>; type MultiLibraryDocumentGraphMutation = Exclude>; type MultiLibraryDocumentMutationDraft = Readonly<{ graph: (operation: MultiLibraryDocumentGraphMutation) => void; attrs: Readonly<{ set: (target: LiveMapDocumentCommitTarget, name: string, value: LiveMapDocumentAttributeValue) => void; drop: (target: LiveMapDocumentCommitTarget, name: string) => void; replace: (target: LiveMapDocumentCommitTarget, attrs: LiveMapDocumentAttrs) => void; }>; content: Readonly<{ replace: (target: LiveMapDocumentCommitTarget, index: number, replacement: LiveMapDocumentContent) => void; insert: (target: LiveMapDocumentCommitTarget, index: number, content: LiveMapDocumentContent) => void; remove: (target: LiveMapDocumentCommitTarget, index: number) => void; move: (target: LiveMapDocumentCommitTarget, from: number, to: number) => void; }>; }>; type MultiLibraryMutationDraftForInput = TInput extends LiveMapDataLibraryInput ? MultiLibraryDataMutationDraftForInput : TInput extends Readonly<{ document: string | import("../core/types.js").HsonNode; }> ? MultiLibraryDocumentMutationDraft : MultiLibraryBroadDataMutationDraft | MultiLibraryDocumentMutationDraft; /** Inferred only inside a multi-library Locus mutation callback. */ type MultiLibraryMutationDraft = Readonly<{ lib: >(name: TLibrary) => MultiLibraryMutationDraftForInput; }>; type MultiLibraryInputs = TMap extends LiveMapLibraries ? TLibraries : LiveMapLibrariesInput; /** Ordinary Locus action context for one fixed multi-library LiveMap. */ export type LocusMultiLibraryActionContext = Readonly<{ map: TMap; mutate: (mutation: (draft: MultiLibraryMutationDraft>) => void) => Promise; seq: LocusSeq; origin: LocusActionOrigin; emitEvent: (event: string, payload: JsonValue) => boolean; }>; export type LocusMultiLibraryActionHandler = (ctx: LocusMultiLibraryActionContext, payload: HsonData | undefined, message: LocusClientActionMessage) => unknown | void | Promise; export type LocusMultiLibraryActions = Readonly<{ [TName in keyof TActions & string]: LocusMultiLibraryActionHandler; }>; /** Existing Locus construction options when `map` is a fixed public Library registry. */ export type LocusMultiLibraryOptions = Readonly<{ map: TMap; state?: never; actions?: Partial, TActions>>; logicalMapId?: LocusLogicalMapId; incarnationId?: LocusIncarnationId; sessionId?: LocusSessionId | (() => LocusSessionId); sessions?: LocusSessionOptions; actionDedupe?: LocusActionDedupeOptions; schema?: Pick, "actions">; authorizeAction?: LocusActionAuthorizer; }>; export type LocusActionDedupeSchedule = (delayMs: number, callback: () => void) => LocusDisposer; export type LocusActionDedupeOptions = Readonly<{ namespace?: string; maxTerminalRecords?: number; maxTerminalBytes?: number; terminalRetentionMs?: number; maxExpiredTombstones?: number; now?: () => number; schedule?: LocusActionDedupeSchedule; }>; export type LocusActionDedupeDiagnostics = Readonly<{ pendingRequestCount: number; pendingWaiterCount: number; retainedTerminalCount: number; retainedTerminalBytes: number; expiredTombstoneCount: number; joinedPendingDuplicateCount: number; cachedOutcomeResponseCount: number; requestIdConflictCount: number; expiredRecordCount: number; unknownStatusQueryCount: number; executionsStarted: number; executionsSucceeded: number; executionsFailed: number; outcomeNormalizationFailureCount: number; oldestRetainedTerminalCompletedAt?: number; oldestRetainedTerminalCompletionRev?: number; disposed: boolean; }>; export type LocusActionDedupeInspector = Readonly<{ debug: () => LocusActionDedupeDiagnostics; dispose: LocusDisposer; }>; export type LocusSessionSchedule = (delayMs: number, callback: () => void) => LocusDisposer; export type LocusSessionOptions = Readonly<{ graceMs?: number; now?: () => number; schedule?: LocusSessionSchedule; credential?: () => LocusSessionCredential; }>; export type LocusSessionState = "attached" | "disconnected" | "expired" | "revoked"; export type LocusSessionDiagnostic = Readonly<{ sessionId: LocusSessionId; state: LocusSessionState; resumable: boolean; activeConnectionEpoch: LocusConnectionEpoch; transportAttached: boolean; subscriptionCount: number; disconnectedAt?: number; expiresAt?: number; reattachmentCount: number; fencingCount: number; expiryCount: number; }>; export type LocusSessionDiagnostics = Readonly<{ activeSessionCount: number; attachedSessionCount: number; disconnectedSessionCount: number; expiredSessionCount: number; revokedSessionCount: number; reattachmentCount: number; fencingCount: number; expiryCount: number; rejectedCredentialCounts: Readonly>>; sessions: readonly LocusSessionDiagnostic[]; }>; export type LocusSessionLifecycleEvent = Readonly<{ kind: "attached"; session: LocusSessionDiagnostic; attachment: "created" | "reattached"; }> | Readonly<{ kind: "detached"; session: LocusSessionDiagnostic; }> | Readonly<{ kind: "expired"; session: LocusSessionDiagnostic; }> | Readonly<{ kind: "revoked"; session: LocusSessionDiagnostic; reason: "goodbye" | "locus_disposed"; }> | Readonly<{ kind: "fenced"; sessionId: LocusSessionId; epoch: LocusConnectionEpoch; }>; export type LocusSessionInspector = Readonly<{ debug: () => LocusSessionDiagnostics; onChange: (listener: (event: LocusSessionLifecycleEvent) => void) => LocusDisposer; dispose: LocusDisposer; }>; export type EchoActionRequest = Readonly<{ requestId: LocusActionRequestId; name: TName; payload?: HsonData | TActions[TName]; }>; export type EchoActionPromise = Promise & Readonly<{ request: EchoActionRequest; }>; export type LocusEventListener = (message: LocusServerEventMessage) => void; export type LocusConnection = LocusDisposer & Readonly<{ emitEvent: (event: string, payload: JsonValue) => void; }>; export type EchoActionFn = (name: TName, ...args: undefined extends TActions[TName] ? [payload?: Exclude | HsonData] : [payload: TActions[TName] | HsonData]) => EchoActionPromise; export type EchoRetryActionFn = (request: EchoActionRequest) => EchoActionPromise; export type EchoActionStatusResult = Readonly<{ requestId: LocusActionRequestId; state: LocusActionStatusState; outcome?: LocusActionTerminalOutcome; }>; export type EchoRecoveryStatus = "idle" | "recovering" | "caught_up" | "failed" | "disposed"; export type EchoRecoveryStrategy = "current" | "replay" | "snapshot" | "reject"; export type EchoRecoveryCursor = Readonly<{ incarnationId: LocusIncarnationId; lastAppliedRev: number; }>; export type EchoRecoveryOptions = Readonly<{ logicalMapId: LocusLogicalMapId; cursor?: EchoRecoveryCursor; }>; export type EchoRecoveryFailure = Readonly<{ code: string; message: string; cause?: unknown; }>; export type EchoRecoveryResult = Readonly<{ strategy: Exclude; sessionId: LocusSessionId; logicalMapId: LocusLogicalMapId; incarnationId: LocusIncarnationId; headRev: number; incarnationChanged: boolean; }>; export type EchoRecoveryDiagnostics = Readonly<{ status: EchoRecoveryStatus; strategy?: EchoRecoveryStrategy; logicalMapId?: LocusLogicalMapId; incarnationId?: LocusIncarnationId; lastAppliedRev?: number; bodyCommitsApplied: number; snapshotInstalls: number; duplicateCommitsIgnored: number; gapsDetected: number; replayConflicts: number; tailCommitsApplied: number; liveCommitsApplied: number; recoveryFailures: number; observerFailures: number; }>; export type EchoRecovery> = Readonly<{ readonly status: EchoRecoveryStatus; readonly logicalMapId: LocusLogicalMapId | undefined; readonly incarnationId: LocusIncarnationId | undefined; readonly lastAppliedRev: number | undefined; readonly map: TMap; readonly failure: EchoRecoveryFailure | undefined; readonly strategy: EchoRecoveryStrategy | undefined; recover: () => Promise; dispose: LocusDisposer; debug: () => EchoRecoveryDiagnostics; }>; export type EchoSessionStatus = "idle" | "creating" | "attaching" | "attached" | "detached" | "failed" | "ended" | "disposed"; export type EchoSessionFailure = Readonly<{ code: string; message: string; }>; export type EchoSessionResult = Readonly<{ sessionId: LocusSessionId; epoch: LocusConnectionEpoch; logicalMapId: LocusLogicalMapId; incarnationId: LocusIncarnationId; reattached: boolean; }>; export type EchoSessionDiagnostics = Readonly<{ status: EchoSessionStatus; sessionId?: LocusSessionId; epoch?: LocusConnectionEpoch; hasCredential: boolean; createCount: number; reattachCount: number; fencingCount: number; rejectionCount: number; }>; export type EchoSession = Readonly<{ readonly status: EchoSessionStatus; readonly sessionId: LocusSessionId | undefined; readonly credential: LocusSessionCredential | undefined; readonly epoch: LocusConnectionEpoch | undefined; readonly logicalMapId: LocusLogicalMapId | undefined; readonly incarnationId: LocusIncarnationId | undefined; readonly failure: EchoSessionFailure | undefined; create: () => Promise; reattach: (credential?: LocusSessionCredential) => Promise; goodbye: () => Promise; dispose: LocusDisposer; debug: () => EchoSessionDiagnostics; }>; export type EchoSessionOptions = Readonly<{ credential?: LocusSessionCredential; }>; type EchoMap = LiveMapAuthority | LiveMapLibraries; type EchoCommonOptions = Readonly<{ socket: LocusSocketLike; /** * Logical client identity used to scope retry-safe action requests. * The default is reload-safe. Reuse an explicit value only when reconnecting * the same logical client and preserving its outstanding request lineage. */ clientId?: LocusClientId; session?: EchoSessionOptions; /** Optional local-only client lifecycle trace sink. Never transmitted. */ trace?: LiveTraceSink; }>; export type EchoOptions = EchoCommonOptions & (TMap extends EchoMap ? Readonly<{ map: TMap; recovery: EchoRecoveryOptions; }> : Readonly<{ map?: never; recovery?: never; }>); export type Echo = Readonly<{ clientId: LocusClientId; session: EchoSession; connect: () => LocusDisposer; disconnect: () => void; action: EchoActionFn & LocusDocumentActionFn; retryAction: EchoRetryActionFn & LocusDocumentRetryActionFn; actionStatus: (requestId: LocusActionRequestId) => Promise; dispose: LocusDisposer; }> & (TMap extends EchoMap ? Readonly<{ map: TMap; recovery: EchoRecovery; }> : Readonly<{}>); export type Locus, TActions extends LocusActionPayloads = LocusActionPayloads> = Readonly<{ map: LocusReadonlyMap; stream: LocusCanonicalStream; activity: LocusActivity; recovery: LocusRecoveryPlanner; sessions: LocusSessionInspector; actionRequests: LocusActionDedupeInspector; seq: LocusSeq; schema?: LocusSchema, TActions>; mutate: (mutation: (draft: LocusMutationDraft) => LiveMapCommit) => Promise>; dispatchAction: (message: LocusClientActionMessage) => Promise; connect: (socket: LocusSocketLike, context?: LocusConnectionContext) => LocusConnection; dispose: LocusDisposer; }>; /** Locus result for the normal fixed multi-library construction surface. */ export type LocusMultiLibrary = Readonly<{ map: TMap; readonly logicalMapId: LocusLogicalMapId; readonly incarnationId: LocusIncarnationId; readonly rev: number; activity: LocusActivity; sessions: LocusSessionInspector; actionRequests: LocusActionDedupeInspector; mutate: (mutation: (draft: MultiLibraryMutationDraft>) => void | Promise) => Promise; dispatchAction: (message: LocusClientActionMessage) => Promise>; connect: (socket: LocusSocketLike, context?: LocusConnectionContext) => LocusConnection; dispose: LocusDisposer; }>; /** Opaque durable-record port for a fixed hosted Library registry. */ export interface LocusMultiLibraryPersistenceAdapter { load(logicalMapId: LocusLogicalMapId): Promise; appendCommit(record: unknown): Promise; replaceCheckpoint(record: unknown): Promise; } export type PersistentLocusMultiLibraryOptions = LocusMultiLibraryOptions & Readonly<{ persistence: LocusMultiLibraryPersistenceAdapter; }>; export type PersistentLocusMultiLibrary = LocusMultiLibrary & Readonly<{ checkpoint: () => Promise; }>; export type LocusActivityKind = "connection" | "session" | "action" | "recovery" | "mutation" | "persistence"; export type LocusActivityState = "active" | "idle" | "disposed"; /** Non-sensitive quiescence information for application-owned authority lifecycle policy. */ export type LocusActivitySnapshot = Readonly<{ state: LocusActivityState; connectionCount: number; retainedSessionCount: number; actionCount: number; recoveryCount: number; mutationCount: number; persistenceCount: number; blockerCount: number; blockers: readonly LocusActivityKind[]; }>; export type LocusActivity = Readonly<{ snapshot(): LocusActivitySnapshot; onChange(listener: (snapshot: LocusActivitySnapshot) => void): LocusDisposer; }>; export {}; //# sourceMappingURL=locus.core.types.d.ts.map