import { UserIdentity, GenericDocument, GenericFieldPaths, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, TableDefinition, SystemFields as SystemFields$1, Expand, IndexTiebreakerField, SearchIndexConfig, VectorIndexConfig, SchemaDefinition, IdField, SystemIndexes, FilterBuilder, Expression, PaginationOptions, PaginationResult as PaginationResult$2, Indexes, IndexRangeBuilder, DocumentByInfo, NamedIndex, IndexRange, SearchIndexes, SearchFilterBuilder, NamedSearchIndex, SearchFilter, WithoutSystemFields, WithOptionalSystemFields, SchedulableFunctionReference, OptionalRestArgs, FunctionReference, FunctionReturnType, GenericActionCtx, VectorIndexNames, NamedTableInfo, VectorSearchQuery, GenericMutationCtx, GenericQueryCtx, DefaultFunctionArgs, RegisteredQuery, RegisteredMutation, RegisteredAction, HttpRouter as HttpRouter$1 } from 'convex/server'; import * as convex_values from 'convex/values'; import { GenericId, VAny, VId, VLiteral, VNull, VFloat64, VInt64, VBoolean, VString, VBytes, Validator, VArray, VOptional, OptionalProperty, VObject, VUnion } from 'convex/values'; import { Effect, Option, Brand, Schema, Cause, Stream, ParseResult, Context, Layer, SchemaAST } from 'effect'; import { ReadonlyRecord } from 'effect/Record'; import * as effect_Types from 'effect/Types'; import { HttpApi as HttpApi$1, HttpApp, HttpApiBuilder, HttpRouter, HttpApiScalar } from '@effect/platform'; interface ConfectAuth { getUserIdentity(): Effect.Effect>; } type IsOptional = {} extends Pick ? true : false; type IsAny = 0 extends 1 & T ? true : false; type IsUnion = T extends unknown ? [U] extends [T] ? false : true : never; // https://stackoverflow.com/a/52806744 type IsValueLiteral = [Vl] extends [never] ? never : [Vl] extends [string | number | bigint | boolean] ? [string] extends [Vl] ? false : [number] extends [Vl] ? false : [boolean] extends [Vl] ? false : [bigint] extends [Vl] ? false : true : false; type DeepMutable = IsAny extends true ? any : T extends Brand.Brand | GenericId ? T : T extends ReadonlyMap ? Map, DeepMutable> : T extends ReadonlySet ? Set> : [keyof T] extends [never] ? T : { -readonly [K in keyof T]: DeepMutable }; type TypeError = [Message, T]; type IsRecursive = true extends DetectCycle ? true : false; type DetectCycle = IsAny extends true ? false : [T] extends [any] ? T extends Cache[number] ? true : T extends Array ? DetectCycle : T extends Map ? DetectCycle : T extends Set ? DetectCycle : T extends object ? true extends { [K in keyof T]: DetectCycle; }[keyof T] ? true : false : false : never; ////////////////////////////////// // START: Vendored from Arktype // ////////////////////////////////// // https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9 type UnionToTuple = _unionToTuple extends infer result ? conform : never; type _unionToTuple< t, result extends unknown[], > = getLastBranch extends infer current ? [t] extends [never] ? result : _unionToTuple, [current, ...result]> : never; type getLastBranch = intersectUnion void : never> extends ( x: infer branch, ) => void ? branch : never; type intersectUnion = (t extends unknown ? (_: t) => void : never) extends ( _: infer intersection, ) => void ? intersection : never; type conform = t extends base ? t : base; /** * Convert a table `Schema` to a table `Validator`. */ type TableSchemaToTableValidator = ValueToValidator extends infer Vd extends VObject | VUnion ? Vd : never; type ReadonlyValue = string | number | bigint | boolean | ArrayBuffer | ReadonlyArrayValue | ReadonlyRecordValue | null; type ReadonlyArrayValue = readonly ReadonlyValue[]; type ReadonlyRecordValue = { readonly [key: string]: ReadonlyValue | undefined; }; type ValueToValidator = IsRecursive extends true ? VAny : [Vl] extends [never] ? never : IsAny extends true ? VAny : [Vl] extends [ReadonlyValue] ? Vl extends { __tableName: infer TableName extends string; } ? VId> : IsValueLiteral extends true ? VLiteral : Vl extends null ? VNull : Vl extends number ? VFloat64 : Vl extends bigint ? VInt64 : Vl extends boolean ? VBoolean : Vl extends string ? VString : Vl extends ArrayBuffer ? VBytes : Vl extends ReadonlyArray ? ArrayValueToValidator : Vl extends ReadonlyRecordValue ? RecordValueToValidator : IsUnion extends true ? UnionValueToValidator : TypeError<"Unexpected value", Vl> : TypeError<"Not a valid Convex value", Vl>; type ArrayValueToValidator> = Vl extends ReadonlyArray ? ValueToValidator extends infer Vd extends Validator ? VArray, Vd> : never : never; type RecordValueToValidator = Vl extends ReadonlyRecordValue ? { -readonly [K in keyof Vl]-?: IsAny extends true ? IsOptional extends true ? VOptional : VAny : UndefinedOrValueToValidator; } extends infer VdRecord extends Record ? { -readonly [K in keyof Vl]: DeepMutable; } extends infer VlRecord extends Record ? VObject : never : never : never; type UndefinedOrValueToValidator = undefined extends Vl ? Vl extends infer Val extends ReadonlyValue | undefined ? ValueToValidator extends infer Vd extends Validator ? VOptional : undefined : never : Vl extends ReadonlyValue ? ValueToValidator : never; type UnionValueToValidator = [Vl] extends [ ReadonlyValue ] ? IsUnion extends true ? UnionToTuple extends infer VlTuple extends ReadonlyArray ? ValueTupleToValidatorTuple extends infer VdTuple extends Validator[] ? VUnion, VdTuple> : TypeError<"Failed to convert value tuple to validator tuple"> : TypeError<"Failed to convert union to tuple"> : TypeError<"Expected a union of values, but got a single value instead"> : TypeError<"Provided value is not a valid Convex value">; type ValueTupleToValidatorTuple> = VlTuple extends [true, false, ...infer VlRest extends ReadonlyArray] | [false, true, ...infer VlRest extends ReadonlyArray] ? ValueTupleToValidatorTuple extends infer VdRest extends Validator[] ? [VBoolean, ...VdRest] : never : VlTuple extends [ infer Vl extends ReadonlyValue, ...infer VlRest extends ReadonlyArray ] ? ValueToValidator extends infer Vd extends Validator ? ValueTupleToValidatorTuple extends infer VdRest extends Validator[] ? [Vd, ...VdRest] : never : never : []; declare const compileSchema: (schema: Schema.Schema) => ValueToValidator<(typeof schema)["Encoded"]>; type GenericConfectDocument = ReadonlyRecord; type GenericEncodedConfectDocument = ReadonlyRecord; type ConfectDocumentByName> = ConfectDataModel[TableName]["confectDocument"]; type GenericConfectDataModel = Record; type DataModelFromConfectDataModel = { [TableName in keyof ConfectDataModel & string]: TableInfoFromConfectTableInfo; }; type TableNamesInConfectDataModel = keyof ConfectDataModel & string; type TableInfoFromConfectTableInfo = { document: ConfectTableInfo["convexDocument"]; fieldPaths: ConfectTableInfo["fieldPaths"]; indexes: ConfectTableInfo["indexes"]; searchIndexes: ConfectTableInfo["searchIndexes"]; vectorIndexes: ConfectTableInfo["vectorIndexes"]; }; type GenericConfectTableInfo = { confectDocument: GenericConfectDocument; encodedConfectDocument: GenericEncodedConfectDocument; convexDocument: GenericDocument; fieldPaths: GenericFieldPaths; indexes: GenericTableIndexes; searchIndexes: GenericTableSearchIndexes; vectorIndexes: GenericTableVectorIndexes; }; /** * The Confect document encoded for storage in Convex. This is the data as it is stored in the database. */ type ConfectDoc> = ConfectDataModel[TableName]["confectDocument"]; /** * Produces a schema for Convex system fields. */ declare const SystemFields: (tableName: TableName) => Schema.Struct<{ _id: Schema.Schema, convex_values.GenericId, never>; _creationTime: typeof Schema.Number; }>; /** * Extend a table schema with Convex system fields at the type level. */ type ExtendWithSystemFields = Schema.extend>>; /** * A Confect schema is a record of table definitions. */ type GenericConfectSchema = Record; /** * A Confect schema definition tracks the Confect schema, its Convex schema definition, and all of its table schemas. */ type GenericConfectSchemaDefinition = ConfectSchemaDefinition; interface ConfectSchemaDefinition { confectSchema: ConfectSchema; convexSchemaDefinition: SchemaDefinition, true>; tableSchemas: TableSchemasFromConfectSchema; } type SchemaDefinitionFromConfectSchemaDefinition = Expand<{ [TableName in keyof ConfectSchema & string]: ConfectSchema[TableName]["tableDefinition"]; }>; /** * Define a Confect schema. */ declare const defineSchema: (confectSchema: ConfectSchema) => ConfectSchemaDefinition; type GenericConfectTableDefinition = ConfectTableDefinition; interface ConfectTableDefinition = TableSchemaToTableValidator, Indexes extends GenericTableIndexes = {}, SearchIndexes extends GenericTableSearchIndexes = {}, VectorIndexes extends GenericTableVectorIndexes = {}> { tableDefinition: TableDefinition; tableSchema: TableSchema; index, RestFieldPaths extends ExtractFieldPaths[]>(name: IndexName, fields: [FirstFieldPath, ...RestFieldPaths]): ConfectTableDefinition>, SearchIndexes, VectorIndexes>; searchIndex, FilterFields extends ExtractFieldPaths = never>(name: IndexName, indexConfig: Expand>): ConfectTableDefinition>, VectorIndexes>; vectorIndex, FilterFields extends ExtractFieldPaths = never>(name: IndexName, indexConfig: Expand>): ConfectTableDefinition>>; } /** * @ignore */ type ConfectDataModelFromConfectSchemaDefinition = ConfectSchemaDef extends ConfectSchemaDefinition ? ConfectDataModelFromConfectSchema : never; /** * Define a Confect table. */ declare const defineTable: (tableSchema: TableSchema) => ConfectTableDefinition; /** * Produce a Confect data model from a Confect schema. */ type ConfectDataModelFromConfectSchema = { [TableName in keyof ConfectSchema & string]: ConfectSchema[TableName] extends ConfectTableDefinition ? TableSchema extends Schema.Schema ? { confectDocument: ExtractConfectDocument; encodedConfectDocument: ExtractEncodedConfectDocument; convexDocument: ExtractDocument; fieldPaths: keyof IdField | ExtractFieldPaths; indexes: Expand; searchIndexes: SearchIndexes; vectorIndexes: VectorIndexes; } : never : never; }; type ExtractConfectDocument> = Expand> & Readonly & S["Type"]>; type ExtractEncodedConfectDocument> = Expand> & Readonly & S["Encoded"]>; declare const confectSystemSchemaDefinition: ConfectSchemaDefinition<{ _scheduled_functions: ConfectTableDefinition; scheduledTime: typeof Schema.Number; completedTime: Schema.optional; state: Schema.Union<[Schema.Struct<{ kind: Schema.Literal<["pending"]>; }>, Schema.Struct<{ kind: Schema.Literal<["inProgress"]>; }>, Schema.Struct<{ kind: Schema.Literal<["success"]>; }>, Schema.Struct<{ kind: Schema.Literal<["failed"]>; error: typeof Schema.String; }>, Schema.Struct<{ kind: Schema.Literal<["canceled"]>; }>]>; }>, convex_values.VObject<{ name: string; args: any[]; scheduledTime: number; state: { kind: "pending"; } | { kind: "inProgress"; } | { kind: "success"; } | { kind: "failed"; error: string; } | { kind: "canceled"; }; completedTime?: number | undefined; }, { name: convex_values.VString; args: convex_values.VArray, "required">; scheduledTime: convex_values.VFloat64; state: convex_values.VObject<{ kind: "pending"; }, { kind: convex_values.VLiteral<"pending", "required">; }, "required", "kind"> | convex_values.VObject<{ kind: "inProgress"; }, { kind: convex_values.VLiteral<"inProgress", "required">; }, "required", "kind"> | convex_values.VObject<{ kind: "success"; }, { kind: convex_values.VLiteral<"success", "required">; }, "required", "kind"> | convex_values.VObject<{ kind: "failed"; error: string; }, { kind: convex_values.VLiteral<"failed", "required">; error: convex_values.VString; }, "required", "kind" | "error"> | convex_values.VObject<{ kind: "canceled"; }, { kind: convex_values.VLiteral<"canceled", "required">; }, "required", "kind">; completedTime: convex_values.VFloat64; }, "required", "name" | "args" | "scheduledTime" | "completedTime" | "state" | "state.kind" | "state.error">, {}, {}, {}>; _storage: ConfectTableDefinition; }>, convex_values.VObject<{ sha256: string; size: number; contentType?: string | undefined; }, { sha256: convex_values.VString; size: convex_values.VFloat64; contentType: convex_values.VString; }, "required", "sha256" | "size" | "contentType">, {}, {}, {}>; }>; type ConfectSystemSchema = typeof confectSystemSchemaDefinition; type ConfectSystemDataModel = ConfectDataModelFromConfectSchemaDefinition; type TableSchemasFromConfectSchema = Expand<{ [TableName in keyof ConfectSchema & string]: { withSystemFields: ExtendWithSystemFields; withoutSystemFields: ConfectSchema[TableName]["tableSchema"]; }; } & { [TableName in keyof ConfectSystemSchema["confectSchema"]]: { withSystemFields: ExtendWithSystemFields; withoutSystemFields: ConfectSystemSchema["confectSchema"][TableName]["tableSchema"]; }; }>; /** * Extract all of the index field paths within a {@link Validator}. * * This is used within {@link defineConvexTable}. * @public */ type ExtractFieldPaths> = T["fieldPaths"] | keyof SystemFields$1; /** * Extract the {@link GenericDocument} within a {@link Validator} and * add on the system fields. * * This is used within {@link defineConvexTable}. * @public */ type ExtractDocument> = Expand & SystemFields$1 & T["type"]>; interface ConfectQuery { filter(predicate: (q: FilterBuilder>) => Expression): ConfectQuery; order(order: "asc" | "desc"): ConfectOrderedQuery; paginate(paginationOpts: PaginationOptions): Effect.Effect>; collect(): Effect.Effect; take(n: number): Effect.Effect; first(): Effect.Effect>; unique(): Effect.Effect, NotUniqueError>; stream(): Stream.Stream; } interface ConfectOrderedQuery extends Omit, "order"> { } declare const NotUniqueError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & { readonly _tag: "NotUniqueError"; } & Readonly; declare class NotUniqueError extends NotUniqueError_base { } interface ConfectQueryInitializer extends ConfectQuery { fullTableScan(): ConfectQuery; withIndex>>(indexName: IndexName, indexRange?: ((q: IndexRangeBuilder>, NamedIndex, IndexName>, 0>) => IndexRange) | undefined): ConfectQuery; withSearchIndex>>(indexName: IndexName, searchFilter: (q: SearchFilterBuilder>, NamedSearchIndex, IndexName>>) => SearchFilter): ConfectOrderedQuery; } interface ConfectDatabaseReader extends ConfectBaseDatabaseReader { system: ConfectBaseDatabaseReader; } interface ConfectBaseDatabaseReader { query>(tableName: TableName): ConfectQueryInitializer; get>(id: GenericId): Effect.Effect>; normalizeId>(tableName: TableName, id: string): Option.Option>; } interface ConfectDatabaseWriter { query>(tableName: TableName): ConfectQueryInitializer; get>(id: GenericId): Effect.Effect>; normalizeId>(tableName: TableName, id: string): Option.Option>; insert>(table: TableName, value: WithoutSystemFields>): Effect.Effect, ParseResult.ParseError>; patch>(id: GenericId, value: Partial>>): Effect.Effect; replace>(id: GenericId, value: WithOptionalSystemFields>): Effect.Effect; delete(id: GenericId): Effect.Effect; } interface ConfectScheduler { runAfter(delayMs: number, functionReference: FuncRef, ...args: OptionalRestArgs): Effect.Effect; runAt(timestamp: number | Date, functionReference: FuncRef, ...args: OptionalRestArgs): Effect.Effect; } interface ConfectStorageReader { getUrl(storageId: GenericId<"_storage">): Effect.Effect>; } interface ConfectStorageWriter extends ConfectStorageReader { generateUploadUrl(): Effect.Effect; delete(storageId: GenericId<"_storage">): Effect.Effect; } type ConfectMutationCtx = { ctx: GenericMutationCtx>; db: ConfectDatabaseWriter; auth: ConfectAuth; storage: ConfectStorageWriter; scheduler: ConfectScheduler; }; declare const ConfectMutationCtx: () => Context.Tag, ConfectMutationCtx>; type ConfectQueryCtx = { ctx: GenericQueryCtx>; db: ConfectDatabaseReader; auth: ConfectAuth; storage: ConfectStorageReader; }; declare const ConfectQueryCtx: () => Context.Tag, ConfectQueryCtx>; type ConfectActionCtx = { runQuery>(query: Query, ...args: OptionalRestArgs): Effect.Effect>; runMutation>(mutation: Mutation, ...args: OptionalRestArgs): Effect.Effect>; runAction>(action: Action, ...args: OptionalRestArgs): Effect.Effect>; ctx: GenericActionCtx>; scheduler: ConfectScheduler; auth: ConfectAuth; storage: ConfectStorageWriter; vectorSearch, IndexName extends VectorIndexNames, TableName>>>(tableName: TableName, indexName: IndexName, query: Expand, TableName>, IndexName>>): Effect.Effect; _score: number; }>>; }; declare const ConfectActionCtx: () => Context.Tag, ConfectActionCtx>; declare const makeFunctions: (confectSchemaDefinition: ConfectSchemaDefinition) => { query: ({ args, returns, handler, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectArgs) => Effect.Effect>>; }) => RegisteredQuery<"public", ConvexArgs, Promise>; internalQuery: ({ args, handler, returns, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectArgs_1) => Effect.Effect>>; }) => RegisteredQuery<"internal", ConvexArgs, Promise>; mutation: ({ args, returns, handler, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectValue) => Effect.Effect> | ConfectMutationCtx>>; }) => RegisteredMutation<"public", ConvexValue, Promise>; internalMutation: ({ args, returns, handler, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectValue_1) => Effect.Effect> | ConfectMutationCtx>>; }) => RegisteredMutation<"internal", ConvexValue, Promise>; action: ({ args, returns, handler, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectValue_2) => Effect.Effect>>; }) => RegisteredAction<"public", ConvexValue, Promise>; internalAction: ({ args, returns, handler, }: { args: Schema.Schema; returns: Schema.Schema; handler: (a: ConfectValue_3) => Effect.Effect>>; }) => RegisteredAction<"internal", ConvexValue, Promise>; }; type Middleware = (httpApp: HttpApp.Default) => HttpApp.Default; type HttpApi = { apiLive: Layer.Layer>; middleware?: Middleware; scalar?: HttpApiScalar.ScalarConfig; }; type RoutePath = "/" | `/${string}/`; type HttpApis = Partial>; declare const makeHttpRouter: (httpApis: HttpApis) => HttpRouter$1; declare const Id: (tableName: TableName) => Schema.Schema>; declare const tableName: (ast: SchemaAST.AST) => Option.Option; declare const Id$1_Id: typeof Id; declare const Id$1_tableName: typeof tableName; declare namespace Id$1 { export { Id$1_Id as Id, Id$1_tableName as tableName }; } declare const PaginationResult: (Doc: Doc) => Schema.mutable>; isDone: typeof Schema.Boolean; continueCursor: typeof Schema.String; splitCursor: Schema.optional>; pageStatus: Schema.optional, Schema.Literal<["SplitRequired"]>, typeof Schema.Null]>>; }>>; declare const PaginationResult$1_PaginationResult: typeof PaginationResult; declare namespace PaginationResult$1 { export { PaginationResult$1_PaginationResult as PaginationResult }; } export { ConfectActionCtx, type ConfectDataModelFromConfectSchemaDefinition, type ConfectDoc, ConfectMutationCtx, ConfectQueryCtx, type HttpApi, Id$1 as Id, NotUniqueError, PaginationResult$1 as PaginationResult, type TableNamesInConfectDataModel, compileSchema, defineSchema, defineTable, makeFunctions, makeHttpRouter };