{"version":3,"sources":["../../src/database/types.ts"],"sourcesContent":["import type { TypeWithID } from '../collections/config/types.js'\nimport type { CollectionSlug, GlobalSlug, Job } from '../index.js'\nimport type {\n Document,\n JoinQuery,\n JsonObject,\n Payload,\n PayloadRequest,\n SelectType,\n Sort,\n Where,\n} from '../types/index.js'\nimport type { TypeWithVersion } from '../versions/types.js'\n\nexport type { TypeWithVersion }\n\nexport interface BaseDatabaseAdapter {\n allowIDOnCreate?: boolean\n /**\n * Start a transaction, requiring commitTransaction() to be called for any changes to be made.\n * @returns an identifier for the transaction or null if one cannot be established\n */\n beginTransaction: BeginTransaction\n /**\n * When true, bulk operations will process documents one at a time\n * in separate transactions instead of all at once in a single transaction.\n * Useful for avoiding transaction limitations with large datasets.\n *\n * @default false\n */\n bulkOperationsSingleTransaction?: boolean\n\n /**\n * Persist the changes made since the start of the transaction.\n */\n commitTransaction: CommitTransaction\n\n /**\n * Open the connection to the database\n */\n connect?: Connect\n count: Count\n countGlobalVersions: CountGlobalVersions\n countVersions: CountVersions\n\n create: Create\n\n createGlobal: CreateGlobal\n\n createGlobalVersion: CreateGlobalVersion\n /**\n * Output a migration file\n */\n createMigration: CreateMigration\n\n createVersion: CreateVersion\n\n /**\n * Specify if the ID is a text or number field by default within this database adapter.\n */\n defaultIDType: 'number' | 'text'\n\n deleteMany: DeleteMany\n\n deleteOne: DeleteOne\n deleteVersions: DeleteVersions\n\n /**\n * Terminate the connection with the database\n */\n destroy?: Destroy\n\n find: Find\n\n findDistinct: FindDistinct\n\n findGlobal: FindGlobal\n\n findGlobalVersions: FindGlobalVersions\n\n findOne: FindOne\n\n findVersions: FindVersions\n\n generateSchema?: GenerateSchema\n\n /**\n * Perform startup tasks required to interact with the database such as building Schema and models\n */\n init?: Init\n\n /**\n * Run any migration up functions that have not yet been performed and update the status\n */\n migrate: (args?: { migrations?: Migration[] }) => Promise\n /**\n * Run any migration down functions that have been performed\n */\n migrateDown: () => Promise\n\n /**\n * Drop the current database and run all migrate up functions\n */\n migrateFresh: (args: { forceAcceptWarning?: boolean }) => Promise\n /**\n * Run all migration down functions before running up\n */\n migrateRefresh: () => Promise\n /**\n * Run all migrate down functions\n */\n migrateReset: () => Promise\n /**\n * Read the current state of migrations and output the result to show which have been run\n */\n migrateStatus: () => Promise\n\n /**\n * Path to read and write migration files from\n */\n migrationDir: string\n\n /**\n * The name of the database adapter\n */\n name: string\n /**\n * Full package name of the database adapter\n *\n * @example @payloadcms/db-postgres\n */\n packageName: string\n /**\n * reference to the instance of payload\n */\n payload: Payload\n\n queryDrafts: QueryDrafts\n\n /**\n * Abort any changes since the start of the transaction.\n */\n rollbackTransaction: RollbackTransaction\n\n /**\n * A key-value store of all sessions open (used for transactions)\n */\n sessions?: {\n [id: string]: {\n db: unknown\n reject: () => Promise\n resolve: () => Promise\n }\n }\n\n /**\n * Updates a global that exists. If the global doesn't exist yet, this will not work - you should use `createGlobal` instead.\n */\n updateGlobal: UpdateGlobal\n\n updateGlobalVersion: UpdateGlobalVersion\n\n updateJobs: UpdateJobs\n\n updateMany: UpdateMany\n\n updateOne: UpdateOne\n updateVersion: UpdateVersion\n upsert: Upsert\n}\n\nexport type Init = () => Promise | void\n\ntype ConnectArgs = {\n hotReload: boolean\n}\n\nexport type Connect = (args?: ConnectArgs) => Promise\n\nexport type Destroy = () => Promise\n\nexport type CreateMigration = (args: {\n file?: string\n forceAcceptWarning?: boolean\n migrationName?: string\n payload: Payload\n /**\n * Skips the prompt asking to create empty migrations\n */\n skipEmpty?: boolean\n}) => Promise | void\n\nexport type Transaction = (\n callback: () => Promise,\n options?: Record,\n) => Promise\n\nexport type BeginTransaction = (\n options?: Record,\n) => Promise\n\nexport type RollbackTransaction = (id: number | Promise | string) => Promise\n\nexport type CommitTransaction = (id: number | Promise | string) => Promise\n\nexport type QueryDraftsArgs = {\n collection: CollectionSlug\n joins?: JoinQuery\n limit?: number\n locale?: string\n page?: number\n pagination?: boolean\n req?: Partial\n select?: SelectType\n sort?: Sort\n where?: Where\n}\n\nexport type QueryDrafts = (args: QueryDraftsArgs) => Promise>\n\nexport type FindOneArgs = {\n collection: CollectionSlug\n draftsEnabled?: boolean\n joins?: JoinQuery\n locale?: string\n req?: Partial\n select?: SelectType\n where?: Where\n}\n\nexport type FindOne = (args: FindOneArgs) => Promise\n\nexport type FindArgs = {\n collection: CollectionSlug\n draftsEnabled?: boolean\n joins?: JoinQuery\n /** Setting limit to 1 is equal to the previous Model.findOne(). Setting limit to 0 disables the limit */\n limit?: number\n locale?: string\n page?: number\n pagination?: boolean\n projection?: Record\n req?: Partial\n select?: SelectType\n /**\n * @deprecated This parameter is going to be removed in the next major version. Use page instead.\n */\n skip?: number\n sort?: Sort\n versions?: boolean\n where?: Where\n}\n\nexport type Find = (args: FindArgs) => Promise>\n\nexport type CountArgs = {\n collection: CollectionSlug\n locale?: string\n req?: Partial\n where?: Where\n}\n\nexport type Count = (args: CountArgs) => Promise<{ totalDocs: number }>\n\nexport type CountVersions = (args: CountArgs) => Promise<{ totalDocs: number }>\n\nexport type CountGlobalVersionArgs = {\n global: string\n locale?: string\n req?: Partial\n where?: Where\n}\n\nexport type CountGlobalVersions = (args: CountGlobalVersionArgs) => Promise<{ totalDocs: number }>\n\ntype BaseVersionArgs = {\n limit?: number\n locale?: string\n page?: number\n pagination?: boolean\n req?: Partial\n select?: SelectType\n /**\n * @deprecated This parameter is going to be removed in the next major version. Use page instead.\n */\n skip?: number\n sort?: Sort\n versions?: boolean\n where?: Where\n}\n\nexport type FindVersionsArgs = {\n collection: CollectionSlug\n} & BaseVersionArgs\n\nexport type FindVersions = (\n args: FindVersionsArgs,\n) => Promise>>\n\nexport type FindGlobalVersionsArgs = {\n global: GlobalSlug\n} & BaseVersionArgs\n\nexport type FindGlobalArgs = {\n locale?: string\n req?: Partial\n select?: SelectType\n slug: string\n where?: Where\n}\n\nexport type UpdateGlobalVersionArgs = {\n global: GlobalSlug\n locale?: string\n /**\n * Additional database adapter specific options to pass to the query\n */\n options?: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n versionData: {\n createdAt?: string\n latest?: boolean\n parent?: number | string\n publishedLocale?: string\n updatedAt?: string\n version: T\n }\n} & (\n | {\n id: number | string\n where?: never\n }\n | {\n id?: never\n where: Where\n }\n)\n\n/**\n * @todo type as Promise | null> in 4.0\n */\nexport type UpdateGlobalVersion = (\n args: UpdateGlobalVersionArgs,\n) => Promise>\n\nexport type FindGlobal = = any>(\n args: FindGlobalArgs,\n) => Promise\n\nexport type CreateGlobalArgs = any> = {\n data: T\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n slug: string\n}\nexport type CreateGlobal = = any>(\n args: CreateGlobalArgs,\n) => Promise\n\nexport type UpdateGlobalArgs = any> = {\n data: T\n /**\n * Additional database adapter specific options to pass to the query\n */\n options?: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n slug: string\n}\n/**\n * @todo type as Promise in 4.0\n */\nexport type UpdateGlobal = = any>(\n args: UpdateGlobalArgs,\n) => Promise\n// export type UpdateOne = (args: UpdateOneArgs) => Promise\n\nexport type FindGlobalVersions = (\n args: FindGlobalVersionsArgs,\n) => Promise>>\n\nexport type DeleteVersionsArgs = {\n collection?: CollectionSlug\n globalSlug?: GlobalSlug\n locale?: string\n req?: Partial\n sort?: {\n [key: string]: string\n }\n where: Where\n}\n\nexport type CreateVersionArgs = {\n autosave: boolean\n collectionSlug: CollectionSlug\n createdAt: string\n /** ID of the parent document for which the version should be created for */\n parent: number | string\n publishedLocale?: string\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n /**\n * If provided, the snapshot will be created\n * after a version is created (not during autosave)\n */\n snapshot?: true\n updatedAt: string\n versionData: T\n}\n\nexport type CreateVersion = (\n args: CreateVersionArgs,\n) => Promise>\n\nexport type CreateGlobalVersionArgs = {\n autosave: boolean\n createdAt: string\n globalSlug: GlobalSlug\n publishedLocale?: string\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n /**\n * If provided, the snapshot will be created\n * after a version is created (not during autosave)\n */\n snapshot?: true\n updatedAt: string\n versionData: T\n}\n\nexport type CreateGlobalVersion = (\n args: CreateGlobalVersionArgs,\n) => Promise, 'parent'>>\n\nexport type DeleteVersions = (args: DeleteVersionsArgs) => Promise\n\nexport type UpdateVersionArgs = {\n collection: CollectionSlug\n locale?: string\n /**\n * Additional database adapter specific options to pass to the query\n */\n options?: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n versionData: {\n createdAt?: string\n latest?: boolean\n parent?: number | string\n publishedLocale?: string\n updatedAt?: string\n version: T\n }\n} & (\n | {\n id: number | string\n where?: never\n }\n | {\n id?: never\n where: Where\n }\n)\n\n/**\n * @todo type as Promise | null> in 4.0\n */\nexport type UpdateVersion = (\n args: UpdateVersionArgs,\n) => Promise>\n\nexport type CreateArgs = {\n collection: CollectionSlug\n customID?: number | string\n data: Record\n draft?: boolean\n locale?: string\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n}\n\nexport type FindDistinctArgs = {\n collection: CollectionSlug\n field: string\n limit?: number\n locale?: string\n page?: number\n req?: Partial\n sort?: Sort\n where?: Where\n}\n\nexport type PaginatedDistinctDocs> = {\n hasNextPage: boolean\n hasPrevPage: boolean\n limit: number\n nextPage?: null | number | undefined\n page: number\n pagingCounter: number\n prevPage?: null | number | undefined\n totalDocs: number\n totalPages: number\n values: T[]\n}\n\nexport type FindDistinct = (\n args: FindDistinctArgs,\n) => Promise>>\n\nexport type Create = (args: CreateArgs) => Promise\n\nexport type UpdateOneArgs = {\n collection: CollectionSlug\n data: Record\n draft?: boolean\n joins?: JoinQuery\n locale?: string\n /**\n * Additional database adapter specific options to pass to the query\n */\n options?: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n} & (\n | {\n id: number | string\n where?: never\n }\n | {\n id?: never\n where: Where\n }\n)\n\n/**\n * @todo type as Promise in 4.0\n */\nexport type UpdateOne = (args: UpdateOneArgs) => Promise\n\nexport type UpdateManyArgs = {\n collection: CollectionSlug\n data: Record\n draft?: boolean\n joins?: JoinQuery\n limit?: number\n locale?: string\n /**\n * Additional database adapter specific options to pass to the query\n */\n options?: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n sort?: Sort\n where: Where\n}\n\nexport type UpdateMany = (args: UpdateManyArgs) => Promise\n\nexport type UpdateJobsArgs = {\n data: Record\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n} & (\n | {\n id: number | string\n limit?: never\n sort?: never\n where?: never\n }\n | {\n id?: never\n limit?: number\n sort?: Sort\n where: Where\n }\n)\n\nexport type UpdateJobs = (args: UpdateJobsArgs) => Promise\n\nexport type UpsertArgs = {\n collection: CollectionSlug\n data: Record\n joins?: JoinQuery\n locale?: string\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n where: Where\n}\n\nexport type Upsert = (args: UpsertArgs) => Promise\n\nexport type DeleteOneArgs = {\n collection: CollectionSlug\n joins?: JoinQuery\n req?: Partial\n /**\n * If true, returns the updated documents\n *\n * @default true\n */\n returning?: boolean\n select?: SelectType\n where: Where\n}\n\n/**\n * @todo type as Promise in 4.0\n */\nexport type DeleteOne = (args: DeleteOneArgs) => Promise\n\nexport type DeleteManyArgs = {\n collection: CollectionSlug\n joins?: JoinQuery\n req?: Partial\n where: Where\n}\n\nexport type DeleteMany = (args: DeleteManyArgs) => Promise\n\nexport type Migration = {\n down: (args: unknown) => Promise\n up: (args: unknown) => Promise\n} & MigrationData\n\nexport type MigrationData = {\n batch?: number\n id?: string\n name: string\n}\n\nexport type PaginatedDocs = {\n docs: T[]\n hasNextPage: boolean\n hasPrevPage: boolean\n limit: number\n nextPage?: null | number | undefined\n page?: number\n pagingCounter: number\n prevPage?: null | number | undefined\n totalDocs: number\n totalPages: number\n}\n\nexport type DatabaseAdapterResult = {\n allowIDOnCreate?: boolean\n defaultIDType: 'number' | 'text'\n init: (args: { payload: Payload }) => T\n /**\n * The name of the database adapter. For example, \"postgres\" or \"mongoose\".\n *\n * @todo make required in 4.0\n */\n name?: string\n}\n\nexport type DBIdentifierName =\n | ((Args: {\n /** The name of the parent table when using relational DBs */\n tableName?: string\n }) => string)\n | string\n\nexport type DynamicMigrationTemplate = (args: { filePath: string; payload: Payload }) => Promise<{\n downSQL?: string\n imports?: string\n upSQL?: string\n}>\n\nexport type MigrationTemplateArgs = {\n downSQL?: string\n dynamic?: DynamicMigrationTemplate\n imports?: string\n packageName?: string\n upSQL?: string\n}\n\nexport type GenerateSchemaArgs = {\n log?: boolean\n outputFile?: string\n prettify?: boolean\n}\n\nexport type GenerateSchema = (args?: GenerateSchemaArgs) => Promise\n"],"names":[],"mappings":"AA2uBA,WAAyE"}