declare abstract class CborCodec { abstract encode(value: unknown): Uint8Array; abstract decode(value: Uint8Array): T; } type EventListener = (...args: TArgs) => void; type EventUnsubscriber = () => void; declare class EventEmitter> { #private; on(event: TEvent, listener: EventListener): EventUnsubscriber; once(event: TEvent, listener: EventListener): EventUnsubscriber; off(event: TEvent, listener: EventListener): void; emit(event: TEvent, ...args: TEvents[TEvent]): void; waitNext(event: TEvent, signal?: AbortSignal): Promise; } type Auth = { type: "root"; username: string; password: string; } | { type: "database"; namespace: string; database: string; username: string; password: string; } | { type: "namespace"; namespace: string; username: string; password: string; } | { type: "token"; token: string; }; type RpcRequest = { method: TMethod; params: TParams; version?: number; }; type RpcResponse = RpcResponseOk | RpcResponseError; type RpcResponseOk = { result: TResult; error?: undefined; }; type RpcResponseError = { result?: undefined; error: { code: number; message: string; }; }; type WithId = T & { id: number; }; type EngineOptions = { namespace?: string; database?: string; auth?: Auth; cbor?: CborCodec; }; type ConnectionState = { token?: string; }; declare enum ConnectionStatus { CONNECTING = "CONNECTING", CONNECTED = "CONNECTED", DISCONNECTING = "DISCONNECTING", DISCONNECTED = "DISCONNECTED", ERROR = "ERROR" } type EmitterEvents = { connecting: []; connected: []; disconnecting: []; disconnected: [error?: Error]; error: [error: Error]; [Key: `rpc-${string}`]: [WithId]; [Key: `live-${string}`]: [any]; }; declare abstract class AbstractEngine extends EventEmitter { cbor: CborCodec; options: EngineOptions; state: ConnectionState; constructor(options?: EngineOptions); abstract isReady(): Promise; abstract getStatus(): ConnectionStatus; abstract connect(): Promise; abstract disconnect(): Promise; abstract rpc(request: RpcRequest): Promise>; abstract version(): Promise; } type HttpEngineOptions = { namespace?: string; database?: string; auth?: Auth; /** * Custom headers to send with every request. */ headers?: HeadersInit; cbor?: CborCodec; }; declare class HttpEngine extends AbstractEngine { #private; url: URL; constructor(url: URL | string, options?: HttpEngineOptions); getStatus(): ConnectionStatus; isReady(): Promise; connect(): Promise; disconnect(): Promise; rpc(request: RpcRequest): Promise>; version(): Promise; } type WebSocketEngineOptions = { namespace?: string; database?: string; auth?: Auth; poolSize?: number; readyTimeout?: number; reconnectTimeout?: number; cbor?: CborCodec; }; declare class WebSocketEngine extends AbstractEngine { #private; constructor(url: URL | string, options?: WebSocketEngineOptions); getStatus(): ConnectionStatus; isReady(): Promise; connect(): Promise; disconnect(): Promise; rpc(request: RpcRequest): Promise>; version(): Promise; } declare class DatabaseError extends Error { code: number; request: RpcRequest; constructor({ code, message }: RpcResponseError["error"], request: RpcRequest); } declare class QueryError extends Error { } declare class ConnectionError extends Error { details?: T; constructor(message: string, details?: T); } /** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ export interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result | Promise>; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ export type Result = SuccessResult | FailureResult; /** The result interface if validation succeeds. */ export interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ export interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ export interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ export interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ export interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ export type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ export type InferOutput = NonNullable["output"]; export { }; } type StandardSchema = StandardSchemaV1; type InferStandardInput = TSchema extends StandardSchema ? TInput : never; type InferStandardOutput = TSchema extends StandardSchema ? TOutput : never; declare class ValidationError extends Error { issues: readonly StandardSchemaV1.Issue[]; constructor(issues: readonly StandardSchemaV1.Issue[]); } /** * Validates a value against a schema and returns the validated value. * * If the schema validation fails, an error will be thrown. * * @param schema The schema to validate against. * @param value The value to validate. * @returns The validated value or an error if the validation failed. */ declare const parseSchema: (schema: TSchema, value: unknown) => Promise>; declare const mergeSchema: (schemas: StandardSchema[]) => StandardSchema; /** * A schema which defines what data is expected from the database. * * Optionally an input type can be provided which is useful * when you have futures or readonly fields in your database. * * Input type is used to generate types for create or update queries * while the result type is used for queries like select fields * or where conditions. */ type SchemaContext = { result: StandardSchema; input?: TInput; }; type InferResult = TContext extends SchemaContext ? TResult : never; type InferInput = TContext extends SchemaContext ? TInput : never; type UnknownSchemaContext = SchemaContext; type AnySchemaContext = SchemaContext; /** * A tagged template is a template literal with all variables as an array. */ type TaggedTemplate = [string[] | TemplateStringsArray, unknown[]]; /** * A variable converter function used in the {@link format} function to convert the variable values to strings. * * This is needed to convert a {@link TaggedTemplate} into a string. */ type FormatVariableConverter = (value: unknown, index: number) => string; /** * Function to create a tagged template using a template literals. * This also preserves the variables in the template. * * @returns A tagged template. */ declare const tag: (strings: string[] | TemplateStringsArray, ...values: unknown[]) => TaggedTemplate; /** * Function to create a tagged template from a string without any variables. * * @param str The string to create the tagged template from. * @returns A tagged template. */ declare const tagString: (str: string) => TaggedTemplate; /** * Function to merge multiple tagged templates into one. * * @param tags A list of tagged templates to merge. * @param join A optional join string which gets inserted between the tagged templates. * @returns A merged tagged template. */ declare const merge: (tags: TaggedTemplate[], join?: string) => TaggedTemplate; /** * Function to format a tagged template into a string. * * @param tag The tagged template to format. * @param variableConverter An optional variable converter function to convert the variable values to strings. (default: String constructor) * @returns The formatted string. */ declare const format: (tag: TaggedTemplate, variableConverter?: FormatVariableConverter) => string; /** * Check whether a tagged template is empty. * * This means that the template will be formatted to an empty string. * * @param template The tagged template to check. * @returns True if the template is empty, false otherwise. */ declare const isEmpty: (template: TaggedTemplate) => boolean; type QueryOptions = { /** * An optional connection to use for executing the query. * * If not provided, the default connection will be used if available. */ connection?: Surrealize; /** * An optional schema to use for validating the result. */ schema?: StandardSchema; }; type QueryListOptions = { /** * An optional connection to use for executing the query. * * If not provided, the default connection will be used if available. */ connection?: Surrealize; }; declare class Query { readonly template: TaggedTemplate; readonly connection?: Surrealize; schema?: StandardSchema; constructor(template: TaggedTemplate, options?: QueryOptions); withConnection(connection: Surrealize): Query; withSchema(schema?: StandardSchema): Query; with(options?: QueryOptions): Query; execute(): Promise; } declare class QueryList[]> { readonly queries: TQueries; readonly connection?: Surrealize; constructor(queries: TQueries, options?: QueryListOptions); withConnection(connection: Surrealize): QueryList; executeAll(): Promise>; executeTransaction(): Promise>; } /** * Create a query using a tagged template. * * @returns The query. */ declare const surql: (strings: string[] | TemplateStringsArray, ...values: unknown[]) => Query; /** * A raw query is a builder for a tagged template query. * * Every mutation returns a new {@link RawQuery} instance, so {@link RawQuery}s are immutable. */ declare class RawQuery { readonly template: TaggedTemplate; constructor(template?: TaggedTemplate); /** * Append a {@link TaggedTemplate} to the current template. * * @param template The {@link TaggedTemplate} or string to append. * @param join The join string to use between the queries. Defaults to a space. * @returns A new {@link RawQuery} with the appended template. */ append(template?: TaggedTemplate | string, join?: string): RawQuery; /** * Convert the query to a {@link Query} object which can be executed. * * @param options The options to use for the query. * @returns The query. */ toQuery(options?: QueryOptions): Query; static empty(): RawQuery; } type PreparedQuery = { query: string; bindings?: Record; }; /** * A queryable is an object which has a context containing the `toQuery` function. * * This function returns a {@link Query} or a {@link RawQuery}. */ type Queryable = Record<"toQuery", () => Query | RawQuery>; /** * A query like type which can be a {@link Query} or a {@link Queryable}. */ type QueryLike = Query | Queryable; /** * This is a list of ${@link QueryLike} objects. */ type QueriesLike = QueryLike[]; /** * Infer the output type of a {@link QueryLike} object. */ type InferQueryOutput = TQuery extends QueryLike ? TOutput : never; /** * Infer the output type of a list of {@link QueryLike} objects. */ type InferQueriesOutput = { [Key in keyof TQueries]: InferQueryOutput; }; /** * A deep partial type which allows for deeply partially defined objects and arrays. */ type DeepPartial = T extends Record | Array ? { [P in keyof T]?: DeepPartial; } : T; /** * A type which only makes a subset of keys partial. */ type PartialOnly = Omit & Partial>; /** * A type which only makes a subset of keys required. */ type RequiredOnly = Omit & Required>; type OptionalId> = PartialOnly; type RequiredId> = RequiredOnly; type _Record = { id: TId; }; type AnyRecord = _Record & { [key: string]: unknown; }; type RecordSchemaContext = SchemaContext>; type InferTableFromSchema = TSchema extends RecordSchemaContext ? TRecordId["table"] : string; /** * A type which represents multiple way of specifying a table. * * Including the {@link Table} itself and a string representation of the table. */ type TableLike = Table | TTable; /** * The table is a collection of records in SurrealDB. */ declare class Table { readonly name: TTable; constructor(name: TTable); /** * Checks if the table is equal to another table. * * @param table The table to compare with. * @returns True if the tables are equal, false otherwise. */ equals(table: Table): table is Table; /** * Checks if a record id is belonging to the table. * * @param recordId The record id to check. * @returns True if record id belongs to the table, false otherwise. */ contains(recordId: RecordId): boolean; /** * Create a record id which belongs to the table. * * @param id The id of the record id. * @returns A record id which belongs to the table. */ getRecordId(id: TId): RecordId; /** * Get the string representation of the table. * * This is simply the name of the table. * * @returns The string representation of the table. */ toString(): string; /** * Instantiate a table from a table like input. * * @param table The table like input. * @returns The instantiated table. */ static from(table: TableLike): Table; } declare class UUID { readonly bytes: Uint8Array; constructor(bytes: Uint8Array); } /** * The value type of a the id part of a record id. */ type RecordIdValue = string | number | bigint | UUID | unknown[] | Record; /** * A type which represents multiple way of specifying a record id. * * Including the {@link RecordId} itself and a string representation of the record id. */ type RecordIdLike = RecordId | `${TTable}:${Extract}`; /** * The record id is the primary key of a record in SurrealDB and is used to identify a record. * * It consists of the table name and an arbitrary id value. */ declare class RecordId { readonly table: TTable; readonly value: TValue; constructor(table: TTable, value: TValue); /** * Checks if the record id is equal to another record id. * * @param recordId The record id to compare with. * @returns True if the record ids are equal, false otherwise. */ equals(recordId: RecordId): recordId is RecordId; /** * Get the table of the record id. * * @returns The table of the record id. */ getTable(): Table; /** * Resolve the actual associated record of the record id using a surrealize connection. * * @param options The options to resolve the record. * @returns The resolved record. */ resolve(options?: { /** * The surrealize connection to use for resolving the record. * * If not provided, the default connection will be used (if set). */ connection?: Surrealize; /** * The schema to use for validating the resolved record. */ schema?: StandardSchema; }): Promise; /** * Instantiate a record id from a table and value. * * @example * ```ts * const rid1 = RecordId.from("user", "bob"); * const rid2 = RecordId.from(Table.from("user"), "bob"); * const rid3 = RecordId.from("sensor", ["SENSOR_1", new Date()]); * ``` * * @param table The table of the record id. * @param value The value of the record id. * @returns The instantiated record id. */ static from(table: TableLike, id: TValue): RecordId; /** * Instantiate a record id from a record id like input. * * @example * ```ts * const rid = RecordId.from("user:bob"); * ``` * * @param recordId The record id like input. * @returns The instantiated record id. */ static from(recordId: RecordIdLike): RecordId; } /** * A target is either a table or a record id. * * This type represents a target in multiple ways. Like a table or a record id in string representation or in its own types. * * @example * * ```ts * * // RecordId * const rid1: TargetLike = "users:123"; * const rid2: TargetLike = new RecordId("users", "123"); * const rid3: TargetLike = RecordId.from("users", "123"); * * // Table * const table1: TargetLike = "users"; * const table2: TargetLike = new Table("users"); * const table3: TargetLike = Table.from("users"); * ``` */ type TargetLike = TableLike | RecordIdLike; /** * The resolved target type which infers a target like type and returns either a record id or a table depending on the target. * * This is the return type of the {@link resolveTarget} function. */ type ResolvedTarget = TTarget extends RecordIdLike ? RecordId : TTarget extends TableLike ? Table : never; /** * Resolves a target and returns either a record id or a table depending on the target. * * @param target The target to resolve. * @returns The resolved target (either a record id or a table). */ declare const resolveTarget: (target: TTarget) => ResolvedTarget; type SurrealizeOptions = { /** * Set the connection as the default connection. * * This will make the Surrealize instance the default instance for all queries. */ default?: boolean; }; declare class Surrealize { static default: Surrealize | undefined; readonly engine: AbstractEngine; readonly options: SurrealizeOptions; constructor(engine: AbstractEngine, options?: SurrealizeOptions); connect(): Promise; disconnect(): Promise; version(): Promise; execute(queryLike: QueryLike): Promise; executeAll(queriesLike: TQueries): Promise>; executeTransaction(queriesLike: TQueries): Promise>; /** * Get a specific target from the database. A target can be a record id or a table. * In case the target is a table, the result will be an array of records. * * @param targetLike A target like input (record id or table). * @param schema The optional schema to use for validating the result. * @returns The target from the database. */ resolve(targetLike: TargetLike, schema?: StandardSchema): Promise; query(query: string, bindings?: Record): Promise; } type BuilderContext = { schema?: TSchema; connection?: Surrealize; }; type Statement any = (...args: any[]) => any> = (query: RawQuery, ctx: BuilderContext) => TFn; type Builder = Record> = { [Key in keyof TStatements]: TStatements[Key] extends Statement ? TFn : never; }; type WithBuilderContext = { toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; }; declare const DURATIONS: { ns: bigint; us: bigint; µs: bigint; ms: bigint; s: bigint; m: bigint; h: bigint; d: bigint; w: bigint; y: bigint; }; type DurationUnit = keyof typeof DURATIONS; type DurationValueUnit = `${number}${TUnit}` | ``; type DurationValue = `${DurationValueUnit<"y">}${DurationValueUnit<"w">}${DurationValueUnit<"d">}${DurationValueUnit<"h">}${DurationValueUnit<"m">}${DurationValueUnit<"s">}${DurationValueUnit<"ms">}${DurationValueUnit<"µs">}${DurationValueUnit<"us">}${DurationValueUnit<"ns">}`; type DurationLike = DurationValue | Duration | bigint | number; declare class Duration { #private; /** * Create a new duration. * * @param duration The duration in nanoseconds. */ constructor(duration: bigint); add(duration: DurationLike): Duration; substract(duration: DurationLike): Duration; get nanoseconds(): bigint; get milliseconds(): bigint; get microseconds(): bigint; get seconds(): bigint; get minutes(): bigint; get hours(): bigint; get days(): bigint; get weeks(): bigint; get years(): bigint; /** * Create a new duration from a value and an unit. * * @param value The value as a number or bigint. * @param unit The unit of the duration. * @returns The duration. */ static from(value: bigint | number, unit: DurationUnit): Duration; /** * Create a new duration from a duration like input. * * @param duration The input duration can be a duration string (e.g. `1y2w3d4h5m6s7ms8µs9ns`), * a number/bigint (in milliseconds) or a duration object itself. * @returns The duration. */ static from(duration: DurationLike): Duration; /** * Parse a duration string into a duration object. * * @param duration The duration string (e.g. `1y2w3d4h5m6s7ms8µs9ns`) * @returns The duration. */ static parseString(duration: DurationValue): Duration; static zero(): Duration; static years(value: number | bigint): Duration; static weeks(value: number | bigint): Duration; static days(value: number | bigint): Duration; static hours(value: number | bigint): Duration; static minutes(value: number | bigint): Duration; static seconds(value: number | bigint): Duration; static milliseconds(value: number | bigint): Duration; static microseconds(value: number | bigint): Duration; static nanoseconds(value: number | bigint): Duration; } type RawField = unknown extends T ? string : Extract; type Field = RawField>; type InputField = RawField>; type ContentLike = InferInput extends Record ? InferInput : Record; type SetLike = { [Key in InputField]?: unknown; }; type UnsetLike = InputField[]; type MergeLike<_TSchema extends SchemaContext> = Record; type PatchLike<_TSchema extends SchemaContext> = Record; type ReturnType = "none" | "after" | "before" | "diff"; declare const create: (query: RawQuery, ctx: BuilderContext) => (targets: TargetLike | TargetLike[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; content: typeof content$2; set: typeof set$2; return: typeof _return$3; timeout: typeof timeout$4; parallel: typeof parallel$4; }>; declare const createOnly: (query: RawQuery, ctx: BuilderContext) => (target: TargetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; content: typeof content$2; set: typeof set$2; return: typeof _return$3; timeout: typeof timeout$4; parallel: typeof parallel$4; }>; declare const content$2: (query: RawQuery, ctx: BuilderContext) => (content?: ContentLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; return: typeof _return$3; timeout: typeof timeout$4; parallel: typeof parallel$4; }>; declare const set$2: (query: RawQuery, ctx: BuilderContext) => (set?: SetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; return: typeof _return$3; timeout: typeof timeout$4; parallel: typeof parallel$4; }>; declare const _return$3: (query: RawQuery, ctx: BuilderContext) => (type?: ReturnType) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; timeout: typeof timeout$4; parallel: typeof parallel$4; }>; declare const timeout$4: (query: RawQuery, ctx: BuilderContext) => (timeout?: DurationLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; parallel: typeof parallel$4; }>; declare const parallel$4: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder>; type WhereState = { conditions: WhereCondition[]; }; type CompareOperator = "=" | "!=" | "==" | "~" | "!~" | "<" | "<=" | ">" | ">="; type WhereCondition = WhereCompare> | WhereAnd | WhereOr; type WhereCompare = { type: "cmp"; field: TField; operator: TOperator; value: TValue; }; type WhereAnd = { type: "and"; conditions: WhereCondition[]; }; type WhereOr = { type: "or"; conditions: WhereCondition[]; }; declare const buildWhere: (conditions?: WhereCondition[]) => TaggedTemplate | undefined; /** * Create a `AND` condition. * * @param conditions The conditions to combine. * @returns The `AND` condition. */ declare const and: (...conditions: WhereCondition[]) => WhereAnd; /** * Create a `OR` condition. * * @param conditions The conditions to combine. * @returns The `OR` condition. */ declare const or: (...conditions: WhereCondition[]) => WhereOr; /** * Create a comparator for a field. * * @param field The field to compare. * @param operator The operator to use. * @param value The value to compare with. * @returns The comparator. */ declare const cmp: (field: TField, operator: TOperator, value: TValue) => WhereCompare; /** * Compares a field using the `==` operator. (strict equality) * * @param field The field to compare. * @param value The value to compare with. * @returns The comparator. */ declare const eq: (field: TField, value: TValue) => WhereCompare", TValue>; /** * Compares a field using the `>=` operator. (greater than or equal) * * @param field The field to compare. * @param value The value to compare with. * @returns The comparator. */ declare const gte: (field: TField, value: TValue) => WhereCompare=", TValue>; /** * Compares a field using the `<` operator. (less than) * * @param field The field to compare. * @param value The value to compare with. * @returns The comparator. */ declare const lt: (field: TField, value: TValue) => WhereCompare; /** * Compares a field using the `<=` operator. (less than or equal) * * @param field The field to compare. * @param value The value to compare with. * @returns The comparator. */ declare const lte: (field: TField, value: TValue) => WhereCompare) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$3; return: typeof _return$2; timeout: typeof timeout$3; parallel: typeof parallel$3; }>; declare const deleteOnly: (query: RawQuery, ctx: BuilderContext) => (target: TargetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$3; return: typeof _return$2; timeout: typeof timeout$3; parallel: typeof parallel$3; }>; declare const where$3: (query: RawQuery, ctx: BuilderContext) => (conditions?: WhereCondition[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; return: typeof _return$2; timeout: typeof timeout$3; parallel: typeof parallel$3; }>; declare const _return$2: (query: RawQuery, ctx: BuilderContext) => (type?: ReturnType) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; timeout: typeof timeout$3; parallel: typeof parallel$3; }>; declare const timeout$3: (query: RawQuery, ctx: BuilderContext) => (timeout?: DurationLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; parallel: typeof parallel$3; }>; declare const parallel$3: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder>; declare const orderDirectionMapping: { asc: string; ascending: string; desc: string; descending: string; }; declare const orderModeMapping: { collate: string; numeric: string; }; type OrderDirection = keyof typeof orderDirectionMapping; type OrderMode = keyof typeof orderModeMapping; type OrderFieldOptions = { field: Field; mode?: OrderMode; direction?: OrderDirection; }; type OrderFields = "rand" | Array | OrderFieldOptions>; declare const select: (query: RawQuery, ctx: BuilderContext) => (fields?: Field[] | "*") => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; from: typeof from; fromOnly: typeof fromOnly; }>; declare const selectValue: (query: RawQuery, ctx: BuilderContext) => (field: Field) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; from: typeof from; fromOnly: typeof fromOnly; }>; declare const from: (query: RawQuery, ctx: BuilderContext) => (targets: TargetLike> | TargetLike>[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; with: typeof _with; where: typeof where$2; split: typeof split; group: typeof group; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const fromOnly: (query: RawQuery, ctx: BuilderContext) => (target: TargetLike>) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; with: typeof _with; where: typeof where$2; split: typeof split; group: typeof group; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const _with: (query: RawQuery, ctx: BuilderContext) => (indexes?: string[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$2; split: typeof split; group: typeof group; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const where$2: (query: RawQuery, ctx: BuilderContext) => (conditions?: WhereCondition[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; split: typeof split; group: typeof group; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const split: (query: RawQuery, ctx: BuilderContext) => (field?: Field) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; group: typeof group; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const group: (query: RawQuery, ctx: BuilderContext) => (fields?: Field[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; order: typeof order; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const order: (query: RawQuery, ctx: BuilderContext) => (fields?: OrderFields) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; limit: typeof limit; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const limit: (query: RawQuery, ctx: BuilderContext) => (limit?: number) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; start: typeof start; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const start: (query: RawQuery, ctx: BuilderContext) => (start?: number) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; fetch: typeof fetch; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const fetch: (query: RawQuery, ctx: BuilderContext) => (fields?: Field[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; timeout: typeof timeout$2; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const timeout$2: (query: RawQuery, ctx: BuilderContext) => (timeout?: DurationLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; parallel: typeof parallel$2; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const parallel$2: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; tempfiles: typeof tempfiles; explain: typeof explain; }>; declare const tempfiles: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; explain: typeof explain; }>; declare const explain: (query: RawQuery, ctx: BuilderContext) => (options?: { full?: boolean; } | false) => Builder>; declare const update: (query: RawQuery, ctx: BuilderContext) => (targets: TargetLike | TargetLike[]) => Builder<{ content: typeof content$1; merge: typeof _merge$1; patch: typeof patch$1; set: typeof set$1; unset: typeof unset$1; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const updateOnly: (query: RawQuery, ctx: BuilderContext) => (target: TargetLike) => Builder<{ content: typeof content$1; merge: typeof _merge$1; patch: typeof patch$1; set: typeof set$1; unset: typeof unset$1; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const content$1: (query: RawQuery, ctx: BuilderContext) => (content?: ContentLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const _merge$1: (query: RawQuery, ctx: BuilderContext) => (merge?: MergeLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const patch$1: (query: RawQuery, ctx: BuilderContext) => (patch?: PatchLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const set$1: (query: RawQuery, ctx: BuilderContext) => (set?: SetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; unset: typeof unset$1; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const unset$1: (query: RawQuery, ctx: BuilderContext) => (unset?: UnsetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where$1; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const where$1: (query: RawQuery, ctx: BuilderContext) => (conditions?: WhereCondition[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; return: typeof _return$1; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const _return$1: (query: RawQuery, ctx: BuilderContext) => (type?: ReturnType) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; timeout: typeof timeout$1; parallel: typeof parallel$1; }>; declare const timeout$1: (query: RawQuery, ctx: BuilderContext) => (timeout?: DurationLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; parallel: typeof parallel$1; }>; declare const parallel$1: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder>; declare const upsert: (query: RawQuery, ctx: BuilderContext) => (targets: TargetLike | TargetLike[]) => Builder<{ content: typeof content; merge: typeof _merge; patch: typeof patch; set: typeof set; unset: typeof unset; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const upsertOnly: (query: RawQuery, ctx: BuilderContext) => (target: TargetLike) => Builder<{ content: typeof content; merge: typeof _merge; patch: typeof patch; set: typeof set; unset: typeof unset; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const content: (query: RawQuery, ctx: BuilderContext) => (content?: ContentLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const _merge: (query: RawQuery, ctx: BuilderContext) => (merge?: MergeLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const patch: (query: RawQuery, ctx: BuilderContext) => (patch?: PatchLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const set: (query: RawQuery, ctx: BuilderContext) => (set?: SetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; unset: typeof unset; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const unset: (query: RawQuery, ctx: BuilderContext) => (unset?: UnsetLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; where: typeof where; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const where: (query: RawQuery, ctx: BuilderContext) => (conditions?: WhereCondition[]) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; return: typeof _return; timeout: typeof timeout; parallel: typeof parallel; }>; declare const _return: (query: RawQuery, ctx: BuilderContext) => (type?: ReturnType) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; timeout: typeof timeout; parallel: typeof parallel; }>; declare const timeout: (query: RawQuery, ctx: BuilderContext) => (timeout?: DurationLike) => Builder<{ toQuery: (query: RawQuery, ctx: BuilderContext) => () => Query>; "~builder": (query: RawQuery, ctx: BuilderContext) => () => { query: RawQuery; ctx: BuilderContext; }; parallel: typeof parallel; }>; declare const parallel: (query: RawQuery, ctx: BuilderContext) => (append?: any) => Builder>; type DefaultBuilder = Builder<{ create: typeof create; createOnly: typeof createOnly; delete: typeof _delete; deleteOnly: typeof deleteOnly; select: typeof select; selectValue: typeof selectValue; update: typeof update; updateOnly: typeof updateOnly; upsert: typeof upsert; upsertOnly: typeof upsertOnly; }>; declare const q: DefaultBuilder; declare const createDefaultBuilder: (options?: { schema?: TSchema; connection?: Surrealize; }) => DefaultBuilder; declare const resolveQuery: (query: QueryLike) => Query; /** * Convert a tagged template query to a prepared query by replacing variables with bindings. * * Also encode the variables to their surrealdb.js representation if possible. * * @param query The tagged template to convert. * @returns The compiled query (including the query string and the bindings object). */ declare const prepareQuery: (template: TaggedTemplate) => PreparedQuery; /** * Convert a tagged template query list to a compiled query by replacing variables with bindings and wrapping it in a transaction. * * Also encode the variables to their surrealdb.js representation if possible. * * @param queries The tagged template queries to convert and wrap in a transaction. * @returns The compiled query (including the query string and the bindings object) as a transaction. */ declare const prepareTransaction: (queries: Query[]) => PreparedQuery; type RepositoryWhere = InferResult extends Record ? DeepPartial> | WhereCondition[] : Record | WhereCondition[]; type RepositoryFindByOptions = { limit?: number; start?: number; parallel?: boolean; tempfiles?: boolean; timeout?: DurationLike; }; type RepositoryFindOneByOptions = Omit; type RepositoryOptions = { connection?: Surrealize; schema?: TSchema; }; /** * An repository is an easy to use interface to communicate with the database. * * It provides a simple and easy to use interface to create, update, delete and query records. */ declare class Repository>> { #private; readonly table: Table>; readonly q: DefaultBuilder; readonly schema?: TSchema; readonly connection?: Surrealize; constructor(table: TableLike, options?: RepositoryOptions); find(options?: RepositoryFindByOptions): Query[]>; findBy(where?: RepositoryWhere, options?: RepositoryFindByOptions): Query[]>; findOneBy(where: RepositoryWhere, options?: RepositoryFindOneByOptions): Query | undefined>; findById(id: RecordIdLike>): Query | undefined>; create(record: OptionalId>): Query>; update(record: RequiredId>): Query>; updateBy(where: RepositoryWhere, set: SetLike): Query[]>; updateById(id: RecordIdLike>, set: SetLike): Query>; upsert(record: RequiredId>): Query>; upsertBy(where: RepositoryWhere, set: SetLike): Query[]>; delete(record: RequiredId>): Query | undefined>; deleteBy(where: RepositoryWhere): Query; deleteById(id: RecordIdLike>): Query; } declare const createSchemaContext: (schema: StandardSchema) => SchemaContext; /** * Indicates that the value should not be flattened and should be used as is. * * This is especially useful on update operations, * where you want to set a whole object instead of updating individual fields. * * @param value The value which should not be flattened. * @returns The wrapped value which indicates the flatting * functionality to keep the value as is. */ declare const keep: (value: T) => T; /** * Flatten an object making all nested values available at the top level * via dot notation. * * If you want to keep a nested value as is, use the `keep` function. * * For example: * ```ts * const source = { * test: 1, * nested: { * test: 2, * nested: { * test: 3 * } * } * } * * flatten(source) * // result: { * // test: 1, * // "nested.test": 2, * // "nested.nested.test": 3 * // } * ``` * * @param source The object to flatten. * @returns The flattened object. */ declare const flatten: (source: Record) => Record; export { AbstractEngine, type AnyRecord, type AnySchemaContext, type Auth, CborCodec, type CompareOperator, ConnectionError, type ConnectionState, ConnectionStatus, DatabaseError, Duration, type DurationLike, type DurationValue, type EmitterEvents, type EngineOptions, EventEmitter, type EventListener, type EventUnsubscriber, type FormatVariableConverter, HttpEngine, type HttpEngineOptions, type InferInput, type InferQueriesOutput, type InferQueryOutput, type InferResult, type InferStandardInput, type InferStandardOutput, type PreparedQuery, type QueriesLike, Query, QueryError, type QueryLike, QueryList, type QueryListOptions, type QueryOptions, type _Record as Record, RecordId, type RecordIdLike, type RecordIdValue, Repository, type RepositoryFindByOptions, type RepositoryFindOneByOptions, type RepositoryOptions, type RepositoryWhere, type ResolvedTarget, type RpcRequest, type RpcResponse, type RpcResponseError, type RpcResponseOk, type SchemaContext, type StandardSchema, Surrealize, type SurrealizeOptions, Table, type TableLike, type TaggedTemplate, type TargetLike, UUID, type UnknownSchemaContext, ValidationError, WebSocketEngine, type WebSocketEngineOptions, type WhereAnd, type WhereCompare, type WhereCondition, type WhereOr, type WhereState, type WithId, and, buildWhere, cmp, createDefaultBuilder, createSchemaContext, eq, eqs, flatten, format, gt, gte, isEmpty, keep, lt, lte, merge, mergeSchema, neq, or, parseSchema, prepareQuery, prepareTransaction, q, resolveQuery, resolveTarget, surql, tag, tagString };