{"version":3,"sources":["../../src/sqlite/types.ts"],"sourcesContent":["import type { Client, ResultSet } from '@libsql/client'\nimport type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm'\nimport type { DrizzleD1Database } from 'drizzle-orm/d1'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type {\n AnySQLiteColumn,\n SQLiteColumn,\n SQLiteInsertOnConflictDoUpdateConfig,\n SQLiteTableWithColumns,\n SQLiteTransactionConfig,\n} from 'drizzle-orm/sqlite-core'\nimport type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport type { Operators } from '../queries/operatorMap.js'\nimport type { BuildQueryJoinAliases, DrizzleAdapter } from '../types.js'\nimport type { extendDrizzleTable } from '../utilities/extendDrizzleTable.js'\n\ntype SQLiteSchema = {\n relations: Record\n tables: Record>\n}\n\ntype SQLiteSchemaHookArgs = {\n extendTable: typeof extendDrizzleTable\n schema: SQLiteSchema\n}\n\nexport type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise | SQLiteSchema\n\nexport type BaseSQLiteArgs = {\n /**\n * Transform the schema after it's built.\n * You can use it to customize the schema with features that aren't supported by Payload.\n * Examples may include: composite indices, generated columns, vectors\n */\n afterSchemaInit?: SQLiteSchemaHook[]\n /**\n * Enable this flag if you want to thread your own ID to create operation data, for example:\n * ```ts\n * // doc created with id 1\n * const doc = await payload.create({ collection: 'posts', data: {id: 1, title: \"my title\"}})\n * ```\n */\n allowIDOnCreate?: boolean\n /**\n * Enable [AUTOINCREMENT](https://www.sqlite.org/autoinc.html) for Primary Keys.\n * This ensures that the same ID cannot be reused from previously deleted rows.\n */\n autoIncrement?: boolean\n /**\n * Transform the schema before it's built.\n * You can use it to preserve an existing database schema and if there are any collissions Payload will override them.\n * To generate Drizzle schema from the database, see [Drizzle Kit introspection](https://orm.drizzle.team/kit-docs/commands#introspect--pull)\n */\n beforeSchemaInit?: SQLiteSchemaHook[]\n /**\n * Store blocks as JSON column instead of storing them in a relational structure.\n */\n blocksAsJSON?: boolean\n /** Generated schema from payload generate:db-schema file path */\n generateSchemaOutputFile?: string\n idType?: 'number' | 'uuid'\n localesSuffix?: string\n logger?: DrizzleConfig['logger']\n migrationDir?: string\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise\n name: string\n up: (args: MigrateUpArgs) => Promise\n }[]\n push?: boolean\n relationshipsSuffix?: string\n schemaName?: string\n transactionOptions?: false | SQLiteTransactionConfig\n versionsSuffix?: string\n}\n\nexport type GenericColumns = {\n [x: string]: AnySQLiteColumn\n}\n\nexport type GenericTable = SQLiteTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericRelation = Relations>>\n\nexport type CountDistinct = (args: {\n column?: SQLiteColumn\n db: LibSQLDatabase\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise\n\nexport type DeleteWhere = (args: {\n db: LibSQLDatabase\n tableName: string\n where: SQL\n}) => Promise\n\nexport type DropDatabase = (args: { adapter: BaseSQLiteAdapter }) => Promise\n\nexport type Execute = (args: {\n db?: DrizzleD1Database | LibSQLDatabase\n drizzle?: DrizzleD1Database | LibSQLDatabase\n raw?: string\n sql?: SQL\n}) => SQLiteRaw> | SQLiteRaw\n\nexport type Insert = (args: {\n db: LibSQLDatabase\n onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig\n tableName: string\n values: Record | Record[]\n}) => Promise[]>\n\n// Explicitly omit drizzle property for complete override in SQLiteAdapter, required in ts 5.5\ntype SQLiteDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'idType'\n | 'insert'\n | 'operators'\n | 'relations'\n>\n\nexport interface GeneratedDatabaseSchema {\n schemaUntyped: Record\n}\n\ntype ResolveSchemaType = 'schema' extends keyof T\n ? T['schema']\n : GeneratedDatabaseSchema['schemaUntyped']\n\ntype Drizzle = { $client: Client } & LibSQLDatabase>\n\nexport type BaseSQLiteAdapter = {\n afterSchemaInit: SQLiteSchemaHook[]\n autoIncrement: boolean\n beforeSchemaInit: SQLiteSchemaHook[]\n client: Client\n countDistinct: CountDistinct\n defaultDrizzleSnapshot: any\n deleteWhere: DeleteWhere\n dropDatabase: DropDatabase\n execute: Execute\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record>\n idType: BaseSQLiteArgs['idType']\n initializing: Promise\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operators: Operators\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise\n name: string\n up: (args: MigrateUpArgs) => Promise\n }[]\n push: boolean\n rejectInitializing: () => void\n relations: Record\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record\n schemaName?: BaseSQLiteArgs['schemaName']\n tableNameMap: Map\n tables: Record\n transactionOptions: SQLiteTransactionConfig\n versionsSuffix?: string\n} & SQLiteDrizzleAdapter\n\nexport type IDType = 'integer' | 'numeric' | 'text'\n\nexport type MigrateUpArgs = {\n /**\n * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-sqlite'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise {\n * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: Drizzle\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-sqlite'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\nexport type MigrateDownArgs = {\n /**\n * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs, sql } from '@payloadcms/db-sqlite'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise {\n * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: Drizzle\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-sqlite'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n"],"names":[],"mappings":"AAyNA,WA8BC"}