// Auto-generated TypeScript definitions for Datahike JavaScript API // DO NOT EDIT - Generated from datahike.api.specification // Core Datahike Types export type Keyword = `:${string}`; export type Attribute = Keyword; declare const datahikeUuidBrand: unique symbol; /** Opaque UUID input returned by uuid() and randomUuid(). */ export interface DatahikeUuid { readonly [datahikeUuidBrand]: true; } /** UUID values returned by the JavaScript boundary are ordinary strings. */ export type UuidValue = string; /** A named branch (for example `':db'` or `':feature'`). */ export type BranchName = Keyword; /** A branch name or an input UUID created with uuid(). */ export type VersionRef = BranchName | DatahikeUuid; export interface GcOptions { /** Keep objects written within this many milliseconds, even if unreachable. */ 'min-age-ms'?: number; } export interface StoreConfig { backend: Keyword; id?: DatahikeUuid; path?: string; [key: string]: any; } /** S3 backend configuration for the opt-in `datahike/s3` browser entry. */ export interface S3StoreConfig extends StoreConfig { backend: ':s3'; id: DatahikeUuid; endpoint: string; bucket: string; 'access-key': string; secret: string; region?: string; 'session-token'?: string; 'path-style?'?: boolean; config?: { 'optimistic-locking-retries'?: number; [key: string]: any; }; } /** * Browser-safe Datahike storage: a complete synchronous memory frontend over * an asynchronous, authoritative S3 backend. Bare S3StoreConfig is not a * usable Datahike query store in browsers. */ export interface TieredS3StoreConfig extends StoreConfig { backend: ':tiered'; id: DatahikeUuid; 'frontend-config': { backend: ':memory'; id: DatahikeUuid }; 'backend-config': S3StoreConfig; 'write-policy'?: ':write-through'; 'read-policy'?: ':frontend-first'; } export interface WriterConfig { backend: Keyword; [key: string]: any; } export interface ConnectOptions { /** * Preserve the ClojureScript API's execution mode. Memory stores can run * synchronously; browser and remote stores use false and resolve a Promise. */ 'sync?'?: boolean; [key: string]: any; } /** Persistent browser backend registered by the `datahike/kabel` entry. */ export interface IndexedDbStoreConfig extends StoreConfig { backend: ':indexeddb'; id: DatahikeUuid; name?: string; } /** Synchronous memory frontend over an authoritative IndexedDB cache. */ export interface TieredIndexedDbStoreConfig extends StoreConfig { backend: ':tiered'; id: DatahikeUuid; 'frontend-config': { backend: ':memory'; id: DatahikeUuid }; 'backend-config': IndexedDbStoreConfig; 'write-policy'?: ':write-through'; 'read-policy'?: ':frontend-first'; } export interface DatabaseConfig { store: StoreConfig; writer?: WriterConfig; branch?: Keyword; 'keep-history?'?: boolean; 'schema-flexibility'?: ':read' | ':write'; 'initial-tx'?: Transaction[]; name?: string; [key: string]: any; } declare const connectionBrand: unique symbol; export interface Connection { readonly [connectionBrand]: true; } declare const databaseBrand: unique symbol; export interface Database { readonly [databaseBrand]: true; } export type EntityId = number | string | [Attribute, any]; export type EntityMap = Record; export type Transaction = | [':db/add', EntityId, Attribute, any] | [':db/retract', EntityId, Attribute, any] | [Keyword, ...any[]] | EntityMap; export interface WithArgs { 'tx-data': Transaction[]; 'tx-meta'?: any; 'tx-options'?: { 'allow-index-backfill?'?: boolean } | null; } export interface QueryArgs { query: string | any[] | Record; args?: any[]; limit?: number; offset?: number; } export interface PullOptions { selector: any[]; eid: EntityId | EntityId[]; } export type Index = ':eavt' | ':aevt' | ':avet'; export interface IndexLookupArgs { index: Index; components?: any[] | null; } export interface IndexRangeArgs { attrid: Attribute; start: any; end: any; } export interface TransactionReport { 'db-before': Database; 'db-after': Database; 'tx-data': Datom[]; tempids: { [key: string]: number }; 'tx-meta'?: any; } export interface DurableCommitEvent { type: ':datahike/commit'; 'store-id': UuidValue; branch: Keyword; 'commit-id': UuidValue; 'parent-commit-ids': UuidValue[]; 'max-tx': number; 'tx-count': number; 'db-before': Database; 'db-after': Database; 'tx-reports': TransactionReport[]; } export interface Datom { e: number; a: Attribute; v: any; tx: number; added: boolean; } export interface Schema { [key: string]: { 'db/valueType': Keyword; 'db/cardinality': Keyword; 'db/unique'?: Keyword; 'db/index'?: boolean; [key: string]: any; }; } export interface Metrics { count: number; 'avet-count': number; 'per-attr-counts': Record; 'per-entity-counts'?: Record; 'temporal-count'?: number; 'temporal-avet-count'?: number; } export interface OptimisticOverlay { readonly __optimisticOverlayBrand: never; } export interface OptimisticOptions { 'max-pending'?: number; 'max-queue'?: number; 'prediction-timeout-ms'?: number | null; 'reconciliation-timeout-ms'?: number | null; } export interface OptimisticSubmitOptions { branch?: Keyword; } export interface OptimisticPredictionOptions extends OptimisticSubmitOptions { 'timeout-ms'?: number | null; } export type OptimisticTransactionInput = | Transaction[] | { 'tx-data': Transaction[]; 'tx-meta'?: any }; export type OptimisticResultStatus = | ':committed' | ':accepted' | ':reconciled' | ':rejected' | ':expired' | ':abandoned' | ':unknown' | ':detached'; export interface OptimisticResult { status: OptimisticResultStatus; error?: any; receipt?: any; 'tx-report'?: TransactionReport; outcome?: ':unknown' | ':committed'; reason?: any; 'accepted?'?: boolean; } export interface OptimisticHandle { ovId: string; result: Promise; } export interface OptimisticPendingEntry { 'ov-id': string; kind: ':writer' | ':prediction'; 'submitted-at': number; 'expires-at'?: number | null; 'expected-max-tx'?: number | null; branch?: string; 'acknowledged?': boolean; 'conflicting?': boolean; 'last-conflict-error'?: any; 'reconcile-deadline-at'?: number | null; 'reconciliation-stalled?'?: boolean; [key: string]: any; } export interface OptimisticChanges { added: Datom[]; removed: Datom[]; } export interface OptimisticTransition { revision: number; 'db-before': Database; 'db-after': Database; 'base-max-tx': number | null; cause: { type: string; [key: string]: any }; changes: OptimisticChanges | null; } export interface OptimisticStatusEvent { revision: number; 'ov-id': string; kind: ':writer' | ':prediction'; status: | ':visible' | ':acknowledged' | ':committed' | ':reconciled' | ':rejected' | ':expired' | ':abandoned' | ':conflicting' | ':applicable' | ':reconciliation-error' | ':reconciliation-stalled' | ':unknown' | ':detached'; [key: string]: any; } // API Functions /** * Returns database state at given time point (Date or transaction ID).. * * Examples: * - Query as of date * (q '[:find ?n :where [_ :name ?n]] (as-of @conn date)) * - Query as of transaction * (as-of @conn 536870913) */ export function asOf(arg0: Database, arg1: number | Date): Promise; /** * Return this database snapshot's active AVET request or most recent result, or nil. */ export function avetBuildStatus(arg0: Database): Promise | null>; /** * Start a background AVET build on a local JVM shared, explicitly fenced, non-crypto persistent-set writer. */ export function beginAvetBuild(arg0: Connection, arg1: Record): Promise; /** * Create a new branch from an existing branch or commit. * * Examples: * - Branch from main * (branch! conn :db :experiment) * - Branch from specific commit * (branch! conn #uuid "..." :hotfix) */ export function branch(conn: Connection, from: VersionRef, newBranch: Keyword): Promise; /** * Load the database at a branch head. * * Examples: * - Load db at branch * (branch-as-db conn :experiment) */ export function branchAsDb(source: Connection | Database, branch: Keyword): Promise; /** * List all known branch names. * * Examples: * - List branches * (branches conn) */ export function branches(conn: Connection): Promise>; /** * Cancel the exact UUID generation of a local JVM AVET build. */ export function cancelAvetBuild(arg0: Connection, arg1: DatahikeUuid): Promise; /** * Load the database at a specific commit. * * Examples: * - Load db at commit * (commit-as-db conn #uuid "...") */ export function commitAsDb(source: Connection | Database, commit: DatahikeUuid): Promise; /** * Retrieve the commit-id for this database value.. * * Examples: * - Get commit id * (commit-id @conn) */ export function commitId(db: Database): Promise; /** * Connects to a Datahike database via configuration map.. * * Examples: * - Connect to default in-memory database * (connect) * - Connect to file-based database * (connect {:store {:backend :file :path "/tmp/example"}}) */ export function connect(config: DatabaseConfig): Promise; export function connect(config: DatabaseConfig, opts: ConnectOptions): Promise; export function connect(): Promise; /** * Creates a database via configuration map.. * * Examples: * - Create empty database * (create-database {:store {:backend :memory :id "example"}}) * - Create with schema-flexibility :read * (create-database {:store {:backend :memory :id "example"} :schema-flexibility :read}) */ export function createDatabase(arg0: DatabaseConfig): Promise; export function createDatabase(): Promise; /** * Checks if a database exists via configuration map.. * * Examples: * - Check if in-memory database exists * (database-exists? {:store {:backend :memory :id "example"}}) * - Check with default config * (database-exists?) */ export function databaseExists(arg0: DatabaseConfig): Promise; export function databaseExists(): Promise; /** * Index lookup. * * Examples: * - Find all datoms for entity * (datoms db {:index :eavt :components [1]}) * - Find datoms for entity and attribute * (datoms db {:index :eavt :components [1 :likes]}) */ export function datoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet" | IndexLookupArgs): Promise; export function datoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet", ...components: Array): Promise; /** * Returns the underlying immutable database value from a connection. * * Examples: * - Get database from connection * (db conn) * - Prefer direct deref * @conn */ export function db(conn: Connection): Promise; /** * Applies transaction to immutable db value, returns new db. * * Examples: * - Get db after transaction * (db-with @conn [[:db/add 1 :name "Ivan"]]) */ export function dbWith(db: Database, tx: Transaction[] | WithArgs): Promise; /** * Remove a branch. * * Examples: * - Delete branch * (delete-branch! conn :experiment) */ export function deleteBranch(conn: Connection, branch: Keyword): Promise; /** * Deletes a database given via configuration map.. * * Examples: * - Delete database * (delete-database {:store {:backend :memory :id "example"}}) */ export function deleteDatabase(arg0: DatabaseConfig): Promise; export function deleteDatabase(): Promise; /** * Retrieves an entity by its id. * * Examples: * - Get entity by id * (entity db 1) * - Get entity by lookup ref * (entity db [:email "alice@example.com"]) */ export function entity(db: Database, eid: number | [string, any] | string | any): Promise; /** * Returns database that entity was created from.. * * Examples: * - Get entity's database * (entity-db (entity db 1)) */ export function entityDb(arg0: any): Promise; /** * Returns a human-readable string explaining the query plan. * * Examples: * - Explain a simple query * (explain '[:find ?e :where [?e :name]] db) * - Explain a recursive rule * (explain '[:find ?e2 :in $ ?e1 % :where (follow ?e1 ?e2)] db 1 '[[(follow ?e1 ?e2) [?e1 :follow ?e2]] [(follow ?e1 ?e2) [?e1 :follow ?t] (follow ?t ?e2)]]) */ export function explain(arg0: Array | Record, ...arg1: Array): Promise; /** * Returns filtered view over database. * * Examples: * - Filter to recent datoms * (filter db (fn [db datom] (> (:tx datom) recent-tx))) */ export function filter(arg0: Database, arg1: any): Promise; /** * Force a branch to point to the provided db value. * * Examples: * - Force branch to current db * (force-branch! @conn :experiment #{:db}) */ export function forceBranch(db: Database, branch: Keyword, parents: VersionRef[]): Promise; /** * Invokes garbage collection on connection's store. * * Examples: * - GC all old snapshots * (gc-storage conn) * - GC snapshots before date * (gc-storage conn (java.util.Date.)) */ export function gcStorage(conn: Connection, removeBefore: number | Date, options: GcOptions): Promise; export function gcStorage(conn: Connection, removeBefore: number | Date): Promise; export function gcStorage(conn: Connection): Promise; /** * Returns full historical state of database including all assertions and retractions.. * * Examples: * - Query historical data * (q '[:find ?n ?a :where [?e :name ?n] [?e :age ?a]] (history @conn)) */ export function history(arg0: Database): Promise; /** * Returns part of :avet index between start and end values.. * * Examples: * - Find datoms in value range * (index-range db {:attrid :likes :start "a" :end "z"}) * - Find entities with age in range * (->> (index-range db {:attrid :age :start 18 :end 60}) (map :e)) */ export function indexRange(db: Database, options: IndexRangeArgs): Promise; /** * Returns true if database was filtered using filter, false otherwise.. * * Examples: * - Check if filtered * (is-filtered db) */ export function isFiltered(arg0: Database): Promise; /** * Listen for changes on connection. * * Examples: * - Listen with callback * (listen conn (fn [tx-report] (println "Transaction:" (:tx-data tx-report)))) * - Listen with key * (listen conn :my-listener (fn [tx-report] ...)) */ export function listen(conn: Connection, listener: (report: TransactionReport) => void): Promise; export function listen(conn: Connection, key: any, listener: (report: TransactionReport) => void): Promise; /** * Listen once per successful durable writer commit. * * Examples: * - Observe durable branch-head transitions * (listen-commits conn :publisher (fn [{:keys [commit-id parent-commit-ids]}] ...)) */ export function listenCommits(conn: Connection, listener: (event: DurableCommitEvent) => void): Promise; export function listenCommits(conn: Connection, key: any, listener: (event: DurableCommitEvent) => void): Promise; /** * Load entities directly (bulk load).. * * Examples: * - Bulk load entities * (load-entities conn entities) */ export function loadEntities(arg0: Connection, arg1: Transaction[]): Promise; /** * Async version of merge-db. * * Examples: * - Async merge * @(d/merge-db! conn #{:feature} [{:name "merged"}]) */ export function mergeDb(conn: Connection, parents: VersionRef[], tx: Transaction[]): Promise; export function mergeDb(conn: Connection, parents: VersionRef[], tx: Transaction[], txMeta: unknown): Promise; /** * Returns database metrics: datom counts overall, per attribute and for the indexed (AVET) attributes, plus the same for history when kept. * * Examples: * - Get metrics * (metrics @conn) * - With datoms per entity (a full walk) * (metrics @conn {:per-entity-counts? true}) */ export function metrics(arg0: Database): Promise; export function metrics(arg0: Database, arg1: Record): Promise; /** * Retrieve parent commit ids from this database value.. * * Examples: * - Get parent commits * (parent-commit-ids @conn) */ export function parentCommitIds(db: Database): Promise; /** * Fetches data using recursive declarative pull pattern.. * * Examples: * - Pull with pattern * (pull db [:db/id :name :likes {:friends [:db/id :name]}] 1) * - Pull with arg-map * (pull db {:selector [:db/id :name] :eid 1}) */ export function pull = Record>(db: Database, patternOrOptions: PullOptions): Promise; export function pull = Record>(db: Database, patternOrOptions: Array, eid: number | [string, any] | string): Promise; /** * Same as pull, but accepts sequence of ids and returns sequence of maps.. * * Examples: * - Pull multiple entities * (pull-many db [:db/id :name] [1 2 3]) */ export function pullMany = Record>(db: Database, patternOrOptions: PullOptions): Promise; export function pullMany = Record>(db: Database, patternOrOptions: Array, eids: Array): Promise; /** * Executes a datalog query.. * * Examples: * - Query with vector syntax * (q '[:find ?value :where [_ :likes ?value]] db) * - Query with map syntax * (q '{:find [?value] :where [[_ :likes ?value]]} db) */ export function q(query: QueryArgs): Promise; export function q(query: Array | Record | string, ...inputs: Array): Promise; /** * Executes query and returns execution statistics.. * * Examples: * - Query with stats * (query-stats '[:find ?e :where [?e :name]] db) */ export function queryStats(query: QueryArgs): Promise>; export function queryStats(query: Array | Record, ...inputs: Array): Promise>; /** * Releases a database connection.. * * Examples: * - Release connection * (release conn) */ export function release(conn: Connection): Promise; export function release(conn: Connection, releaseAll: any): Promise; /** * Returns reverse schema definition (attribute id to ident mapping).. * * Examples: * - Get reverse schema * (reverse-schema @conn) */ export function reverseSchema(arg0: Database): Promise>; /** * Like seek-datoms, but iterates BACKWARDS: datoms <= the given components, descending to the beginning of the index. * * Examples: * - Latest room messages, newest first * (take 20 (rseek-datoms db {:index :avet :components [:message/room room-eid]})) */ export function rseekDatoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet" | IndexLookupArgs): Promise; export function rseekDatoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet", ...components: Array): Promise; /** * Returns current schema definition.. * * Examples: * - Get schema * (schema @conn) */ export function schema(arg0: Database): Promise; /** * Like datoms, but returns datoms starting from specified components through end of index.. * * Examples: * - Seek from entity * (seek-datoms db {:index :eavt :components [1]}) */ export function seekDatoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet" | IndexLookupArgs): Promise; export function seekDatoms(db: Database, indexOrOptions: ":eavt" | ":aevt" | ":avet", ...components: Array): Promise; /** * Returns database state since given time point (Date or transaction ID). * * Examples: * - Query since date * (since @conn (java.util.Date.)) * - Query since transaction * (since @conn 536870913) */ export function since(arg0: Database, arg1: number | Date): Promise; /** * Allocates temporary id (negative integer). * * Examples: * - Generate tempid * (tempid :db.part/user) * - Prefer direct negative integers * (transact conn [{:db/id -1 :name "Alice"}]) */ export function tempid(arg0: Keyword): Promise; export function tempid(arg0: Keyword, arg1: number): Promise; /** * Same as transact, but asynchronously returns a future. * * Examples: * - Async transaction * @(transact! conn [{:db/id -1 :name "Alice"}]) */ export function transact(conn: Connection, tx: Transaction[] | WithArgs): Promise; /** * Removes registered listener from connection.. * * Examples: * - Remove listener * (unlisten conn :my-listener) */ export function unlisten(conn: Connection, key: any): Promise>; /** * Remove a durable commit listener.. * * Examples: * - Stop observing durable commits * (unlisten-commits conn :publisher) */ export function unlistenCommits(conn: Connection, key: any): Promise>; /** * Strip any valid-time markers from `db` so the full vt-history is visible. * * Examples: * - Drop vt-marker for full-history query * (q '[:find ?n :where [_ :name ?n]] (valid-all @conn)) */ export function validAll(arg0: Database): Promise; /** * Tag `db` with a `:datahike/valid-at` marker so vt-aware secondary indices push the filter through `-search-at-vt`. * * Examples: * - Query as of valid-time * (q '[:find ?n :where [_ :name ?n]] (valid-at @conn #inst "2024-04-15")) */ export function validAt(arg0: Database, arg1: any): Promise; /** * Filter `db` to datoms whose asserting tx's vt-window overlaps the half-open interval `[from, to)`. * * Examples: * - Datoms whose tx vt-window overlaps Q2 2024 * (q '[:find ?n :where [_ :name ?n]] (valid-between @conn #inst "2024-04-01" #inst "2024-07-01")) */ export function validBetween(arg0: Database, arg1: any, arg2: any): Promise; /** * Filter `db` to datoms whose tx's vt-window is *fully contained* in `[from, to)`. * * Examples: * - Corrections whose vt-window was wholly inside Q2 * (q '[:find ?e :where [?e :name _]] (valid-during @conn #inst "2024-04-01" #inst "2024-07-01")) */ export function validDuring(arg0: Database, arg1: any, arg2: any): Promise; /** * Applies transaction to immutable db value. * * Examples: * - Transaction on db value * (with @conn [[:db/add 1 :name "Ivan"]]) * - With metadata * (with @conn {:tx-data [...] :tx-meta {:source :import}}) */ export function withDb(db: Database, tx: Transaction[] | WithArgs): Promise; export function withDb(db: Database, tx: Transaction[], txMeta: any): Promise; export function withDb(db: Database, tx: Transaction[], txMeta: any, arg3: any): Promise; // Explicit optimistic overlay API. Unlike specification-generated functions, // snapshot reads and lifecycle commands are synchronous. export function openOptimistic(conn: Connection, opts?: OptimisticOptions): OptimisticOverlay; export function optimisticDb(overlay: OptimisticOverlay): Database; export function optimisticPending(overlay: OptimisticOverlay): OptimisticPendingEntry[]; export function optimisticTransact(overlay: OptimisticOverlay, txData: OptimisticTransactionInput, opts?: OptimisticSubmitOptions): OptimisticHandle; export function optimisticPredict(overlay: OptimisticOverlay, txData: OptimisticTransactionInput, reconciled: (db: Database) => boolean, opts?: OptimisticPredictionOptions): OptimisticHandle; export function optimisticAck(overlay: OptimisticOverlay, ovId: string, receipt?: any): null; export function optimisticReject(overlay: OptimisticOverlay, ovId: string, error: any): null; export function optimisticAbandon(overlay: OptimisticOverlay, ovId: string, reason?: any): null; export function optimisticListen(overlay: OptimisticOverlay, listener: (event: OptimisticTransition) => void): () => void; export function optimisticListenStatus(overlay: OptimisticOverlay, listener: (event: OptimisticStatusEvent) => void): () => void; export function closeOptimistic(overlay: OptimisticOverlay): null; // JavaScript-specific value helpers. export function isPromise(value: any): value is Promise; export function uuid(value: string): DatahikeUuid; export function randomUuid(): DatahikeUuid; export type LogLevel = 'off' | 'trace' | 'debug' | 'info' | 'warn' | 'error'; /** * Configure logging for the Datahike JavaScript package. * The initial level is `warn`, or `DATAHIKE_LOG_LEVEL` in Node.js. */ export function setLogLevel(level: LogLevel): LogLevel;