import * as otel from '@opentelemetry/api'; import { type Adapter, type BootStatus, type ClientSessionSyncProcessorSimulationParams, LogConfig, type MigrationsReport, UnknownError } from '@livestore/common'; import type { LiveStoreSchema } from '@livestore/common/schema'; import { Context, Deferred, Effect, Layer, OtelTracer, Schema, Scope } from '@livestore/utils/effect'; import type { LiveStoreContextRunning as LiveStoreContextRunning_, OtelOptions, ShutdownDeferred } from './store-types.ts'; import { Store } from './store.ts'; declare global { /** Store instances for console debugging */ var __debugLiveStore: Record> | undefined; } declare const LiveStoreContextRunning_base: Context.TagClass; /** * @deprecated Use `makeStoreContext()` from `@livestore/livestore/effect` instead. * This service doesn't preserve schema types. See the Effect integration docs for migration. * * @example Migration * ```ts * // Before (untyped) * import { LiveStoreContextRunning } from '@livestore/livestore/effect' * const { store } = yield* LiveStoreContextRunning * * // After (typed) * import { makeStoreContext } from '@livestore/livestore/effect' * const AppStore = makeStoreContext()('app') * const { store } = yield* AppStore.Tag * ``` */ export declare class LiveStoreContextRunning extends LiveStoreContextRunning_base { static fromDeferred: Layer.Layer; } declare const DeferredStoreContext_base: Context.TagClass>; /** * @deprecated Use `StoreContext.DeferredTag` from `makeStoreContext()` instead. */ export declare class DeferredStoreContext extends DeferredStoreContext_base { } export type LiveStoreContextProps = typeof Schema.JsonValue> = { schema: TSchema; /** * The `storeId` can be used to isolate multiple stores from each other. * So it can be useful for multi-tenancy scenarios. * * The `storeId` is also used for persistence. * * @default 'default' */ storeId?: string; /** Can be useful for custom live query implementations (e.g. see `@livestore/graphql`) */ context?: TContext; boot?: (store: Store) => Effect.Effect; adapter: Adapter; /** * Whether to disable devtools. * * @default 'auto' */ disableDevtools?: boolean | 'auto'; onBootStatus?: (status: BootStatus) => void; batchUpdates: (run: () => void) => void; /** * Schema describing the shape of the sync payload and used to encode it. * * - If omitted, `Schema.JsonValue` is used (no additional typing/validation). * - Prefer exporting a schema from your app (e.g. `export const SyncPayload = Schema.Struct({ authToken: Schema.String })`) * and pass it here to get end-to-end type safety and validation. */ syncPayloadSchema?: TSyncPayloadSchema; /** * Payload that is sent to the sync backend when connecting * * - Its TypeScript type is inferred from `syncPayloadSchema` (i.e. `typeof SyncPayload.Type`). * - At runtime this value is encoded with `syncPayloadSchema` before being handed to the adapter. * * Example: * const SyncPayload = Schema.Struct({ authToken: Schema.String }) * useStore({ ..., syncPayloadSchema: SyncPayload, syncPayload: { authToken: '...' } }) */ syncPayload?: Schema.Schema.Type; }; export interface CreateStoreOptions = typeof Schema.JsonValue> extends LogConfig.WithLoggerOptions { /** The LiveStore schema defining tables, events, and materializers. */ schema: TSchema; /** Adapter used for data storage and synchronization. */ adapter: Adapter; /** * Unique identifier for the Store instance, stable for its lifetime. * * - **Valid characters**: Only alphanumeric characters, underscores (`_`), and hyphens (`-`) * are allowed. Must match `/^[a-zA-Z0-9_-]+$/`. * - **Globally unique**: Use globally unique IDs (e.g., nanoid) to prevent collisions across stores. * - **Use namespaces**: Prefix to avoid collisions and for easier identification when debugging * (e.g., `app-root`, `workspace-abc123`, `issue-456`) */ storeId: string; /** User-defined context that will be attached to the created Store (e.g. for dependency injection). */ context?: TContext; boot?: (store: Store, ctx: { migrationsReport: MigrationsReport; parentSpan: otel.Span; }) => Effect.SyncOrPromiseOrEffect; onBootStatus?: (status: BootStatus) => void; /** * Needed in React so LiveStore can apply multiple events in a single render. * * @example * ```ts * // With React DOM * import { unstable_batchedUpdates as batchUpdates } from 'react-dom' * * // With React Native * import { unstable_batchedUpdates as batchUpdates } from 'react-native' * ``` */ batchUpdates?: (run: () => void) => void; /** * Whether to disable devtools. * * @default 'auto' */ disableDevtools?: boolean | 'auto'; shutdownDeferred?: ShutdownDeferred; /** * Currently only used in the web adapter: * If true, registers a beforeunload event listener to confirm unsaved changes. * * @default true */ confirmUnsavedChanges?: boolean; /** * Schema describing the shape of the sync payload and used to encode it. * * - If omitted, `Schema.JsonValue` is used (no additional typing/validation). * - Prefer exporting a schema from your app (e.g. `export const SyncPayload = Schema.Struct({ authToken: Schema.String })`) * and pass it here to get end-to-end type safety and validation. */ syncPayloadSchema?: TSyncPayloadSchema; /** * Payload that is sent to the sync backend when connecting * * - Its TypeScript type is inferred from `syncPayloadSchema` (i.e. `typeof SyncPayload.Type`). * - At runtime this value is encoded with `syncPayloadSchema` and carried through the adapter * to the backend where it can be decoded with the same schema. * * @default undefined */ syncPayload?: Schema.Schema.Type; /** Options provided to the Store constructor. */ params?: { /** Max events pushed to the leader per write batch. */ leaderPushBatchSize?: number; /** Chunk size used when the stream replays confirmed events. */ eventQueryBatchSize?: number; simulation?: { clientSessionSyncProcessor: typeof ClientSessionSyncProcessorSimulationParams.Type; }; }; debug?: { instanceId?: string; }; } export type CreateStoreOptionsPromise = typeof Schema.JsonValue> = CreateStoreOptions & { signal?: AbortSignal; otelOptions?: Partial; }; /** Create a new LiveStore Store */ export declare const createStorePromise: = typeof Schema.JsonValue>({ signal, otelOptions, ...options }: CreateStoreOptionsPromise) => Promise>; export declare const createStore: = typeof Schema.JsonValue>({ schema, adapter, storeId, context, boot, batchUpdates, disableDevtools, onBootStatus, shutdownDeferred, params, debug, confirmUnsavedChanges, syncPayload, syncPayloadSchema, }: CreateStoreOptions) => Effect.Effect, UnknownError, Scope.Scope | OtelTracer.OtelTracer>; export {}; //# sourceMappingURL=create-store.d.ts.map