@payloadcms/drizzle 4.0.0-internal.ea6e8f8 → 4.0.0-internal.ee5d8bd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +3 -25
- package/dist/count.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +4 -28
- package/dist/countVersions.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +2 -15
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +1 -12
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -18
- package/dist/deleteOne.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts +2 -3
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +1 -2
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.d.ts +4 -4
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.js +26 -32
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -1
- package/dist/find/buildPolymorphicJoinWhere.js +1 -1
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -1
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +2 -1
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -1
- package/dist/find/createPolymorphicJoinWherePlan.js +14 -5
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -1
- package/dist/find/findMany.d.ts +1 -6
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +3 -16
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +2 -3
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +8 -54
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +4 -32
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +8 -107
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +5 -22
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +3 -8
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +3 -30
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +5 -32
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +1 -1
- package/dist/postgres/insert.d.ts.map +1 -1
- package/dist/postgres/insert.js +2 -4
- package/dist/postgres/insert.js.map +1 -1
- package/dist/postgres/types.d.ts +0 -4
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -3
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +2 -3
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +1 -2
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -3
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -4
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +2 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +27 -166
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -4
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +4 -23
- package/dist/queryDrafts.js.map +1 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +20 -23
- package/dist/schema/build.js.map +1 -1
- package/dist/sqlite/execute.js.map +1 -1
- package/dist/sqlite/insert.d.ts.map +1 -1
- package/dist/sqlite/insert.js +3 -5
- package/dist/sqlite/insert.js.map +1 -1
- package/dist/sqlite/types.d.ts +0 -4
- package/dist/sqlite/types.d.ts.map +1 -1
- package/dist/sqlite/types.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +5 -13
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +5 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +2 -3
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +1 -2
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +2 -3
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +1 -2
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js +0 -2
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +1 -2
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +6 -32
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/transform/write/types.d.ts +0 -7
- package/dist/transform/write/types.d.ts.map +1 -1
- package/dist/transform/write/types.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -5
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +4 -96
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +5 -47
- package/dist/updateOne.js.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +12 -17
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +42 -132
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/types.d.ts +0 -3
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.js +6 -17
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -1
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +7 -12
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.js +1 -1
- package/dist/utilities/executeSchemaHooks.js.map +1 -1
- package/dist/utilities/formatGeneratedFile.d.ts +10 -0
- package/dist/utilities/formatGeneratedFile.d.ts.map +1 -0
- package/dist/utilities/formatGeneratedFile.js +58 -0
- package/dist/utilities/formatGeneratedFile.js.map +1 -0
- package/dist/utilities/getTransaction.js.map +1 -1
- package/package.json +16 -19
- package/dist/deleteBranchGlobal.d.ts +0 -10
- package/dist/deleteBranchGlobal.d.ts.map +0 -1
- package/dist/deleteBranchGlobal.js +0 -27
- package/dist/deleteBranchGlobal.js.map +0 -1
- package/dist/queries/buildBranchVisibility.d.ts +0 -11
- package/dist/queries/buildBranchVisibility.d.ts.map +0 -1
- package/dist/queries/buildBranchVisibility.js +0 -48
- package/dist/queries/buildBranchVisibility.js.map +0 -1
- package/dist/upsertBranchGlobalChange.d.ts +0 -3
- package/dist/upsertBranchGlobalChange.d.ts.map +0 -1
- package/dist/upsertBranchGlobalChange.js +0 -35
- package/dist/upsertBranchGlobalChange.js.map +0 -1
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Column,\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n SQL,\n TableRelationalConfig,\n} from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type {\n PgColumn,\n PgTable,\n PgTransaction,\n Precision,\n UpdateDeleteAction,\n} from 'drizzle-orm/pg-core'\nimport type { SQLiteColumn, SQLiteTable, SQLiteTransaction } from 'drizzle-orm/sqlite-core'\nimport type { Result } from 'drizzle-orm/sqlite-core/session'\nimport type {\n BaseDatabaseAdapter,\n FlattenedField,\n MigrationData,\n Operator,\n Payload,\n PayloadRequest,\n} from 'payload'\n\nimport type { BuildQueryJoinAliases } from './queries/buildQuery.js'\n\nexport { BuildQueryJoinAliases }\n\nimport type { ResultSet } from '@libsql/client'\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'\nimport type { QueryResult } from 'pg'\n\nimport type { DrizzleResolvedOperator, Operators } from './queries/operatorMap.js'\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type SQLiteDB = LibSQLDatabase<\n Record<string, GenericRelation | GenericTable> & Record<string, unknown>\n>\n\nexport type GenericPgColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns<T> = {\n [x: string]: T\n}\n\ntype GenericPgTable = PgTable<{\n columns: GenericColumns<GenericPgColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\ntype GenericSQLiteTable = SQLiteTable<{\n columns: GenericColumns<SQLiteColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\nexport type GenericColumn = GenericPgColumn | SQLiteColumn\n\nexport type GenericTable = GenericPgTable | GenericSQLiteTable\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type TransactionSQLite = SQLiteTransaction<\n 'async',\n Result<'async', unknown>,\n Record<string, unknown>,\n { tsName: TableRelationalConfig }\n>\nexport type TransactionPg = PgTransaction<\n NodePgQueryResultHKT,\n Record<string, unknown>,\n ExtractTablesWithRelations<Record<string, unknown>>\n>\n\nexport type DrizzleTransaction = TransactionPg | TransactionSQLite\n\nexport type CountDistinct = (args: {\n column?: PgColumn<any> | SQLiteColumn<any>\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: DrizzleAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n drizzle?: LibSQLDatabase | PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) =>\n | Promise<QueryResult<Record<string, T>>>\n | SQLiteRaw<Promise<{ rows: T[] }>>\n | SQLiteRaw<ResultSet>\n\nexport type Insert = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n onConflictDoNothing?: unknown\n onConflictDoUpdate?: unknown\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type RequireDrizzleKit = () => {\n generateDrizzleJson: (\n args: Record<string, unknown>,\n ) => DrizzleSnapshotJSON | Promise<DrizzleSnapshotJSON>\n generateMigration: (prev: DrizzleSnapshotJSON, cur: DrizzleSnapshotJSON) => Promise<string[]>\n pushSchema: (\n schema: Record<string, unknown>,\n drizzle: DrizzleAdapter['drizzle'],\n filterSchema?: string[],\n tablesFilter?: string[],\n extensionsFilter?: string[],\n ) => Promise<{ apply; hasDataLoss; warnings }>\n upSnapshot?: (snapshot: Record<string, unknown>) => DrizzleSnapshotJSON\n}\n\nexport type Migration = {\n down: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase<Record<string, never>> | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n up: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n} & MigrationData\n\nexport type CreateJSONQueryArgs = {\n column?: Column | string\n operator: string\n pathSegments: string[]\n rawColumn?: SQL<unknown>\n table?: string\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: boolean | number | number[] | string | string[]\n}\n\n/**\n * Abstract relation link\n */\nexport type RawRelation =\n | {\n fields: { name: string; table: string }[]\n references: string[]\n relationName?: string\n to: string\n type: 'one'\n }\n | {\n relationName?: string\n to: string\n type: 'many'\n }\n\n/**\n * Abstract SQL table that later gets converted by database specific implementation to Drizzle\n */\nexport type RawTable = {\n columns: Record<string, RawColumn>\n foreignKeys?: Record<string, RawForeignKey>\n indexes?: Record<string, RawIndex>\n name: string\n}\n\n/**\n * Abstract SQL foreign key that later gets converted by database specific implementation to Drizzle\n */\nexport type RawForeignKey = {\n columns: string[]\n foreignColumns: { name: string; table: string }[]\n name: string\n onDelete?: UpdateDeleteAction\n onUpdate?: UpdateDeleteAction\n}\n\n/**\n * Abstract SQL index that later gets converted by database specific implementation to Drizzle\n */\nexport type RawIndex = {\n name: string\n on: string | string[]\n unique?: boolean\n}\n\n/**\n * Abstract SQL column that later gets converted by database specific implementation to Drizzle\n */\nexport type BaseRawColumn = {\n default?: any\n name: string\n notNull?: boolean\n primaryKey?: boolean\n reference?: {\n name: string\n onDelete: UpdateDeleteAction\n table: string\n }\n}\n\n/**\n * Postgres: native timestamp type\n * SQLite: text column, defaultNow achieved through strftime('%Y-%m-%dT%H:%M:%fZ', 'now'). withTimezone/precision have no any effect.\n */\nexport type TimestampRawColumn = {\n defaultNow?: boolean\n mode: 'date' | 'string'\n precision: Precision\n type: 'timestamp'\n withTimezone?: boolean\n} & BaseRawColumn\n\n/**\n * Postgres: native UUID type and db lavel defaultRandom\n * SQLite: text type and defaultRandom in the app level\n */\nexport type UUIDRawColumn = {\n defaultRandom?: boolean\n /** App-side UUID v7 default (Postgres & SQLite); mutually exclusive with defaultRandom in practice */\n defaultV7?: boolean\n type: 'uuid'\n} & BaseRawColumn\n\n/**\n * Accepts either `locale: true` to have options from locales or `options` string array\n * Postgres: native enums\n * SQLite: text column with checks.\n */\nexport type EnumRawColumn = (\n | {\n enumName: string\n options: string[]\n type: 'enum'\n }\n | {\n locale: true\n type: 'enum'\n }\n) &\n BaseRawColumn\n\nexport type IntegerRawColumn = {\n /**\n * SQLite only.\n * Enable [AUTOINCREMENT](https://www.sqlite.org/autoinc.html) for primary key to ensure that the same ID cannot be reused from previously deleted rows.\n */\n autoIncrement?: boolean\n type: 'integer'\n} & BaseRawColumn\n\nexport type VectorRawColumn = {\n dimensions?: number\n type: 'vector'\n} & BaseRawColumn\n\nexport type HalfVecRawColumn = {\n dimensions?: number\n type: 'halfvec'\n} & BaseRawColumn\n\nexport type SparseVecRawColumn = {\n dimensions?: number\n type: 'sparsevec'\n} & BaseRawColumn\n\nexport type BinaryVecRawColumn = {\n dimensions?: number\n type: 'bit'\n} & BaseRawColumn\n\nexport type RawColumn =\n | ({\n type: 'boolean' | 'geometry' | 'jsonb' | 'numeric' | 'serial' | 'text' | 'varchar'\n } & BaseRawColumn)\n | BinaryVecRawColumn\n | EnumRawColumn\n | HalfVecRawColumn\n | IntegerRawColumn\n | SparseVecRawColumn\n | TimestampRawColumn\n | UUIDRawColumn\n | VectorRawColumn\n\nexport type IDType = 'integer' | 'numeric' | 'text' | 'uuid' | 'varchar'\n\nexport type SetColumnID = (args: {\n adapter: DrizzleAdapter\n columns: Record<string, RawColumn>\n fields: FlattenedField[]\n}) => IDType\n\nexport type ColumnToCodeConverter = (args: {\n adapter: DrizzleAdapter\n addEnum: (name: string, options: string[]) => void\n addImport: (from: string, name: string) => void\n circularEdges?: Set<string>\n column: RawColumn\n locales?: string[]\n tableKey: string\n}) => string\n\nexport type BuildDrizzleTable<T extends DrizzleAdapter = DrizzleAdapter> = (args: {\n adapter: T\n locales: string[]\n rawTable: RawTable\n}) => void\n\nexport type BlocksToJsonBlockToMigrate = {\n data: Record<string, unknown> | Record<string, unknown>[]\n fieldAccessor: (number | string)[]\n}\n\nexport interface BaseBlocksToJsonEntityToMigrate {\n blocks: BlocksToJsonBlockToMigrate[]\n originalData: Record<string, any>\n}\n\nexport interface CollectionOrVersionBlocksToJsonEntityToMigrate\n extends BaseBlocksToJsonEntityToMigrate {\n id: number | string\n slug: string\n type: 'collection' | 'collectionVersion' | 'globalVersion'\n}\n\nexport interface GlobalBlocksToJsonEntityToMigrate extends BaseBlocksToJsonEntityToMigrate {\n slug: string\n type: 'global'\n}\n\nexport type BlocksToJsonEntityToMigrate =\n | CollectionOrVersionBlocksToJsonEntityToMigrate\n | GlobalBlocksToJsonEntityToMigrate\n\nexport interface BlocksToJsonMigrator {\n collectAndSaveEntitiesToBatches(\n req: PayloadRequest,\n options?: {\n batchSize?: number\n },\n ): Promise<void>\n getMigrationStatements(): Promise<{\n statements: string\n writeDrizzleSnapshot(filePath: string): void\n }>\n migrateEntitiesFromTempFolder(\n req: PayloadRequest,\n options?: {\n clearBatches?: boolean\n },\n ): Promise<void>\n setTempFolder(tempFolderPath: string): void\n updatePayloadConfigFile(): Promise<void>\n}\n\n/**\n * The information passed to a query-operator handler for one user-facing leaf comparison.\n */\nexport type DrizzleOperatorHandlerContext = {\n adapter: DrizzleAdapter\n column: Column | SQL\n field: FlattenedField\n locale?: string\n /** The operator supplied by the Payload query, before any adapter conversions. */\n originalOperator: Operator\n path: string\n /** The operator actually sent to the database after Payload's existing conversions. */\n resolvedOperator: DrizzleResolvedOperator\n storage: 'column'\n value: unknown\n}\n\n/**\n * Transforms the column and/or value of a matching operator before the default (or replacement)\n * comparison runs. Multiple matching transform handlers compose in configuration order.\n */\nexport type DrizzleOperandTransformHandler = {\n build?: never\n /** Restricts the handler to these Payload field types. Omit to match every field type. */\n fieldTypes?: FlattenedField['type'][]\n name: string\n operators: DrizzleResolvedOperator[]\n transformOperands: (context: DrizzleOperatorHandlerContext) => {\n column: Column | SQL\n value: unknown\n }\n}\n\n/**\n * Replaces the default comparison for a matching operator entirely. Runs after every matching\n * `transformOperands` handler has already run.\n */\nexport type DrizzleOperatorReplacementHandler = {\n build: (context: DrizzleOperatorHandlerContext) => SQL\n /** Restricts the handler to these Payload field types. Omit to match every field type. */\n fieldTypes?: FlattenedField['type'][]\n name: string\n operators: DrizzleResolvedOperator[]\n transformOperands?: never\n}\n\nexport type DrizzleOperatorHandler =\n | DrizzleOperandTransformHandler\n | DrizzleOperatorReplacementHandler\n\nexport type DrizzleQueryConfig = {\n operatorHandlers?: DrizzleOperatorHandler[]\n}\n\nexport interface DrizzleAdapter extends BaseDatabaseAdapter {\n blocksAsJSON?: boolean\n blocksToJsonMigrator?: BlocksToJsonMigrator\n convertPathToJSONTraversal?: (incomingSegments: string[]) => string\n countDistinct: CountDistinct\n createJSONQuery: (args: CreateJSONQueryArgs) => string\n defaultDrizzleSnapshot: Record<string, unknown>\n deleteWhere: DeleteWhere\n drizzle: LibSQLDatabase | PostgresDB\n dropDatabase: DropDatabase\n enums?: never | Record<string, unknown>\n execute: Execute<unknown>\n features: {\n json?: boolean\n }\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<string, Record<string, string>>\n\n foreignKeys: Set<string>\n idType: 'serial' | 'uuid' | 'uuidv7'\n indexes: Set<string>\n initializing: Promise<void>\n insert: Insert\n /**\n * Timestamp (ms) of the last write operation. When read replicas are configured,\n * reads within `readReplicasAfterWriteInterval` ms of this timestamp are routed to the\n * primary to guarantee read-after-write consistency.\n */\n lastWriteTimestamp?: number\n limitedBoundParameters?: boolean\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operatorHandlers: DrizzleOperatorHandler[]\n operators: Operators\n /**\n * When read replicas are configured, holds the unwrapped primary drizzle instance\n * (before withReplicas wrapping). Used for reads that are part of write operations\n * to avoid replication lag.\n */\n primaryDrizzle?: PostgresDB\n push: boolean\n rawRelations: Record<string, Record<string, RawRelation>>\n rawTables: Record<string, RawTable>\n /**\n * How long (ms) after a write to route reads to the primary instead of a\n * read replica. Avoids stale reads caused by replication lag.\n * @default 2000\n */\n readReplicasAfterWriteInterval: number\n\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n requireDrizzleKit: RequireDrizzleKit\n resolveInitializing: () => void\n\n schema: Record<string, unknown>\n\n schemaName?: string\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, any>\n transactionOptions: unknown\n versionsSuffix?: string\n}\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n"],"names":[],"mappings":"AAqgBA,WAQC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Column,\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n SQL,\n TableRelationalConfig,\n} from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type {\n PgColumn,\n PgTable,\n PgTransaction,\n Precision,\n UpdateDeleteAction,\n} from 'drizzle-orm/pg-core'\nimport type { SQLiteColumn, SQLiteTable, SQLiteTransaction } from 'drizzle-orm/sqlite-core'\nimport type { Result } from 'drizzle-orm/sqlite-core/session'\nimport type {\n BaseDatabaseAdapter,\n FlattenedField,\n MigrationData,\n Operator,\n Payload,\n PayloadRequest,\n} from 'payload'\n\nimport type { BuildQueryJoinAliases } from './queries/buildQuery.js'\n\nexport { BuildQueryJoinAliases }\n\nimport type { ResultSet } from '@libsql/client'\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'\nimport type { QueryResult } from 'pg'\n\nimport type { DrizzleResolvedOperator, Operators } from './queries/operatorMap.js'\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type SQLiteDB = LibSQLDatabase<\n Record<string, GenericRelation | GenericTable> & Record<string, unknown>\n>\n\nexport type GenericPgColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns<T> = {\n [x: string]: T\n}\n\ntype GenericPgTable = PgTable<{\n columns: GenericColumns<GenericPgColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\ntype GenericSQLiteTable = SQLiteTable<{\n columns: GenericColumns<SQLiteColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\nexport type GenericColumn = GenericPgColumn | SQLiteColumn\n\nexport type GenericTable = GenericPgTable | GenericSQLiteTable\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type TransactionSQLite = SQLiteTransaction<\n 'async',\n Result<'async', unknown>,\n Record<string, unknown>,\n { tsName: TableRelationalConfig }\n>\nexport type TransactionPg = PgTransaction<\n NodePgQueryResultHKT,\n Record<string, unknown>,\n ExtractTablesWithRelations<Record<string, unknown>>\n>\n\nexport type DrizzleTransaction = TransactionPg | TransactionSQLite\n\nexport type CountDistinct = (args: {\n column?: PgColumn<any> | SQLiteColumn<any>\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: DrizzleAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n drizzle?: LibSQLDatabase | PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) =>\n | Promise<QueryResult<Record<string, T>>>\n | SQLiteRaw<Promise<{ rows: T[] }>>\n | SQLiteRaw<ResultSet>\n\nexport type Insert = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n onConflictDoUpdate?: unknown\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type RequireDrizzleKit = () => {\n generateDrizzleJson: (\n args: Record<string, unknown>,\n ) => DrizzleSnapshotJSON | Promise<DrizzleSnapshotJSON>\n generateMigration: (prev: DrizzleSnapshotJSON, cur: DrizzleSnapshotJSON) => Promise<string[]>\n pushSchema: (\n schema: Record<string, unknown>,\n drizzle: DrizzleAdapter['drizzle'],\n filterSchema?: string[],\n tablesFilter?: string[],\n extensionsFilter?: string[],\n ) => Promise<{ apply; hasDataLoss; warnings }>\n upSnapshot?: (snapshot: Record<string, unknown>) => DrizzleSnapshotJSON\n}\n\nexport type Migration = {\n down: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase<Record<string, never>> | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n up: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n} & MigrationData\n\nexport type CreateJSONQueryArgs = {\n column?: Column | string\n operator: string\n pathSegments: string[]\n rawColumn?: SQL<unknown>\n table?: string\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: boolean | number | number[] | string | string[]\n}\n\n/**\n * Abstract relation link\n */\nexport type RawRelation =\n | {\n fields: { name: string; table: string }[]\n references: string[]\n relationName?: string\n to: string\n type: 'one'\n }\n | {\n relationName?: string\n to: string\n type: 'many'\n }\n\n/**\n * Abstract SQL table that later gets converted by database specific implementation to Drizzle\n */\nexport type RawTable = {\n columns: Record<string, RawColumn>\n foreignKeys?: Record<string, RawForeignKey>\n indexes?: Record<string, RawIndex>\n name: string\n}\n\n/**\n * Abstract SQL foreign key that later gets converted by database specific implementation to Drizzle\n */\nexport type RawForeignKey = {\n columns: string[]\n foreignColumns: { name: string; table: string }[]\n name: string\n onDelete?: UpdateDeleteAction\n onUpdate?: UpdateDeleteAction\n}\n\n/**\n * Abstract SQL index that later gets converted by database specific implementation to Drizzle\n */\nexport type RawIndex = {\n name: string\n on: string | string[]\n unique?: boolean\n}\n\n/**\n * Abstract SQL column that later gets converted by database specific implementation to Drizzle\n */\nexport type BaseRawColumn = {\n default?: any\n name: string\n notNull?: boolean\n primaryKey?: boolean\n reference?: {\n name: string\n onDelete: UpdateDeleteAction\n table: string\n }\n}\n\n/**\n * Postgres: native timestamp type\n * SQLite: text column, defaultNow achieved through strftime('%Y-%m-%dT%H:%M:%fZ', 'now'). withTimezone/precision have no any effect.\n */\nexport type TimestampRawColumn = {\n defaultNow?: boolean\n mode: 'date' | 'string'\n precision: Precision\n type: 'timestamp'\n withTimezone?: boolean\n} & BaseRawColumn\n\n/**\n * Postgres: native UUID type and db lavel defaultRandom\n * SQLite: text type and defaultRandom in the app level\n */\nexport type UUIDRawColumn = {\n defaultRandom?: boolean\n /** App-side UUID v7 default (Postgres & SQLite); mutually exclusive with defaultRandom in practice */\n defaultV7?: boolean\n type: 'uuid'\n} & BaseRawColumn\n\n/**\n * Accepts either `locale: true` to have options from locales or `options` string array\n * Postgres: native enums\n * SQLite: text column with checks.\n */\nexport type EnumRawColumn = (\n | {\n enumName: string\n options: string[]\n type: 'enum'\n }\n | {\n locale: true\n type: 'enum'\n }\n) &\n BaseRawColumn\n\nexport type IntegerRawColumn = {\n /**\n * SQLite only.\n * Enable [AUTOINCREMENT](https://www.sqlite.org/autoinc.html) for primary key to ensure that the same ID cannot be reused from previously deleted rows.\n */\n autoIncrement?: boolean\n type: 'integer'\n} & BaseRawColumn\n\nexport type VectorRawColumn = {\n dimensions?: number\n type: 'vector'\n} & BaseRawColumn\n\nexport type HalfVecRawColumn = {\n dimensions?: number\n type: 'halfvec'\n} & BaseRawColumn\n\nexport type SparseVecRawColumn = {\n dimensions?: number\n type: 'sparsevec'\n} & BaseRawColumn\n\nexport type BinaryVecRawColumn = {\n dimensions?: number\n type: 'bit'\n} & BaseRawColumn\n\nexport type RawColumn =\n | ({\n type: 'boolean' | 'geometry' | 'jsonb' | 'numeric' | 'serial' | 'text' | 'varchar'\n } & BaseRawColumn)\n | BinaryVecRawColumn\n | EnumRawColumn\n | HalfVecRawColumn\n | IntegerRawColumn\n | SparseVecRawColumn\n | TimestampRawColumn\n | UUIDRawColumn\n | VectorRawColumn\n\nexport type IDType = 'integer' | 'numeric' | 'text' | 'uuid' | 'varchar'\n\nexport type SetColumnID = (args: {\n adapter: DrizzleAdapter\n columns: Record<string, RawColumn>\n fields: FlattenedField[]\n}) => IDType\n\nexport type ColumnToCodeConverter = (args: {\n adapter: DrizzleAdapter\n addEnum: (name: string, options: string[]) => void\n addImport: (from: string, name: string) => void\n circularEdges?: Set<string>\n column: RawColumn\n locales?: string[]\n tableKey: string\n}) => string\n\nexport type BuildDrizzleTable<T extends DrizzleAdapter = DrizzleAdapter> = (args: {\n adapter: T\n locales: string[]\n rawTable: RawTable\n}) => void\n\nexport type BlocksToJsonBlockToMigrate = {\n data: Record<string, unknown> | Record<string, unknown>[]\n fieldAccessor: (number | string)[]\n}\n\nexport interface BaseBlocksToJsonEntityToMigrate {\n blocks: BlocksToJsonBlockToMigrate[]\n originalData: Record<string, any>\n}\n\nexport interface CollectionOrVersionBlocksToJsonEntityToMigrate extends BaseBlocksToJsonEntityToMigrate {\n id: number | string\n slug: string\n type: 'collection' | 'collectionVersion' | 'globalVersion'\n}\n\nexport interface GlobalBlocksToJsonEntityToMigrate extends BaseBlocksToJsonEntityToMigrate {\n slug: string\n type: 'global'\n}\n\nexport type BlocksToJsonEntityToMigrate =\n | CollectionOrVersionBlocksToJsonEntityToMigrate\n | GlobalBlocksToJsonEntityToMigrate\n\nexport interface BlocksToJsonMigrator {\n collectAndSaveEntitiesToBatches(\n req: PayloadRequest,\n options?: {\n batchSize?: number\n },\n ): Promise<void>\n getMigrationStatements(): Promise<{\n statements: string\n writeDrizzleSnapshot(filePath: string): void\n }>\n migrateEntitiesFromTempFolder(\n req: PayloadRequest,\n options?: {\n clearBatches?: boolean\n },\n ): Promise<void>\n setTempFolder(tempFolderPath: string): void\n updatePayloadConfigFile(): Promise<void>\n}\n\n/**\n * The information passed to a query-operator handler for one user-facing leaf comparison.\n */\nexport type DrizzleOperatorHandlerContext = {\n adapter: DrizzleAdapter\n column: Column | SQL\n field: FlattenedField\n locale?: string\n /** The operator supplied by the Payload query, before any adapter conversions. */\n originalOperator: Operator\n path: string\n /** The operator actually sent to the database after Payload's existing conversions. */\n resolvedOperator: DrizzleResolvedOperator\n storage: 'column'\n value: unknown\n}\n\n/**\n * Transforms the column and/or value of a matching operator before the default (or replacement)\n * comparison runs. Multiple matching transform handlers compose in configuration order.\n */\nexport type DrizzleOperandTransformHandler = {\n build?: never\n /** Restricts the handler to these Payload field types. Omit to match every field type. */\n fieldTypes?: FlattenedField['type'][]\n name: string\n operators: DrizzleResolvedOperator[]\n transformOperands: (context: DrizzleOperatorHandlerContext) => {\n column: Column | SQL\n value: unknown\n }\n}\n\n/**\n * Replaces the default comparison for a matching operator entirely. Runs after every matching\n * `transformOperands` handler has already run.\n */\nexport type DrizzleOperatorReplacementHandler = {\n build: (context: DrizzleOperatorHandlerContext) => SQL\n /** Restricts the handler to these Payload field types. Omit to match every field type. */\n fieldTypes?: FlattenedField['type'][]\n name: string\n operators: DrizzleResolvedOperator[]\n transformOperands?: never\n}\n\nexport type DrizzleOperatorHandler =\n | DrizzleOperandTransformHandler\n | DrizzleOperatorReplacementHandler\n\nexport type DrizzleQueryConfig = {\n operatorHandlers?: DrizzleOperatorHandler[]\n}\n\nexport interface DrizzleAdapter extends BaseDatabaseAdapter {\n blocksAsJSON?: boolean\n blocksToJsonMigrator?: BlocksToJsonMigrator\n convertPathToJSONTraversal?: (incomingSegments: string[]) => string\n countDistinct: CountDistinct\n createJSONQuery: (args: CreateJSONQueryArgs) => string\n defaultDrizzleSnapshot: Record<string, unknown>\n deleteWhere: DeleteWhere\n drizzle: LibSQLDatabase | PostgresDB\n dropDatabase: DropDatabase\n enums?: never | Record<string, unknown>\n execute: Execute<unknown>\n features: {\n json?: boolean\n }\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<string, Record<string, string>>\n\n foreignKeys: Set<string>\n idType: 'serial' | 'uuid' | 'uuidv7'\n indexes: Set<string>\n initializing: Promise<void>\n insert: Insert\n /**\n * Timestamp (ms) of the last write operation. When read replicas are configured,\n * reads within `readReplicasAfterWriteInterval` ms of this timestamp are routed to the\n * primary to guarantee read-after-write consistency.\n */\n lastWriteTimestamp?: number\n limitedBoundParameters?: boolean\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operatorHandlers: DrizzleOperatorHandler[]\n operators: Operators\n /**\n * When read replicas are configured, holds the unwrapped primary drizzle instance\n * (before withReplicas wrapping). Used for reads that are part of write operations\n * to avoid replication lag.\n */\n primaryDrizzle?: PostgresDB\n push: boolean\n rawRelations: Record<string, Record<string, RawRelation>>\n rawTables: Record<string, RawTable>\n /**\n * How long (ms) after a write to route reads to the primary instead of a\n * read replica. Avoids stale reads caused by replication lag.\n * @default 2000\n */\n readReplicasAfterWriteInterval: number\n\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n requireDrizzleKit: RequireDrizzleKit\n resolveInitializing: () => void\n\n schema: Record<string, unknown>\n\n schemaName?: string\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, any>\n transactionOptions: unknown\n versionsSuffix?: string\n}\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n"],"names":[],"mappings":"AAmgBA,WAQC"}
|
package/dist/updateGlobal.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import type { UpdateGlobalArgs } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
|
|
4
|
-
branchConflictData?: Record<string, unknown>;
|
|
5
|
-
} & UpdateGlobalArgs;
|
|
6
|
-
export declare function updateGlobal<T extends Record<string, unknown>>(this: DrizzleAdapter, { slug, branch, branchConflictData, data, req, returning, select }: BranchUpdateGlobalArgs): Promise<T>;
|
|
7
|
-
export {};
|
|
3
|
+
export declare function updateGlobal<T extends Record<string, unknown>>(this: DrizzleAdapter, { slug, data, req, returning, select }: UpdateGlobalArgs): Promise<T>;
|
|
8
4
|
//# sourceMappingURL=updateGlobal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,cAAc,EACpB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,gBAAgB,GACvD,OAAO,CAAC,CAAC,CAAC,CA2BZ"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,79 +1,21 @@
|
|
|
1
|
-
import { deepCopyObjectSimple, resolveBranchGlobalWrite } from 'payload';
|
|
2
|
-
import { traverseFields } from 'payload/shared';
|
|
3
1
|
import toSnakeCase from 'to-snake-case';
|
|
4
|
-
import { v4 as uuid } from 'uuid';
|
|
5
|
-
import { findGlobal } from './findGlobal.js';
|
|
6
2
|
import { upsertRow } from './upsertRow/index.js';
|
|
7
3
|
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
8
4
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
9
|
-
export async function updateGlobal({ slug,
|
|
5
|
+
export async function updateGlobal({ slug, data, req, returning, select }) {
|
|
10
6
|
const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
|
|
11
7
|
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
|
12
8
|
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
13
|
-
const
|
|
14
|
-
branch,
|
|
15
|
-
globalSlug: slug,
|
|
16
|
-
req
|
|
17
|
-
});
|
|
18
|
-
// Each global has its own table holding one row per branch. On a branch the
|
|
19
|
-
// write targets that branch's row, seeded from main's content the first time
|
|
20
|
-
// the global is touched.
|
|
21
|
-
const rows = await db.query[tableName].findMany({});
|
|
22
|
-
const existingGlobal = writeBranch ? rows.find((row)=>row._branch === writeBranch) : rows.find((row)=>(row._branch ?? 'main') === 'main');
|
|
23
|
-
const mainRow = rows.find((row)=>(row._branch ?? 'main') === 'main');
|
|
24
|
-
const mainGlobal = writeBranch && !existingGlobal ? await findGlobal.call(this, {
|
|
25
|
-
slug,
|
|
26
|
-
branch: false,
|
|
27
|
-
locale: 'all',
|
|
28
|
-
req,
|
|
29
|
-
where: typeof mainRow?.id === 'string' || typeof mainRow?.id === 'number' ? {
|
|
30
|
-
id: {
|
|
31
|
-
equals: mainRow.id
|
|
32
|
-
}
|
|
33
|
-
} : {
|
|
34
|
-
_branch: {
|
|
35
|
-
equals: 'main'
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}) : null;
|
|
39
|
-
const mainSource = mainGlobal && Object.keys(mainGlobal).length ? mainGlobal : mainRow ?? {};
|
|
40
|
-
const { id: _mainID, _branch: _mainBranch, globalType: _mainGlobalType, ...mainData } = mainSource;
|
|
41
|
-
const branchData = writeBranch ? {
|
|
42
|
-
...data,
|
|
43
|
-
_branch: writeBranch
|
|
44
|
-
} : data;
|
|
45
|
-
const branchConflictWriteData = writeBranch ? {
|
|
46
|
-
...branchConflictData ?? data,
|
|
47
|
-
_branch: writeBranch
|
|
48
|
-
} : data;
|
|
49
|
-
const dataToWrite = writeBranch && !existingGlobal ? copyGlobalDataWithFreshRowIDs({
|
|
50
|
-
config: this.payload.config,
|
|
51
|
-
data: {
|
|
52
|
-
...mainData,
|
|
53
|
-
...branchData
|
|
54
|
-
},
|
|
55
|
-
fields: globalConfig.fields
|
|
56
|
-
}) : branchData;
|
|
57
|
-
const conflictDataToWrite = writeBranch && !existingGlobal ? copyGlobalDataWithFreshRowIDs({
|
|
58
|
-
config: this.payload.config,
|
|
59
|
-
data: branchConflictWriteData,
|
|
60
|
-
fields: globalConfig.fields
|
|
61
|
-
}) : branchConflictWriteData;
|
|
9
|
+
const existingGlobal = await db.query[tableName].findFirst({});
|
|
62
10
|
const result = await upsertRow({
|
|
63
|
-
...
|
|
64
|
-
operation: 'update',
|
|
65
|
-
...!existingGlobal ? {
|
|
66
|
-
upsertConflictData: conflictDataToWrite
|
|
67
|
-
} : {},
|
|
68
|
-
upsertTarget: this.tables[tableName]._branch
|
|
69
|
-
} : existingGlobal ? {
|
|
11
|
+
...existingGlobal ? {
|
|
70
12
|
id: existingGlobal.id,
|
|
71
13
|
operation: 'update'
|
|
72
14
|
} : {
|
|
73
15
|
operation: 'create'
|
|
74
16
|
},
|
|
75
17
|
adapter: this,
|
|
76
|
-
data
|
|
18
|
+
data,
|
|
77
19
|
db,
|
|
78
20
|
fields: globalConfig.flattenedFields,
|
|
79
21
|
globalSlug: slug,
|
|
@@ -88,39 +30,5 @@ export async function updateGlobal({ slug, branch, branchConflictData, data, req
|
|
|
88
30
|
result.globalType = slug;
|
|
89
31
|
return result;
|
|
90
32
|
}
|
|
91
|
-
const copyGlobalDataWithFreshRowIDs = ({ config, data, fields })=>{
|
|
92
|
-
const clonedData = deepCopyObjectSimple(data);
|
|
93
|
-
traverseFields({
|
|
94
|
-
callback: ({ field, ref })=>{
|
|
95
|
-
if (field.type !== 'array' && field.type !== 'blocks' || !('name' in field) || !field.name || !ref || typeof ref !== 'object') {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const value = ref[field.name];
|
|
99
|
-
const rekeyRows = (rows)=>{
|
|
100
|
-
if (!Array.isArray(rows)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
for (const row of rows){
|
|
104
|
-
if (row && typeof row === 'object' && 'id' in row) {
|
|
105
|
-
const rowData = row;
|
|
106
|
-
rowData.id = typeof rowData.id === 'string' ? uuid() : undefined;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
if (Array.isArray(value)) {
|
|
111
|
-
rekeyRows(value);
|
|
112
|
-
} else if (value && typeof value === 'object') {
|
|
113
|
-
for (const localizedRows of Object.values(value)){
|
|
114
|
-
rekeyRows(localizedRows);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
config,
|
|
119
|
-
fields,
|
|
120
|
-
fillEmpty: false,
|
|
121
|
-
ref: clonedData
|
|
122
|
-
});
|
|
123
|
-
return clonedData;
|
|
124
|
-
};
|
|
125
33
|
|
|
126
34
|
//# sourceMappingURL=updateGlobal.js.map
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req, returning, select }: UpdateGlobalArgs,\n): Promise<T> {\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n const existingGlobal = await db.query[tableName].findFirst({})\n\n const result = await upsertRow<{ globalType: string } & T>({\n ...(existingGlobal ? { id: existingGlobal.id, operation: 'update' } : { operation: 'create' }),\n adapter: this,\n data,\n db,\n fields: globalConfig.flattenedFields,\n globalSlug: slug,\n ignoreResult: returning === false,\n req,\n select,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n result.globalType = slug\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getPrimaryDb","getTransaction","updateGlobal","slug","data","req","returning","select","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","db","existingGlobal","query","findFirst","result","id","operation","adapter","fields","flattenedFields","globalSlug","ignoreResult","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAoB;IAExD,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOR,IAAI,KAAKA;IAClF,MAAMU,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACjB,YAAYU,aAAaL,IAAI;IAErE,MAAMa,KAAKhB,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEI;IACzD,MAAMY,iBAAiB,MAAMD,GAAGE,KAAK,CAACL,UAAU,CAACM,SAAS,CAAC,CAAC;IAE5D,MAAMC,SAAS,MAAMrB,UAAsC;QACzD,GAAIkB,iBAAiB;YAAEI,IAAIJ,eAAeI,EAAE;YAAEC,WAAW;QAAS,IAAI;YAAEA,WAAW;QAAS,CAAC;QAC7FC,SAAS,IAAI;QACbnB;QACAY;QACAQ,QAAQhB,aAAaiB,eAAe;QACpCC,YAAYvB;QACZwB,cAAcrB,cAAc;QAC5BD;QACAE;QACAM;IACF;IAEA,IAAIP,cAAc,OAAO;QACvB,OAAO;IACT;IAEAc,OAAOQ,UAAU,GAAGzB;IAEpB,OAAOiB;AACT"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAgBxC,eAAO,MAAM,SAAS,EAAE,SAiIvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { and, eq } from 'drizzle-orm';
|
|
2
|
-
import { applyBranchIDProjection, resolveBranchRowID, withBranchIDSelect } from 'payload';
|
|
3
1
|
import toSnakeCase from 'to-snake-case';
|
|
4
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
5
3
|
import { selectDistinct } from './queries/selectDistinct.js';
|
|
@@ -10,17 +8,12 @@ import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpser
|
|
|
10
8
|
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
11
9
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
12
10
|
import { markWrite } from './utilities/readAfterWrite.js';
|
|
13
|
-
export const updateOne = async function updateOne({ id,
|
|
11
|
+
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, joins: joinQuery, locale, options = {
|
|
14
12
|
upsert: false
|
|
15
13
|
}, req, returning, select, where: whereArg }) {
|
|
16
14
|
const collection = this.payload.collections[collectionSlug].config;
|
|
17
15
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
18
|
-
let idToUpdate = id
|
|
19
|
-
id,
|
|
20
|
-
branch,
|
|
21
|
-
collectionSlug,
|
|
22
|
-
req
|
|
23
|
-
});
|
|
16
|
+
let idToUpdate = id;
|
|
24
17
|
let whereToUpdate;
|
|
25
18
|
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
26
19
|
if (!idToUpdate) {
|
|
@@ -35,9 +28,6 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
|
|
|
35
28
|
// queries keep resolving a matching id first and then update that row unconditionally
|
|
36
29
|
whereToUpdate = joins.length === 0 ? where : undefined;
|
|
37
30
|
if (options.atomic === true) {
|
|
38
|
-
if (joins.length > 0) {
|
|
39
|
-
throw new Error('Atomic where updates do not support predicates that require joins');
|
|
40
|
-
}
|
|
41
31
|
if (!shouldUseOptimizedUpsertRow({
|
|
42
32
|
data,
|
|
43
33
|
fields: collection.flattenedFields
|
|
@@ -54,20 +44,12 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
|
|
|
54
44
|
if (arraysToPush && Object.keys(arraysToPush).length) {
|
|
55
45
|
throw new Error('Atomic where updates do not support array operations');
|
|
56
46
|
}
|
|
57
|
-
const table = this.tables[tableName];
|
|
58
|
-
const matchingRows = await db.select({
|
|
59
|
-
id: table.id
|
|
60
|
-
}).from(table).where(where).limit(1);
|
|
61
|
-
const matchingRowID = matchingRows[0]?.id;
|
|
62
|
-
if (matchingRowID === undefined || matchingRowID === null) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
47
|
markWrite(this);
|
|
66
|
-
const docs = await db.update(
|
|
48
|
+
const docs = await db.update(this.tables[tableName]).set(row).where(where).returning();
|
|
67
49
|
if (!docs[0]) {
|
|
68
50
|
return null;
|
|
69
51
|
}
|
|
70
|
-
|
|
52
|
+
return transform({
|
|
71
53
|
adapter: this,
|
|
72
54
|
config: this.payload.config,
|
|
73
55
|
data: docs[0],
|
|
@@ -75,15 +57,6 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
|
|
|
75
57
|
joinQuery: false,
|
|
76
58
|
tableName
|
|
77
59
|
});
|
|
78
|
-
applyBranchIDProjection({
|
|
79
|
-
branch,
|
|
80
|
-
collectionSlug,
|
|
81
|
-
docs: [
|
|
82
|
-
result
|
|
83
|
-
],
|
|
84
|
-
req
|
|
85
|
-
});
|
|
86
|
-
return result;
|
|
87
60
|
}
|
|
88
61
|
// selectDistinct will only return if there are joins
|
|
89
62
|
const selectDistinctResult = await selectDistinct({
|
|
@@ -123,28 +96,13 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
|
|
|
123
96
|
joinQuery,
|
|
124
97
|
operation: 'update',
|
|
125
98
|
req,
|
|
126
|
-
select
|
|
127
|
-
branch,
|
|
128
|
-
collectionSlug,
|
|
129
|
-
req,
|
|
130
|
-
select
|
|
131
|
-
}),
|
|
99
|
+
select,
|
|
132
100
|
tableName,
|
|
133
101
|
where: whereToUpdate
|
|
134
102
|
});
|
|
135
103
|
if (returning === false) {
|
|
136
104
|
return null;
|
|
137
105
|
}
|
|
138
|
-
// The row written on a branch is the shadow row, so the document it returns
|
|
139
|
-
// carries that row's primary key rather than the document's canonical ID.
|
|
140
|
-
applyBranchIDProjection({
|
|
141
|
-
branch,
|
|
142
|
-
collectionSlug,
|
|
143
|
-
docs: [
|
|
144
|
-
result
|
|
145
|
-
],
|
|
146
|
-
req
|
|
147
|
-
});
|
|
148
106
|
return result;
|
|
149
107
|
};
|
|
150
108
|
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateOne } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { transform } from './transform/read/index.js'\nimport { transformForWrite } from './transform/write/index.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\nimport { markWrite } from './utilities/readAfterWrite.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: DrizzleAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n joins: joinQuery,\n locale,\n options = { upsert: false },\n req,\n returning,\n select,\n where: whereArg,\n },\n) {\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n let idToUpdate = id\n let whereToUpdate: SQL<unknown> | undefined\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n if (!idToUpdate) {\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n tableName,\n where: whereArg,\n })\n // A `where` that needs joins cannot be applied to the UPDATE statement itself, so those\n // queries keep resolving a matching id first and then update that row unconditionally\n whereToUpdate = joins.length === 0 ? where : undefined\n\n if (options.atomic === true) {\n if (!shouldUseOptimizedUpsertRow({ data, fields: collection.flattenedFields })) {\n throw new Error('Atomic where updates only support fields stored on the main table')\n }\n\n const { arraysToPush, row } = transformForWrite({\n adapter: this,\n data,\n enableAtomicWrites: true,\n fields: collection.flattenedFields,\n tableName,\n })\n\n if (arraysToPush && Object.keys(arraysToPush).length) {\n throw new Error('Atomic where updates do not support array operations')\n }\n\n markWrite(this)\n\n const docs = await (db as LibSQLDatabase)\n .update(this.tables[tableName])\n .set(row)\n .where(where)\n .returning()\n\n if (!docs[0]) {\n return null\n }\n\n return transform({\n adapter: this,\n config: this.payload.config,\n data: docs[0],\n fields: collection.flattenedFields,\n joinQuery: false,\n tableName,\n })\n }\n\n // selectDistinct will only return if there are joins\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n query: ({ query }) => query.limit(1),\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idToUpdate = selectDistinctResult?.[0]?.id\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n } else if (whereArg && !joins.length) {\n const table = this.tables[tableName]\n\n const docsToUpdate = await (db as LibSQLDatabase)\n .select({\n id: table.id,\n })\n .from(table)\n .where(where)\n .limit(1)\n idToUpdate = docsToUpdate?.[0]?.id\n }\n }\n\n if (!idToUpdate && !options.upsert) {\n // TODO: In 4.0, if returning === false, we should differentiate between:\n // - No document found to update\n // - Document found, but returning === false\n return null\n }\n\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n collectionSlug,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n joinQuery,\n operation: 'update',\n req,\n select,\n tableName,\n where: whereToUpdate,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","transform","transformForWrite","upsertRow","shouldUseOptimizedUpsertRow","getPrimaryDb","getTransaction","markWrite","updateOne","id","collection","collectionSlug","data","joins","joinQuery","locale","options","upsert","req","returning","select","where","whereArg","payload","collections","config","tableName","tableNameMap","get","slug","idToUpdate","whereToUpdate","db","selectFields","adapter","fields","flattenedFields","length","undefined","atomic","Error","arraysToPush","row","enableAtomicWrites","Object","keys","docs","update","tables","set","selectDistinctResult","query","limit","table","docsToUpdate","from","result","ignoreResult","operation"],"mappings":"AAIA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AACxF,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,SAAS,QAAQ,gCAA+B;AAEzD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,OAAOC,SAAS,EAChBC,MAAM,EACNC,UAAU;IAAEC,QAAQ;AAAM,CAAC,EAC3BC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,MAAMZ,aAAa,IAAI,CAACa,OAAO,CAACC,WAAW,CAACb,eAAe,CAACc,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC9B,YAAYY,WAAWmB,IAAI;IACnE,IAAIC,aAAarB;IACjB,IAAIsB;IAEJ,MAAMC,KAAK3B,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEY;IAEzD,IAAI,CAACY,YAAY;QACf,MAAM,EAAEjB,KAAK,EAAEoB,YAAY,EAAEZ,KAAK,EAAE,GAAGtB,WAAW;YAChDmC,SAAS,IAAI;YACbC,QAAQzB,WAAW0B,eAAe;YAClCrB;YACAW;YACAL,OAAOC;QACT;QACA,wFAAwF;QACxF,sFAAsF;QACtFS,gBAAgBlB,MAAMwB,MAAM,KAAK,IAAIhB,QAAQiB;QAE7C,IAAItB,QAAQuB,MAAM,KAAK,MAAM;YAC3B,IAAI,CAACnC,4BAA4B;gBAAEQ;gBAAMuB,QAAQzB,WAAW0B,eAAe;YAAC,IAAI;gBAC9E,MAAM,IAAII,MAAM;YAClB;YAEA,MAAM,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGxC,kBAAkB;gBAC9CgC,SAAS,IAAI;gBACbtB;gBACA+B,oBAAoB;gBACpBR,QAAQzB,WAAW0B,eAAe;gBAClCV;YACF;YAEA,IAAIe,gBAAgBG,OAAOC,IAAI,CAACJ,cAAcJ,MAAM,EAAE;gBACpD,MAAM,IAAIG,MAAM;YAClB;YAEAjC,UAAU,IAAI;YAEd,MAAMuC,OAAO,MAAM,AAACd,GACjBe,MAAM,CAAC,IAAI,CAACC,MAAM,CAACtB,UAAU,EAC7BuB,GAAG,CAACP,KACJrB,KAAK,CAACA,OACNF,SAAS;YAEZ,IAAI,CAAC2B,IAAI,CAAC,EAAE,EAAE;gBACZ,OAAO;YACT;YAEA,OAAO7C,UAAU;gBACfiC,SAAS,IAAI;gBACbT,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;gBAC3Bb,MAAMkC,IAAI,CAAC,EAAE;gBACbX,QAAQzB,WAAW0B,eAAe;gBAClCtB,WAAW;gBACXY;YACF;QACF;QAEA,qDAAqD;QACrD,MAAMwB,uBAAuB,MAAMlD,eAAe;YAChDkC,SAAS,IAAI;YACbF;YACAnB;YACAsC,OAAO,CAAC,EAAEA,KAAK,EAAE,GAAKA,MAAMC,KAAK,CAAC;YAClCnB;YACAP;YACAL;QACF;QAEA,IAAI6B,sBAAsB,CAAC,EAAE,EAAEzC,IAAI;YACjCqB,aAAaoB,sBAAsB,CAAC,EAAE,EAAEzC;QACxC,gFAAgF;QAClF,OAAO,IAAIa,YAAY,CAACT,MAAMwB,MAAM,EAAE;YACpC,MAAMgB,QAAQ,IAAI,CAACL,MAAM,CAACtB,UAAU;YAEpC,MAAM4B,eAAe,MAAM,AAACtB,GACzBZ,MAAM,CAAC;gBACNX,IAAI4C,MAAM5C,EAAE;YACd,GACC8C,IAAI,CAACF,OACLhC,KAAK,CAACA,OACN+B,KAAK,CAAC;YACTtB,aAAawB,cAAc,CAAC,EAAE,EAAE7C;QAClC;IACF;IAEA,IAAI,CAACqB,cAAc,CAACd,QAAQC,MAAM,EAAE;QAClC,yEAAyE;QACzE,gCAAgC;QAChC,4CAA4C;QAC5C,OAAO;IACT;IAEA,MAAMuC,SAAS,MAAMrD,UAAU;QAC7BM,IAAIqB;QACJI,SAAS,IAAI;QACbvB;QACAC;QACAoB;QACAG,QAAQzB,WAAW0B,eAAe;QAClCqB,cAActC,cAAc;QAC5BL;QACA4C,WAAW;QACXxC;QACAE;QACAM;QACAL,OAAOU;IACT;IAEA,IAAIZ,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOqC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGASlC,IAAI,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGASlC,IAAI,KAAG,OAAO,CAAC,IAAI,CA4CrB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { and, eq, inArray } from 'drizzle-orm';
|
|
2
2
|
export const deleteExistingRowsByPath = async ({ adapter, db, localeColumnName = '_locale', parentColumnName = '_parentID', parentID, pathColumnName = '_path', rows, tableName })=>{
|
|
3
|
-
const localizedPathsToDelete = new
|
|
3
|
+
const localizedPathsToDelete = new Set();
|
|
4
4
|
const pathsToDelete = new Set();
|
|
5
5
|
const table = adapter.tables[tableName];
|
|
6
6
|
rows.forEach((row)=>{
|
|
@@ -8,29 +8,24 @@ export const deleteExistingRowsByPath = async ({ adapter, db, localeColumnName =
|
|
|
8
8
|
const localeData = row[localeColumnName];
|
|
9
9
|
if (typeof path === 'string') {
|
|
10
10
|
if (typeof localeData === 'string') {
|
|
11
|
-
|
|
12
|
-
localePaths.add(path);
|
|
13
|
-
localizedPathsToDelete.set(localeData, localePaths);
|
|
11
|
+
localizedPathsToDelete.add(path);
|
|
14
12
|
} else {
|
|
15
13
|
pathsToDelete.add(path);
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
});
|
|
19
17
|
if (localizedPathsToDelete.size > 0) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
whereConstraints.push(inArray(table[pathColumnName], Array.from(localePaths)));
|
|
26
|
-
}
|
|
27
|
-
whereConstraints.push(eq(table[localeColumnName], locale));
|
|
28
|
-
await adapter.deleteWhere({
|
|
29
|
-
db,
|
|
30
|
-
tableName,
|
|
31
|
-
where: and(...whereConstraints)
|
|
32
|
-
});
|
|
18
|
+
const whereConstraints = [
|
|
19
|
+
eq(table[parentColumnName], parentID)
|
|
20
|
+
];
|
|
21
|
+
if (pathColumnName) {
|
|
22
|
+
whereConstraints.push(inArray(table[pathColumnName], Array.from(localizedPathsToDelete)));
|
|
33
23
|
}
|
|
24
|
+
await adapter.deleteWhere({
|
|
25
|
+
db,
|
|
26
|
+
tableName,
|
|
27
|
+
where: and(...whereConstraints)
|
|
28
|
+
});
|
|
34
29
|
}
|
|
35
30
|
if (pathsToDelete.size > 0) {
|
|
36
31
|
const whereConstraints = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"sourcesContent":["import { and, eq, inArray } from 'drizzle-orm'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n localeColumnName?: string\n parentColumnName?: string\n parentID: unknown\n pathColumnName?: string\n rows: Record<string, unknown>[]\n tableName: string\n}\n\nexport const deleteExistingRowsByPath = async ({\n adapter,\n db,\n localeColumnName = '_locale',\n parentColumnName = '_parentID',\n parentID,\n pathColumnName = '_path',\n rows,\n tableName,\n}: Args): Promise<void> => {\n const localizedPathsToDelete = new
|
|
1
|
+
{"version":3,"sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"sourcesContent":["import { and, eq, inArray } from 'drizzle-orm'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n localeColumnName?: string\n parentColumnName?: string\n parentID: unknown\n pathColumnName?: string\n rows: Record<string, unknown>[]\n tableName: string\n}\n\nexport const deleteExistingRowsByPath = async ({\n adapter,\n db,\n localeColumnName = '_locale',\n parentColumnName = '_parentID',\n parentID,\n pathColumnName = '_path',\n rows,\n tableName,\n}: Args): Promise<void> => {\n const localizedPathsToDelete = new Set<string>()\n const pathsToDelete = new Set<string>()\n const table = adapter.tables[tableName]\n\n rows.forEach((row) => {\n const path = row[pathColumnName]\n const localeData = row[localeColumnName]\n if (typeof path === 'string') {\n if (typeof localeData === 'string') {\n localizedPathsToDelete.add(path)\n } else {\n pathsToDelete.add(path)\n }\n }\n })\n\n if (localizedPathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName) {\n whereConstraints.push(inArray(table[pathColumnName], Array.from(localizedPathsToDelete)))\n }\n\n await adapter.deleteWhere({\n db,\n tableName,\n where: and(...whereConstraints),\n })\n }\n\n if (pathsToDelete.size > 0) {\n const whereConstraints = [eq(table[parentColumnName], parentID)]\n\n if (pathColumnName) {\n whereConstraints.push(inArray(table[pathColumnName], Array.from(pathsToDelete)))\n }\n\n await adapter.deleteWhere({\n db,\n tableName,\n where: and(...whereConstraints),\n })\n }\n}\n"],"names":["and","eq","inArray","deleteExistingRowsByPath","adapter","db","localeColumnName","parentColumnName","parentID","pathColumnName","rows","tableName","localizedPathsToDelete","Set","pathsToDelete","table","tables","forEach","row","path","localeData","add","size","whereConstraints","push","Array","from","deleteWhere","where"],"mappings":"AAAA,SAASA,GAAG,EAAEC,EAAE,EAAEC,OAAO,QAAQ,cAAa;AAe9C,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,OAAO,EACPC,EAAE,EACFC,mBAAmB,SAAS,EAC5BC,mBAAmB,WAAW,EAC9BC,QAAQ,EACRC,iBAAiB,OAAO,EACxBC,IAAI,EACJC,SAAS,EACJ;IACL,MAAMC,yBAAyB,IAAIC;IACnC,MAAMC,gBAAgB,IAAID;IAC1B,MAAME,QAAQX,QAAQY,MAAM,CAACL,UAAU;IAEvCD,KAAKO,OAAO,CAAC,CAACC;QACZ,MAAMC,OAAOD,GAAG,CAACT,eAAe;QAChC,MAAMW,aAAaF,GAAG,CAACZ,iBAAiB;QACxC,IAAI,OAAOa,SAAS,UAAU;YAC5B,IAAI,OAAOC,eAAe,UAAU;gBAClCR,uBAAuBS,GAAG,CAACF;YAC7B,OAAO;gBACLL,cAAcO,GAAG,CAACF;YACpB;QACF;IACF;IAEA,IAAIP,uBAAuBU,IAAI,GAAG,GAAG;QACnC,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBAAgB;YAClBc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACd;QAClE;QAEA,MAAMR,QAAQuB,WAAW,CAAC;YACxBtB;YACAM;YACAiB,OAAO5B,OAAOuB;QAChB;IACF;IAEA,IAAIT,cAAcQ,IAAI,GAAG,GAAG;QAC1B,MAAMC,mBAAmB;YAACtB,GAAGc,KAAK,CAACR,iBAAiB,EAAEC;SAAU;QAEhE,IAAIC,gBAAgB;YAClBc,iBAAiBC,IAAI,CAACtB,QAAQa,KAAK,CAACN,eAAe,EAAEgB,MAAMC,IAAI,CAACZ;QAClE;QAEA,MAAMV,QAAQuB,WAAW,CAAC;YACxBtB;YACAM;YACAiB,OAAO5B,OAAOuB;QAChB;IACF;AACF,EAAC"}
|
|
@@ -7,5 +7,5 @@ import type { Args } from './types.js';
|
|
|
7
7
|
*
|
|
8
8
|
* adapter function replaces the entire row and does not support partial updates.
|
|
9
9
|
*/
|
|
10
|
-
export declare const upsertRow: <T extends Record<string, unknown> | TypeWithID>({ id, adapter, collectionSlug, data, db, fields, globalSlug, ignoreResult, customID, joinQuery: _joinQuery, operation, path, req, select, tableName,
|
|
10
|
+
export declare const upsertRow: <T extends Record<string, unknown> | TypeWithID>({ id, adapter, collectionSlug, data, db, fields, globalSlug, ignoreResult, customID, joinQuery: _joinQuery, operation, path, req, select, tableName, upsertTarget, where, }: Args) => Promise<null | T>;
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAqBtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,+KAqB3E,IAAI,KAAG,OAAO,CAAC,IAAI,GAAG,CAAC,CA2uBzB,CAAA"}
|