import { type AuthState, type User, type ConnectionStatus, type TransactionChunk, type RoomSchemaShape, type InstaQLOptions, type InstantConfig, type PageInfoResponse, type InstaQLLifecycleState, type InstaQLResponse, type ValidQuery, Auth, Storage, Streams, InstantCoreDatabase, InstantSchemaDef, RoomsOf, IInstantDatabase } from '@instantdb/core'; import { InstantSvelteRoom } from './InstantSvelteRoom.svelte.js'; export type InfiniteQueryState, Q extends ValidQuery, UseDates extends boolean> = { isLoading: boolean; error: { message: string; } | undefined; data: InstaQLResponse | undefined; canLoadNextPage: boolean; loadNextPage: () => void; }; export declare class InstantSvelteDatabase, UseDates extends boolean = false, Rooms extends RoomSchemaShape = RoomsOf> implements IInstantDatabase { tx: import("@instantdb/core").TxChunk; auth: Auth; storage: Storage; streams: Streams; core: InstantCoreDatabase; constructor(core: InstantCoreDatabase); /** * Returns a unique ID for a given `name`. It's stored in local storage, * so you will get the same ID across sessions. * * @example * const deviceId = await db.getLocalId('device'); */ getLocalId: (name: string) => Promise; /** * Use this to write data! You can create, update, delete, and link objects * * @see https://instantdb.com/docs/instaml * * @example * const goalId = id(); * db.transact(db.tx.goals[goalId].update({title: "Get fit"})) */ transact: (chunks: TransactionChunk | TransactionChunk[]) => Promise; /** * One time query for the logged in state. * * @see https://instantdb.com/docs/auth * @example * const user = await db.getAuth(); * console.log('logged in as', user.email) */ getAuth(): Promise; /** * Use this for one-off queries. * Returns local data if available, otherwise fetches from the server. * * @see https://instantdb.com/docs/instaql * * @example * const resp = await db.queryOnce({ goals: {} }); * console.log(resp.data.goals) */ queryOnce: >(query: Q, opts?: InstaQLOptions) => Promise<{ data: InstaQLResponse; pageInfo: PageInfoResponse; }>; /** * Use this to query your data! * * @see https://instantdb.com/docs/instaql * * @example * // basic query * const state = db.useQuery({ goals: {} }); * // state.isLoading, state.error, state.data * * @example * // conditional query (pass a function that returns null to skip) * const auth = db.useAuth(); * const state = db.useQuery(() => * auth.user ? { todos: { $: { where: { 'owner.id': auth.user.id } } } } : null * ); * * @example * // reactive query (re-runs when $state variables change) * let filter = $state<'all' | 'done'>('all'); * const state = db.useQuery(() => { * if (filter === 'all') return { todos: {} }; * return { todos: { $: { where: { done: true } } } }; * }); */ useQuery: >(query: (() => null | Q) | null | Q, opts?: InstaQLOptions) => InstaQLLifecycleState; /** * Subscribe to a query and incrementally load more items. * * Only one top level namespace in the query is allowed. * * @see https://instantdb.com/docs/instaql * * @example * const state = db.useInfiniteQuery({ * posts: { * $: { * limit: 20, * order: { createdAt: 'desc' }, * }, * }, * }); * // state.data, state.isLoading, state.error, * // state.canLoadNextPage, state.loadNextPage() */ useInfiniteQuery: >(query: (() => null | Q) | null | Q, opts?: InstaQLOptions) => InfiniteQueryState; /** * Listen for the logged in state. This is useful * for deciding when to show a login screen. * * @see https://instantdb.com/docs/auth * @example * const auth = db.useAuth(); * // auth.isLoading, auth.user, auth.error */ useAuth: () => AuthState; /** * Subscribe to the currently logged in user. * If the user is not logged in, this will throw an Error. * * @see https://instantdb.com/docs/auth * @example * const user = db.useUser(); * // user.email, user.id, etc. * // Throws if not logged in */ useUser: () => User; /** * Listen for connection status changes to Instant. * * @see https://www.instantdb.com/docs/patterns#connection-status * @example * const status = db.useConnectionStatus(); * // status.current */ useConnectionStatus: () => { current: ConnectionStatus; }; /** * A hook that returns a unique ID for a given `name`. localIds are * stored in local storage, so you will get the same ID across sessions. * * Initially returns `null`, and then loads the localId. * * @example * const deviceId = db.useLocalId('device'); * // deviceId.current is null initially, then the ID string */ useLocalId: (name: string) => { current: string | null; }; /** * Obtain a handle to a room, which allows you to listen to topics and presence data * * @see https://instantdb.com/docs/presence-and-topics * * @example * const room = db.room('chat', roomId); * const presence = db.rooms.usePresence(room); */ room(type?: RoomType, id?: string): InstantSvelteRoom; /** * Hooks for working with rooms * * @see https://instantdb.com/docs/presence-and-topics * * @example * const room = db.room('chat', roomId); * const presence = db.rooms.usePresence(room); * const publish = db.rooms.usePublishTopic(room, 'emoji'); */ rooms: { useTopicEffect: typeof import("./InstantSvelteRoom.svelte.js").useTopicEffect; usePublishTopic: typeof import("./InstantSvelteRoom.svelte.js").usePublishTopic; usePresence: typeof import("./InstantSvelteRoom.svelte.js").usePresence; useSyncPresence: typeof import("./InstantSvelteRoom.svelte.js").useSyncPresence; useTypingIndicator: typeof import("./InstantSvelteRoom.svelte.js").useTypingIndicator; }; } /** * The first step: init your application! * * Visit https://instantdb.com/dash to get your `appId` :) * * @example * import { init } from "@instantdb/svelte" * * const db = init({ appId: "my-app-id" }) * * // You can also provide a schema for type safety and editor autocomplete! * * import { init } from "@instantdb/svelte" * import schema from "../instant.schema.ts"; * * const db = init({ appId: "my-app-id", schema }) */ export declare function init, UseDates extends boolean = false>(config: Omit, 'useDateObjects'> & { useDateObjects?: UseDates; }): InstantSvelteDatabase; //# sourceMappingURL=InstantSvelteDatabase.svelte.d.ts.map