import * as SqlClient from '@effect/sql/SqlClient'; import type * as SqlError from '@effect/sql/SqlError'; import * as EffectContext from 'effect/Context'; import * as Effect from 'effect/Effect'; import { Event } from '@dxos/async'; import { type SpaceId } from '@dxos/keys'; import { FeedProtocol } from '@dxos/protocols'; import { SqlTransaction } from '@dxos/sql-sqlite'; import { PositionConflictError } from './errors'; type AppendRequest = FeedProtocol.AppendRequest; type AppendResponse = FeedProtocol.AppendResponse; type Block = FeedProtocol.Block; export interface FeedStoreOptions { /** * The actor ID of the local user. */ localActorId: string; /** * Whether to assign positions to appended blocks. * Only a single peer (usually the server) can assign positions. */ assignPositions: boolean; } declare const FeedStoreService_base: EffectContext.TagClass; /** * Effect service tag for {@link FeedStore}. */ export declare class FeedStoreService extends FeedStoreService_base { } /** * Persistent storage for feed metadata, blocks, subscriptions, and sync state. * */ export declare class FeedStore { #private; constructor(options: FeedStoreOptions); /** * Emits after successful block append operations. */ readonly onNewBlocks: Event; /** * Creates required feed store tables and indexes if they do not exist. */ migrate: () => Effect.Effect; /** * Queries feed blocks by feed IDs or subscription with cursor/position pagination. */ query: (request: FeedProtocol.QueryRequest) => Effect.Effect; /** * Creates a subscription and stores the resolved internal feed IDs. */ subscribe: (request: FeedProtocol.SubscribeRequest) => Effect.Effect; /** * Get the last pulled position for the given space and namespace. * Returns -1 if no sync state exists yet. */ getSyncState: (opts: { spaceId: SpaceId; feedNamespace: string; }) => Effect.Effect; /** * Update the last pulled position for the given space and namespace. */ setSyncState: (opts: { spaceId: SpaceId; feedNamespace: string; lastPulledPosition: number; }) => Effect.Effect; /** * Returns the number of blocks pending push (no global position yet) in a space/namespace. */ countUnpositionedBlocks: (opts: { spaceId: SpaceId; feedNamespace: string; }) => Effect.Effect; /** * Returns the total number of blocks stored locally for a space/namespace. */ countNamespaceBlocks: (opts: { spaceId: SpaceId; feedNamespace: string; }) => Effect.Effect; /** * Returns the number of stored blocks for a single feed in a space/namespace. * Intended as a low-level primitive for callers (for example Cloudflare Worker code) * that need to make retention decisions under constrained storage resources. */ countBlocks: (opts: { spaceId: SpaceId; feedNamespace: string; feedId: string; }) => Effect.Effect; /** * Deletes the oldest blocks for a single feed in a space/namespace. * This API intentionally does not enforce any retention policy (such as max size); * callers decide when and how much to prune, which is useful for constrained * environments like Cloudflare Workers. * * @returns Number of deleted rows. */ deleteOldestBlocks: (opts: { spaceId: SpaceId; feedNamespace: string; feedId: string; count: number; }) => Effect.Effect; /** * Appends blocks for a space/namespace and optionally assigns global positions. */ append: (request: AppendRequest) => Effect.Effect; /** * Creates local blocks with sequential predecessors and appends grouped batches. * * A block whose object id is later superseded by a newer same-id block (a live feed object's * `Obj.update`, persisted as a whole-object re-append) is never reclaimed — the index collapses * reads to the latest block by id, but old blocks stay on disk indefinitely. * TODO(wittjosiah): Add compaction/retention driven by `Feed.RetentionOptions`. */ appendLocal: (messages: { spaceId: string; feedId: string; feedNamespace: string; data: Uint8Array; }[]) => Effect.Effect; /** * Sets positions for existing blocks while preventing conflicting reassignments. */ setPosition: (request: { spaceId: string; blocks: (Pick & { feedNamespace: string; })[]; }) => Effect.Effect; /** * Gets all feeds and their blocks for a space, organized by feed ID and namespace. * Used for space archive export. */ getAllFeedsForSpace: (opts: { spaceId: SpaceId; }) => Effect.Effect, SqlError.SqlError, SqlClient.SqlClient>; } export {}; //# sourceMappingURL=feed-store.d.ts.map