@payloadcms/drizzle 4.0.0-canary.20261124 → 4.0.0-canary.20261125
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAEV,cAAc,EAGd,IAAI,EACJ,KAAK,EACN,MAAM,SAAS,CAAA;AA0BhB,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAc5D,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAA;AAExD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,OAAO,EAAE,YAAY,CAAA;IACrB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,wBAAgB,WAAW,CAAC,EAC1B,OAAO,EACP,UAAU,EACV,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE,IAAI,GAAG,GAAG,CA+iBZ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { aliasedTable, and, eq, exists, getTableName, isNotNull, isNull, like, notExists, notInArray, or, sql } from 'drizzle-orm';
|
|
2
2
|
import { PgUUID } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { APIError, getFieldByPath, QueryError } from 'payload';
|
|
4
|
+
import { getNestedRelationshipReadConstraint } from 'payload/internal';
|
|
4
5
|
import { hasManyRelationshipOperatorSet, isNestedRelationshipQuery, validOperatorSet } from 'payload/shared';
|
|
5
6
|
import toSnakeCase from 'to-snake-case';
|
|
6
7
|
import { escapeSQLValue } from '../utilities/escapeSQLValue.js';
|
|
@@ -598,11 +599,62 @@ export function parseParams({ adapter, aliasTable, context, fields, joins, local
|
|
|
598
599
|
case 'contains':
|
|
599
600
|
return exists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)));
|
|
600
601
|
case 'equals':
|
|
601
|
-
|
|
602
|
-
|
|
602
|
+
{
|
|
603
|
+
const readConstraint = getNestedRelationshipReadConstraint(where);
|
|
604
|
+
if (readConstraint) {
|
|
605
|
+
// Related documents the caller cannot read must not affect the result: only a readable
|
|
606
|
+
// related document that fails the query excludes the parent.
|
|
607
|
+
const readableRelatedDocumentSubquery = buildReadableRelatedDocumentSubquery({
|
|
608
|
+
adapter,
|
|
609
|
+
locale: relationshipLocale,
|
|
610
|
+
readConstraint,
|
|
611
|
+
relatedCollection,
|
|
612
|
+
relatedTableName,
|
|
613
|
+
relationshipTable,
|
|
614
|
+
relationTo: relationshipField.relationTo
|
|
615
|
+
});
|
|
616
|
+
return notExists(buildRelationshipRowsSubquery(and(exists(readableRelatedDocumentSubquery), notExists(relatedDocumentSubquery))));
|
|
617
|
+
}
|
|
618
|
+
// All related documents match when no relationship row points to one that fails.
|
|
619
|
+
return notExists(buildRelationshipRowsSubquery(notExists(relatedDocumentSubquery)));
|
|
620
|
+
}
|
|
603
621
|
case 'not_equals':
|
|
604
622
|
return notExists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)));
|
|
605
623
|
}
|
|
606
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Builds a subquery that finds the related document a relationship row points to, if the caller
|
|
627
|
+
* can read it. It uses its own table alias and joins so it can sit beside the main related
|
|
628
|
+
* document subquery.
|
|
629
|
+
*/ function buildReadableRelatedDocumentSubquery({ adapter, locale, readConstraint, relatedCollection, relatedTableName, relationshipTable, relationTo }) {
|
|
630
|
+
const { newAliasTable: readableRelatedTable } = getTableAlias({
|
|
631
|
+
adapter,
|
|
632
|
+
tableName: relatedTableName
|
|
633
|
+
});
|
|
634
|
+
const readableJoins = [];
|
|
635
|
+
const readableWhere = parseParams({
|
|
636
|
+
adapter,
|
|
637
|
+
aliasTable: readableRelatedTable,
|
|
638
|
+
context: {
|
|
639
|
+
sort: undefined
|
|
640
|
+
},
|
|
641
|
+
fields: relatedCollection.config.flattenedFields,
|
|
642
|
+
joins: readableJoins,
|
|
643
|
+
locale,
|
|
644
|
+
parentIsLocalized: false,
|
|
645
|
+
selectFields: {},
|
|
646
|
+
tableName: relatedTableName,
|
|
647
|
+
where: readConstraint
|
|
648
|
+
});
|
|
649
|
+
let readableSubquery = adapter.drizzle.select({
|
|
650
|
+
id: readableRelatedTable.id
|
|
651
|
+
}).from(readableRelatedTable).$dynamic();
|
|
652
|
+
for (const join of readableJoins){
|
|
653
|
+
readableSubquery = readableSubquery[join.type ?? 'leftJoin'](join.table, join.condition);
|
|
654
|
+
}
|
|
655
|
+
return readableSubquery.where(and(eq(readableRelatedTable.id, relationshipTable[`${relationTo}ID`]), ...readableWhere ? [
|
|
656
|
+
readableWhere
|
|
657
|
+
] : []));
|
|
658
|
+
}
|
|
607
659
|
|
|
608
660
|
//# sourceMappingURL=parseParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type { FlattenedField, HasManyRelationshipOperator, Operator, Sort, Where } from 'payload'\n\nimport {\n aliasedTable,\n and,\n eq,\n exists,\n getTableName,\n isNotNull,\n isNull,\n like,\n notExists,\n notInArray,\n or,\n sql,\n} from 'drizzle-orm'\nimport { PgUUID } from 'drizzle-orm/pg-core'\nimport { APIError, getFieldByPath, QueryError } from 'payload'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\nimport type { DrizzleResolvedOperator } from './operatorMap.js'\n\nimport { escapeSQLValue } from '../utilities/escapeSQLValue.js'\nimport { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js'\nimport { isValidStringID } from '../utilities/isValidStringID.js'\nimport { DistinctSymbol, isRawConstraint } from '../utilities/rawConstraint.js'\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildOperatorConstraint } from './buildOperatorConstraint.js'\nimport { getTableAlias } from './getTableAlias.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { resolveRelationshipPath } from './resolveRelationshipPath.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nexport type QueryContext = { rawSort?: SQL; sort: Sort }\n\ntype Args = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n context: QueryContext\n fields: FlattenedField[]\n joins: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized: boolean\n selectFields: Record<string, GenericColumn>\n selectLocale?: boolean\n tableName: string\n where: Where\n}\n\nexport function parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where,\n}: Args): SQL {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n if (relationOrPath) {\n const condition = where[relationOrPath]\n let conditionOperator: typeof and | typeof or\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = and\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = or\n }\n if (Array.isArray(condition)) {\n const builtConditions = buildAndOrConditions({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = conditionOperator(...builtConditions)\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (let operator of Object.keys(pathOperators)) {\n if (validOperatorSet.has(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const originalOperator = operator as Operator\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n isNestedRelationshipQuery(val) &&\n !isRawConstraint(val)\n ) {\n const relationshipPath = resolveRelationshipPath({\n adapter,\n fields,\n locale,\n parentIsLocalized,\n path: relationOrPath.replace(/__/g, '.'),\n })\n\n if (\n relationshipPath?.field.hasMany &&\n typeof relationshipPath.field.relationTo === 'string'\n ) {\n constraints.push(\n buildHasManyRelationshipCondition({\n adapter,\n aliasTable,\n fields,\n locale,\n operator: operator as HasManyRelationshipOperator,\n parentIsLocalized,\n relationOrPath,\n tableName,\n where: val,\n }),\n )\n continue\n }\n\n // A join points to many related documents. Expanding the nested query into\n // prefixed dot-paths reuses the join's shared table alias, so every condition is\n // evaluated against the same joined row (same-document `contains` semantics).\n if (operator === 'contains' && !relationshipPath) {\n const joinField = getFieldByPath({\n fields,\n path: relationOrPath.replace(/__/g, '.'),\n })?.field\n\n if (joinField?.type === 'join') {\n constraints.push(\n parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where: prefixJoinContainsWhere({\n prefix: relationOrPath,\n where: val,\n }),\n }),\n )\n continue\n }\n }\n }\n\n const {\n columnName,\n columns,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n parentIsLocalized,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n selectLocale,\n tableName,\n value: val,\n })\n\n const resolvedColumn =\n rawColumn ||\n (aliasTable && tableName === getNameFromDrizzleTable(table)\n ? aliasTable[columnName]\n : table[columnName])\n\n if (val === DistinctSymbol) {\n selectFields['_selected'] = resolvedColumn\n break\n }\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(adapter.operators.like(constraintTable[col], value))\n } else {\n constraints.push(adapter.operators.equals(constraintTable[col], value))\n }\n })\n\n if (\n (['json', 'richText'].includes(field.type) ||\n (field.type === 'blocks' && adapter.blocksAsJSON)) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n if (adapter.name === 'postgres') {\n const constraint = adapter.createJSONQuery({\n column: rawColumn || table[columnName],\n operator,\n pathSegments,\n value: val,\n })\n\n constraints.push(sql.raw(constraint))\n break\n }\n\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n // use the table name from the nearest join to handle blocks, arrays, etc. or use the tableName arg\n const jsonTable =\n joins.length === 0\n ? tableName\n : joins[joins.length - 1].table[\n Object.getOwnPropertySymbols(joins[joins.length - 1].table)[0]\n ]\n const jsonQuery = adapter.createJSONQuery({\n operator,\n pathSegments: segments,\n table: jsonTable,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = adapter.convertPathToJSONTraversal(pathSegments)\n const operatorKeys: Record<string, { operator: string; wildcard: string }> = {\n contains: { operator: 'like', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null', wildcard: '' },\n in: { operator: 'in', wildcard: '' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n not_in: { operator: 'not in', wildcard: '' },\n not_like: { operator: 'not like', wildcard: '%' },\n }\n\n let formattedValue = val\n if (\n adapter.name === 'sqlite' &&\n operator === 'equals' &&\n (typeof val === 'number' || typeof val === 'boolean')\n ) {\n formattedValue = val\n } else if (['in', 'not_in'].includes(operator) && Array.isArray(val)) {\n formattedValue = `(${val\n .map((v) => {\n const escaped = escapeSQLValue(v)\n return typeof v === 'string' ? `'${escaped}'` : String(escaped)\n })\n .join(',')})`\n } else {\n formattedValue = `'${operatorKeys[operator].wildcard}${escapeSQLValue(val)}${operatorKeys[operator].wildcard}'`\n }\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n let jsonQuerySelector = `${table[columnName].name}${jsonQuery}`\n\n if (adapter.name === 'sqlite' && operator === 'not_like') {\n jsonQuerySelector = `COALESCE(${table[columnName].name}${jsonQuery}, '')`\n }\n\n const rawSQLQuery = `${jsonQuerySelector} ${operatorKeys[operator].operator} ${formattedValue}`\n\n constraints.push(sql.raw(rawSQLQuery))\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' ||\n field.type === 'relationship' ||\n field.type === 'upload' ||\n table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(\n ...val.split(' ').map((word) =>\n buildOperatorConstraint({\n adapter,\n column: table[columnName],\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: 'like',\n value: `%${word}%`,\n }),\n ),\n ),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n columns,\n field,\n isUUID: table?.[columnName] instanceof PgUUID,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const {\n columns: queryColumns,\n operator: queryOperator,\n value: queryValue,\n } = sanitizedQueryValue\n\n // Handle polymorphic relationships by value\n if (queryColumns) {\n if (!queryColumns.length) {\n break\n }\n\n let wrapOperator = or\n\n if (queryValue === null && ['equals', 'not_equals'].includes(operator)) {\n if (operator === 'equals') {\n wrapOperator = and\n }\n\n constraints.push(\n wrapOperator(\n ...queryColumns.map(({ rawColumn }) =>\n operator === 'equals' ? isNull(rawColumn) : isNotNull(rawColumn),\n ),\n ),\n )\n break\n }\n\n if (['not_equals', 'not_in'].includes(operator)) {\n wrapOperator = and\n }\n\n constraints.push(\n wrapOperator(\n ...queryColumns.map(({ rawColumn, value }) =>\n buildOperatorConstraint({\n adapter,\n column: rawColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value,\n }),\n ),\n ),\n )\n\n break\n }\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(resolvedColumn),\n buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: 'not_equals',\n value: queryValue,\n }),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n queryOperator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(resolvedColumn))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(resolvedColumn))\n break\n }\n\n if (field.type === 'point' && adapter.name === 'postgres') {\n switch (operator) {\n case 'intersects': {\n constraints.push(\n sql`ST_Intersects(${table[columnName]}, ST_GeomFromGeoJSON(${JSON.stringify(queryValue)}))`,\n )\n break\n }\n\n case 'near': {\n const [lng, lat, maxDistance, minDistance] = queryValue as number[]\n const geoConstraints: SQL[] = []\n\n if (typeof maxDistance === 'number' && !Number.isNaN(maxDistance)) {\n geoConstraints.push(\n sql`ST_DWithin(${table[columnName]}::geography, ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)::geography, ${maxDistance})`,\n )\n }\n\n if (typeof minDistance === 'number' && !Number.isNaN(minDistance)) {\n geoConstraints.push(\n sql`ST_Distance(${table[columnName]}::geography, ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)::geography) >= ${minDistance}`,\n )\n }\n if (geoConstraints.length) {\n context.sort = relationOrPath\n context.rawSort = sql`${table[columnName]} <-> ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)`\n constraints.push(and(...geoConstraints))\n }\n break\n }\n\n case 'within': {\n constraints.push(\n sql`ST_Within(${table[columnName]}, ST_GeomFromGeoJSON(${JSON.stringify(queryValue)}))`,\n )\n break\n }\n\n default:\n break\n }\n break\n }\n\n const orConditions: SQL<unknown>[] = []\n let resolvedQueryValue = queryValue\n if (\n operator === 'in' &&\n Array.isArray(queryValue) &&\n queryValue.some((v) => v === null)\n ) {\n orConditions.push(isNull(resolvedColumn))\n resolvedQueryValue = queryValue.filter((v) => v !== null)\n }\n\n if (\n operator === 'contains' &&\n Array.isArray(queryValue) &&\n 'hasMany' in field &&\n field.hasMany &&\n ['number', 'select', 'text'].includes(field.type)\n ) {\n // Create OR conditions for each value in the array\n orConditions.push(\n ...queryValue.map((val) =>\n buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value: val,\n }),\n ),\n )\n // Set constraint to combine all OR conditions\n const constraint = orConditions.length > 0 ? or(...orConditions) : undefined\n if (constraint) {\n constraints.push(constraint)\n }\n break\n }\n\n let constraint = buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value: resolvedQueryValue,\n })\n\n if (\n adapter.limitedBoundParameters &&\n (operator === 'in' || operator === 'not_in') &&\n relationOrPath === 'id' &&\n Array.isArray(queryValue)\n ) {\n let isInvalid = false\n for (const val of queryValue) {\n if (typeof val === 'number' || val === null) {\n continue\n }\n if (typeof val === 'string') {\n if (!isValidStringID(val)) {\n isInvalid = true\n break\n } else {\n continue\n }\n }\n isInvalid = true\n break\n }\n\n if (isInvalid) {\n throw new APIError(`Invalid ID value in ${JSON.stringify(queryValue)}`)\n }\n\n constraints.push(\n sql.raw(\n `\"${getTableName(resolvedColumn.table)}\".\"${resolvedColumn.name}\" ${operator === 'in' ? 'IN' : 'NOT IN'} (${queryValue\n .map((e) => {\n if (e === null) {\n return `NULL`\n }\n\n if (typeof e === 'number') {\n return e\n }\n\n return `'${e}'`\n })\n .join(',')})`,\n ),\n )\n break\n }\n\n if (orConditions.length) {\n orConditions.push(constraint)\n constraint = or(...orConditions)\n }\n constraints.push(constraint)\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n\n/**\n * Prefixes every field path in a join's nested `contains` query with the join field's path, so the\n * query can be resolved through the join's shared table alias.\n *\n * @example\n * ```ts\n * prefixJoinContainsWhere({ prefix: 'comments', where: { and: [{ text: { equals: 'hi' } }] } })\n * // => { and: [{ 'comments.text': { equals: 'hi' } }] }\n * ```\n */\nfunction prefixJoinContainsWhere({ prefix, where }: { prefix: string; where: Where }): Where {\n const prefixedWhere: Where = {}\n\n for (const [key, value] of Object.entries(where)) {\n if (['and', 'or'].includes(key.toLowerCase()) && Array.isArray(value)) {\n prefixedWhere[key] = value.map((nestedWhere) =>\n prefixJoinContainsWhere({ prefix, where: nestedWhere }),\n )\n } else {\n prefixedWhere[`${prefix}.${key}`] = value\n }\n }\n\n return prefixedWhere\n}\n\n/**\n * Builds a SQL condition for an operator containing a nested has-many relationship query.\n *\n * `contains`: at least one related document matches.\n * `not_equals`: no related documents match.\n * `equals`: all related documents match; an empty relationship also matches.\n *\n * A normal dotted relationship query adds joins to the parent query. That cannot implement\n * the negative cases, because they must inspect all relationship rows before deciding whether to\n * include the parent. A correlated `EXISTS` subquery keeps that decision scoped to one parent.\n *\n * @example\n * ```ts\n * // Find burgers with no unhealthy ingredients.\n * const where = {\n * ingredients: {\n * not_equals: {\n * isHealthy: { equals: false },\n * },\n * },\n * }\n * ```\n */\nfunction buildHasManyRelationshipCondition({\n adapter,\n aliasTable,\n fields,\n locale,\n operator,\n parentIsLocalized,\n relationOrPath,\n tableName,\n where,\n}: {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n locale?: string\n operator: HasManyRelationshipOperator\n parentIsLocalized: boolean\n relationOrPath: string\n tableName: string\n where: Where\n}): SQL {\n const relationshipFieldPath = relationOrPath.replace(/__/g, '.')\n\n if (!where || typeof where !== 'object' || Array.isArray(where)) {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n const relationshipPath = resolveRelationshipPath({\n adapter,\n fields,\n locale,\n parentIsLocalized,\n path: relationshipFieldPath,\n })\n\n if (!relationshipPath) {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n const relationshipField = relationshipPath.field\n\n if (!relationshipField.hasMany || typeof relationshipField.relationTo !== 'string') {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n // Every related document matches an empty query, including when there are no related documents.\n if (operator === 'equals' && Object.keys(where).length === 0) {\n return sql`true`\n }\n\n const relationshipTableName = `${tableName}${adapter.relationshipsSuffix}`\n const relatedCollection = adapter.payload.collections[relationshipField.relationTo]\n const relatedTableName = adapter.tableNameMap.get(toSnakeCase(relatedCollection.config.slug))\n const relationshipLocale = relationshipPath.locale\n const { newAliasTable: relationshipTable } = getTableAlias({\n adapter,\n tableName: relationshipTableName,\n })\n const { newAliasTable: relatedTable } = getTableAlias({\n adapter,\n tableName: relatedTableName,\n })\n\n // Parse the nested `where` exactly like a normal query, but start from the related collection\n // and keep its joins inside the subquery.\n const nestedJoins: BuildQueryJoinAliases = []\n const relatedDocumentWhere =\n Object.keys(where).length > 0\n ? parseParams({\n adapter,\n aliasTable: relatedTable,\n context: { sort: undefined },\n fields: relatedCollection.config.flattenedFields,\n joins: nestedJoins,\n locale: relationshipLocale,\n parentIsLocalized: false,\n selectFields: {},\n tableName: relatedTableName,\n where,\n })\n : undefined\n\n // Correlate relationship rows back to the parent document currently being considered by the\n // outer query. The stored path distinguishes this field from other relationships on the parent.\n const outerTable = aliasTable ?? aliasedTable(adapter.tables[tableName], tableName)\n const relationshipRowConstraints: SQL[] = [\n eq(relationshipTable.parent, outerTable.id),\n relationshipPath.path.includes('%')\n ? like(relationshipTable.path, relationshipPath.path)\n : eq(relationshipTable.path, relationshipPath.path),\n ]\n\n if (relationshipLocale && relationshipLocale !== 'all' && relationshipPath.isLocalized) {\n relationshipRowConstraints.push(eq(relationshipTable.locale, relationshipLocale))\n }\n\n const relatedDocumentConstraints = [\n eq(relatedTable.id, relationshipTable[`${relationshipField.relationTo}ID`]),\n ]\n\n if (relatedDocumentWhere) {\n relatedDocumentConstraints.push(relatedDocumentWhere)\n }\n\n let relatedDocumentSubquery = (adapter.drizzle as any)\n .select({ id: relatedTable.id })\n .from(relatedTable)\n .$dynamic()\n\n for (const join of nestedJoins) {\n relatedDocumentSubquery = relatedDocumentSubquery[join.type ?? 'leftJoin'](\n join.table,\n join.condition,\n )\n }\n\n relatedDocumentSubquery = relatedDocumentSubquery.where(and(...relatedDocumentConstraints))\n\n const buildRelationshipRowsSubquery = (relatedDocumentCheck: SQL) =>\n (adapter.drizzle as any)\n .select({ id: relationshipTable.parent })\n .from(relationshipTable)\n .where(and(...relationshipRowConstraints, relatedDocumentCheck))\n\n switch (operator) {\n case 'contains':\n return exists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)))\n\n case 'equals':\n // All related documents match when no relationship row points to one that fails.\n return notExists(buildRelationshipRowsSubquery(notExists(relatedDocumentSubquery)))\n\n case 'not_equals':\n return notExists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)))\n }\n}\n"],"names":["aliasedTable","and","eq","exists","getTableName","isNotNull","isNull","like","notExists","notInArray","or","sql","PgUUID","APIError","getFieldByPath","QueryError","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","toSnakeCase","escapeSQLValue","getNameFromDrizzleTable","isValidStringID","DistinctSymbol","isRawConstraint","buildAndOrConditions","buildOperatorConstraint","getTableAlias","getTableColumnFromPath","resolveRelationshipPath","sanitizeQueryValue","parseParams","adapter","aliasTable","context","fields","joins","locale","parentIsLocalized","selectFields","selectLocale","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","has","val","originalOperator","relationshipPath","path","replace","field","hasMany","relationTo","push","buildHasManyRelationshipCondition","joinField","type","prefixJoinContainsWhere","prefix","columnName","columns","queryConstraints","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","split","value","resolvedColumn","forEach","col","constraintTable","indexOf","operators","equals","includes","blocksAsJSON","name","constraint","createJSONQuery","column","raw","segments","slice","unshift","jsonTable","getOwnPropertySymbols","jsonQuery","treatAsArray","treatRootAsArray","convertPathToJSONTraversal","operatorKeys","contains","wildcard","in","not_equals","not_in","not_like","formattedValue","map","v","escaped","String","join","jsonQuerySelector","rawSQLQuery","columnType","word","resolvedOperator","sanitizedQueryValue","isUUID","queryColumns","queryOperator","queryValue","wrapOperator","JSON","stringify","lng","lat","maxDistance","minDistance","geoConstraints","Number","isNaN","sort","rawSort","orConditions","resolvedQueryValue","some","filter","undefined","limitedBoundParameters","isInvalid","e","prefixedWhere","key","entries","nestedWhere","relationshipFieldPath","relationshipField","relationshipTableName","relationshipsSuffix","relatedCollection","payload","collections","relatedTableName","tableNameMap","get","config","slug","relationshipLocale","newAliasTable","relationshipTable","relatedTable","nestedJoins","relatedDocumentWhere","flattenedFields","outerTable","tables","relationshipRowConstraints","parent","id","isLocalized","relatedDocumentConstraints","relatedDocumentSubquery","drizzle","select","from","$dynamic","buildRelationshipRowsSubquery","relatedDocumentCheck"],"mappings":"AAGA,SACEA,YAAY,EACZC,GAAG,EACHC,EAAE,EACFC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,UAAU,EACVC,EAAE,EACFC,GAAG,QACE,cAAa;AACpB,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,QAAQ,EAAEC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AAC9D,SACEC,8BAA8B,EAC9BC,yBAAyB,EACzBC,gBAAgB,QACX,iBAAgB;AACvB,OAAOC,iBAAiB,gBAAe;AAMvC,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,cAAc,EAAEC,eAAe,QAAQ,gCAA+B;AAC/E,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAkB5D,OAAO,SAASC,YAAY,EAC1BC,OAAO,EACPC,UAAU,EACVC,O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AQmJ,OAAO,CACbC,MAAM,CAAC;YAAEL,IAAIT,kBAAkBQ,MAAM;QAAC,GACtCO,IAAI,CAACf,mBACL5H,KAAK,CAACzC,OAAO4K,4BAA4BW;IAE9C,OAAQhI;QACN,KAAK;YACH,OAAOrD,OAAOoL,8BAA8BpL,OAAO+K;QAErD,KAAK;YACH,iFAAiF;YACjF,OAAO1K,UAAU+K,8BAA8B/K,UAAU0K;QAE3D,KAAK;YACH,OAAO1K,UAAU+K,8BAA8BpL,OAAO+K;IAC1D;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type {\n Collection,\n FlattenedField,\n HasManyRelationshipOperator,\n Operator,\n Sort,\n Where,\n} from 'payload'\n\nimport {\n aliasedTable,\n and,\n eq,\n exists,\n getTableName,\n isNotNull,\n isNull,\n like,\n notExists,\n notInArray,\n or,\n sql,\n} from 'drizzle-orm'\nimport { PgUUID } from 'drizzle-orm/pg-core'\nimport { APIError, getFieldByPath, QueryError } from 'payload'\nimport { getNestedRelationshipReadConstraint } from 'payload/internal'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\nimport type { DrizzleResolvedOperator } from './operatorMap.js'\n\nimport { escapeSQLValue } from '../utilities/escapeSQLValue.js'\nimport { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js'\nimport { isValidStringID } from '../utilities/isValidStringID.js'\nimport { DistinctSymbol, isRawConstraint } from '../utilities/rawConstraint.js'\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildOperatorConstraint } from './buildOperatorConstraint.js'\nimport { getTableAlias } from './getTableAlias.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { resolveRelationshipPath } from './resolveRelationshipPath.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nexport type QueryContext = { rawSort?: SQL; sort: Sort }\n\ntype Args = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n context: QueryContext\n fields: FlattenedField[]\n joins: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized: boolean\n selectFields: Record<string, GenericColumn>\n selectLocale?: boolean\n tableName: string\n where: Where\n}\n\nexport function parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where,\n}: Args): SQL {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n if (relationOrPath) {\n const condition = where[relationOrPath]\n let conditionOperator: typeof and | typeof or\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = and\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = or\n }\n if (Array.isArray(condition)) {\n const builtConditions = buildAndOrConditions({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = conditionOperator(...builtConditions)\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (let operator of Object.keys(pathOperators)) {\n if (validOperatorSet.has(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const originalOperator = operator as Operator\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n isNestedRelationshipQuery(val) &&\n !isRawConstraint(val)\n ) {\n const relationshipPath = resolveRelationshipPath({\n adapter,\n fields,\n locale,\n parentIsLocalized,\n path: relationOrPath.replace(/__/g, '.'),\n })\n\n if (\n relationshipPath?.field.hasMany &&\n typeof relationshipPath.field.relationTo === 'string'\n ) {\n constraints.push(\n buildHasManyRelationshipCondition({\n adapter,\n aliasTable,\n fields,\n locale,\n operator: operator as HasManyRelationshipOperator,\n parentIsLocalized,\n relationOrPath,\n tableName,\n where: val,\n }),\n )\n continue\n }\n\n // A join points to many related documents. Expanding the nested query into\n // prefixed dot-paths reuses the join's shared table alias, so every condition is\n // evaluated against the same joined row (same-document `contains` semantics).\n if (operator === 'contains' && !relationshipPath) {\n const joinField = getFieldByPath({\n fields,\n path: relationOrPath.replace(/__/g, '.'),\n })?.field\n\n if (joinField?.type === 'join') {\n constraints.push(\n parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where: prefixJoinContainsWhere({\n prefix: relationOrPath,\n where: val,\n }),\n }),\n )\n continue\n }\n }\n }\n\n const {\n columnName,\n columns,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n parentIsLocalized,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n selectLocale,\n tableName,\n value: val,\n })\n\n const resolvedColumn =\n rawColumn ||\n (aliasTable && tableName === getNameFromDrizzleTable(table)\n ? aliasTable[columnName]\n : table[columnName])\n\n if (val === DistinctSymbol) {\n selectFields['_selected'] = resolvedColumn\n break\n }\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(adapter.operators.like(constraintTable[col], value))\n } else {\n constraints.push(adapter.operators.equals(constraintTable[col], value))\n }\n })\n\n if (\n (['json', 'richText'].includes(field.type) ||\n (field.type === 'blocks' && adapter.blocksAsJSON)) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n if (adapter.name === 'postgres') {\n const constraint = adapter.createJSONQuery({\n column: rawColumn || table[columnName],\n operator,\n pathSegments,\n value: val,\n })\n\n constraints.push(sql.raw(constraint))\n break\n }\n\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n // use the table name from the nearest join to handle blocks, arrays, etc. or use the tableName arg\n const jsonTable =\n joins.length === 0\n ? tableName\n : joins[joins.length - 1].table[\n Object.getOwnPropertySymbols(joins[joins.length - 1].table)[0]\n ]\n const jsonQuery = adapter.createJSONQuery({\n operator,\n pathSegments: segments,\n table: jsonTable,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = adapter.convertPathToJSONTraversal(pathSegments)\n const operatorKeys: Record<string, { operator: string; wildcard: string }> = {\n contains: { operator: 'like', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null', wildcard: '' },\n in: { operator: 'in', wildcard: '' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n not_in: { operator: 'not in', wildcard: '' },\n not_like: { operator: 'not like', wildcard: '%' },\n }\n\n let formattedValue = val\n if (\n adapter.name === 'sqlite' &&\n operator === 'equals' &&\n (typeof val === 'number' || typeof val === 'boolean')\n ) {\n formattedValue = val\n } else if (['in', 'not_in'].includes(operator) && Array.isArray(val)) {\n formattedValue = `(${val\n .map((v) => {\n const escaped = escapeSQLValue(v)\n return typeof v === 'string' ? `'${escaped}'` : String(escaped)\n })\n .join(',')})`\n } else {\n formattedValue = `'${operatorKeys[operator].wildcard}${escapeSQLValue(val)}${operatorKeys[operator].wildcard}'`\n }\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n let jsonQuerySelector = `${table[columnName].name}${jsonQuery}`\n\n if (adapter.name === 'sqlite' && operator === 'not_like') {\n jsonQuerySelector = `COALESCE(${table[columnName].name}${jsonQuery}, '')`\n }\n\n const rawSQLQuery = `${jsonQuerySelector} ${operatorKeys[operator].operator} ${formattedValue}`\n\n constraints.push(sql.raw(rawSQLQuery))\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' ||\n field.type === 'relationship' ||\n field.type === 'upload' ||\n table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(\n ...val.split(' ').map((word) =>\n buildOperatorConstraint({\n adapter,\n column: table[columnName],\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: 'like',\n value: `%${word}%`,\n }),\n ),\n ),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n columns,\n field,\n isUUID: table?.[columnName] instanceof PgUUID,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const {\n columns: queryColumns,\n operator: queryOperator,\n value: queryValue,\n } = sanitizedQueryValue\n\n // Handle polymorphic relationships by value\n if (queryColumns) {\n if (!queryColumns.length) {\n break\n }\n\n let wrapOperator = or\n\n if (queryValue === null && ['equals', 'not_equals'].includes(operator)) {\n if (operator === 'equals') {\n wrapOperator = and\n }\n\n constraints.push(\n wrapOperator(\n ...queryColumns.map(({ rawColumn }) =>\n operator === 'equals' ? isNull(rawColumn) : isNotNull(rawColumn),\n ),\n ),\n )\n break\n }\n\n if (['not_equals', 'not_in'].includes(operator)) {\n wrapOperator = and\n }\n\n constraints.push(\n wrapOperator(\n ...queryColumns.map(({ rawColumn, value }) =>\n buildOperatorConstraint({\n adapter,\n column: rawColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value,\n }),\n ),\n ),\n )\n\n break\n }\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(resolvedColumn),\n buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: 'not_equals',\n value: queryValue,\n }),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n queryOperator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(resolvedColumn))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(resolvedColumn))\n break\n }\n\n if (field.type === 'point' && adapter.name === 'postgres') {\n switch (operator) {\n case 'intersects': {\n constraints.push(\n sql`ST_Intersects(${table[columnName]}, ST_GeomFromGeoJSON(${JSON.stringify(queryValue)}))`,\n )\n break\n }\n\n case 'near': {\n const [lng, lat, maxDistance, minDistance] = queryValue as number[]\n const geoConstraints: SQL[] = []\n\n if (typeof maxDistance === 'number' && !Number.isNaN(maxDistance)) {\n geoConstraints.push(\n sql`ST_DWithin(${table[columnName]}::geography, ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)::geography, ${maxDistance})`,\n )\n }\n\n if (typeof minDistance === 'number' && !Number.isNaN(minDistance)) {\n geoConstraints.push(\n sql`ST_Distance(${table[columnName]}::geography, ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)::geography) >= ${minDistance}`,\n )\n }\n if (geoConstraints.length) {\n context.sort = relationOrPath\n context.rawSort = sql`${table[columnName]} <-> ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)`\n constraints.push(and(...geoConstraints))\n }\n break\n }\n\n case 'within': {\n constraints.push(\n sql`ST_Within(${table[columnName]}, ST_GeomFromGeoJSON(${JSON.stringify(queryValue)}))`,\n )\n break\n }\n\n default:\n break\n }\n break\n }\n\n const orConditions: SQL<unknown>[] = []\n let resolvedQueryValue = queryValue\n if (\n operator === 'in' &&\n Array.isArray(queryValue) &&\n queryValue.some((v) => v === null)\n ) {\n orConditions.push(isNull(resolvedColumn))\n resolvedQueryValue = queryValue.filter((v) => v !== null)\n }\n\n if (\n operator === 'contains' &&\n Array.isArray(queryValue) &&\n 'hasMany' in field &&\n field.hasMany &&\n ['number', 'select', 'text'].includes(field.type)\n ) {\n // Create OR conditions for each value in the array\n orConditions.push(\n ...queryValue.map((val) =>\n buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value: val,\n }),\n ),\n )\n // Set constraint to combine all OR conditions\n const constraint = orConditions.length > 0 ? or(...orConditions) : undefined\n if (constraint) {\n constraints.push(constraint)\n }\n break\n }\n\n let constraint = buildOperatorConstraint({\n adapter,\n column: resolvedColumn,\n field,\n locale,\n originalOperator,\n path: relationOrPath,\n resolvedOperator: queryOperator as DrizzleResolvedOperator,\n value: resolvedQueryValue,\n })\n\n if (\n adapter.limitedBoundParameters &&\n (operator === 'in' || operator === 'not_in') &&\n relationOrPath === 'id' &&\n Array.isArray(queryValue)\n ) {\n let isInvalid = false\n for (const val of queryValue) {\n if (typeof val === 'number' || val === null) {\n continue\n }\n if (typeof val === 'string') {\n if (!isValidStringID(val)) {\n isInvalid = true\n break\n } else {\n continue\n }\n }\n isInvalid = true\n break\n }\n\n if (isInvalid) {\n throw new APIError(`Invalid ID value in ${JSON.stringify(queryValue)}`)\n }\n\n constraints.push(\n sql.raw(\n `\"${getTableName(resolvedColumn.table)}\".\"${resolvedColumn.name}\" ${operator === 'in' ? 'IN' : 'NOT IN'} (${queryValue\n .map((e) => {\n if (e === null) {\n return `NULL`\n }\n\n if (typeof e === 'number') {\n return e\n }\n\n return `'${e}'`\n })\n .join(',')})`,\n ),\n )\n break\n }\n\n if (orConditions.length) {\n orConditions.push(constraint)\n constraint = or(...orConditions)\n }\n constraints.push(constraint)\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n\n/**\n * Prefixes every field path in a join's nested `contains` query with the join field's path, so the\n * query can be resolved through the join's shared table alias.\n *\n * @example\n * ```ts\n * prefixJoinContainsWhere({ prefix: 'comments', where: { and: [{ text: { equals: 'hi' } }] } })\n * // => { and: [{ 'comments.text': { equals: 'hi' } }] }\n * ```\n */\nfunction prefixJoinContainsWhere({ prefix, where }: { prefix: string; where: Where }): Where {\n const prefixedWhere: Where = {}\n\n for (const [key, value] of Object.entries(where)) {\n if (['and', 'or'].includes(key.toLowerCase()) && Array.isArray(value)) {\n prefixedWhere[key] = value.map((nestedWhere) =>\n prefixJoinContainsWhere({ prefix, where: nestedWhere }),\n )\n } else {\n prefixedWhere[`${prefix}.${key}`] = value\n }\n }\n\n return prefixedWhere\n}\n\n/**\n * Builds a SQL condition for an operator containing a nested has-many relationship query.\n *\n * `contains`: at least one related document matches.\n * `not_equals`: no related documents match.\n * `equals`: all related documents match; an empty relationship also matches.\n *\n * A normal dotted relationship query adds joins to the parent query. That cannot implement\n * the negative cases, because they must inspect all relationship rows before deciding whether to\n * include the parent. A correlated `EXISTS` subquery keeps that decision scoped to one parent.\n *\n * @example\n * ```ts\n * // Find burgers with no unhealthy ingredients.\n * const where = {\n * ingredients: {\n * not_equals: {\n * isHealthy: { equals: false },\n * },\n * },\n * }\n * ```\n */\nfunction buildHasManyRelationshipCondition({\n adapter,\n aliasTable,\n fields,\n locale,\n operator,\n parentIsLocalized,\n relationOrPath,\n tableName,\n where,\n}: {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n locale?: string\n operator: HasManyRelationshipOperator\n parentIsLocalized: boolean\n relationOrPath: string\n tableName: string\n where: Where\n}): SQL {\n const relationshipFieldPath = relationOrPath.replace(/__/g, '.')\n\n if (!where || typeof where !== 'object' || Array.isArray(where)) {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n const relationshipPath = resolveRelationshipPath({\n adapter,\n fields,\n locale,\n parentIsLocalized,\n path: relationshipFieldPath,\n })\n\n if (!relationshipPath) {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n const relationshipField = relationshipPath.field\n\n if (!relationshipField.hasMany || typeof relationshipField.relationTo !== 'string') {\n throw new QueryError([{ path: `${relationshipFieldPath}.${operator}` }])\n }\n\n // Every related document matches an empty query, including when there are no related documents.\n if (operator === 'equals' && Object.keys(where).length === 0) {\n return sql`true`\n }\n\n const relationshipTableName = `${tableName}${adapter.relationshipsSuffix}`\n const relatedCollection = adapter.payload.collections[relationshipField.relationTo]\n const relatedTableName = adapter.tableNameMap.get(toSnakeCase(relatedCollection.config.slug))\n const relationshipLocale = relationshipPath.locale\n const { newAliasTable: relationshipTable } = getTableAlias({\n adapter,\n tableName: relationshipTableName,\n })\n const { newAliasTable: relatedTable } = getTableAlias({\n adapter,\n tableName: relatedTableName,\n })\n\n // Parse the nested `where` exactly like a normal query, but start from the related collection\n // and keep its joins inside the subquery.\n const nestedJoins: BuildQueryJoinAliases = []\n const relatedDocumentWhere =\n Object.keys(where).length > 0\n ? parseParams({\n adapter,\n aliasTable: relatedTable,\n context: { sort: undefined },\n fields: relatedCollection.config.flattenedFields,\n joins: nestedJoins,\n locale: relationshipLocale,\n parentIsLocalized: false,\n selectFields: {},\n tableName: relatedTableName,\n where,\n })\n : undefined\n\n // Correlate relationship rows back to the parent document currently being considered by the\n // outer query. The stored path distinguishes this field from other relationships on the parent.\n const outerTable = aliasTable ?? aliasedTable(adapter.tables[tableName], tableName)\n const relationshipRowConstraints: SQL[] = [\n eq(relationshipTable.parent, outerTable.id),\n relationshipPath.path.includes('%')\n ? like(relationshipTable.path, relationshipPath.path)\n : eq(relationshipTable.path, relationshipPath.path),\n ]\n\n if (relationshipLocale && relationshipLocale !== 'all' && relationshipPath.isLocalized) {\n relationshipRowConstraints.push(eq(relationshipTable.locale, relationshipLocale))\n }\n\n const relatedDocumentConstraints = [\n eq(relatedTable.id, relationshipTable[`${relationshipField.relationTo}ID`]),\n ]\n\n if (relatedDocumentWhere) {\n relatedDocumentConstraints.push(relatedDocumentWhere)\n }\n\n let relatedDocumentSubquery = (adapter.drizzle as any)\n .select({ id: relatedTable.id })\n .from(relatedTable)\n .$dynamic()\n\n for (const join of nestedJoins) {\n relatedDocumentSubquery = relatedDocumentSubquery[join.type ?? 'leftJoin'](\n join.table,\n join.condition,\n )\n }\n\n relatedDocumentSubquery = relatedDocumentSubquery.where(and(...relatedDocumentConstraints))\n\n const buildRelationshipRowsSubquery = (relatedDocumentCheck: SQL) =>\n (adapter.drizzle as any)\n .select({ id: relationshipTable.parent })\n .from(relationshipTable)\n .where(and(...relationshipRowConstraints, relatedDocumentCheck))\n\n switch (operator) {\n case 'contains':\n return exists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)))\n\n case 'equals': {\n const readConstraint = getNestedRelationshipReadConstraint(where)\n\n if (readConstraint) {\n // Related documents the caller cannot read must not affect the result: only a readable\n // related document that fails the query excludes the parent.\n const readableRelatedDocumentSubquery = buildReadableRelatedDocumentSubquery({\n adapter,\n locale: relationshipLocale,\n readConstraint,\n relatedCollection,\n relatedTableName,\n relationshipTable,\n relationTo: relationshipField.relationTo,\n })\n\n return notExists(\n buildRelationshipRowsSubquery(\n and(exists(readableRelatedDocumentSubquery), notExists(relatedDocumentSubquery))!,\n ),\n )\n }\n\n // All related documents match when no relationship row points to one that fails.\n return notExists(buildRelationshipRowsSubquery(notExists(relatedDocumentSubquery)))\n }\n\n case 'not_equals':\n return notExists(buildRelationshipRowsSubquery(exists(relatedDocumentSubquery)))\n }\n}\n\n/**\n * Builds a subquery that finds the related document a relationship row points to, if the caller\n * can read it. It uses its own table alias and joins so it can sit beside the main related\n * document subquery.\n */\nfunction buildReadableRelatedDocumentSubquery({\n adapter,\n locale,\n readConstraint,\n relatedCollection,\n relatedTableName,\n relationshipTable,\n relationTo,\n}: {\n adapter: DrizzleAdapter\n locale?: string\n readConstraint: Where\n relatedCollection: Collection\n relatedTableName: string\n relationshipTable: Table\n relationTo: string\n}) {\n const { newAliasTable: readableRelatedTable } = getTableAlias({\n adapter,\n tableName: relatedTableName,\n })\n const readableJoins: BuildQueryJoinAliases = []\n const readableWhere = parseParams({\n adapter,\n aliasTable: readableRelatedTable,\n context: { sort: undefined },\n fields: relatedCollection.config.flattenedFields,\n joins: readableJoins,\n locale,\n parentIsLocalized: false,\n selectFields: {},\n tableName: relatedTableName,\n where: readConstraint,\n })\n\n let readableSubquery = (adapter.drizzle as any)\n .select({ id: readableRelatedTable.id })\n .from(readableRelatedTable)\n .$dynamic()\n\n for (const join of readableJoins) {\n readableSubquery = readableSubquery[join.type ?? 'leftJoin'](join.table, join.condition)\n }\n\n return readableSubquery.where(\n and(\n eq(readableRelatedTable.id, (relationshipTable as any)[`${relationTo}ID`]),\n ...(readableWhere ? [readableWhere] : []),\n ),\n )\n}\n"],"names":["aliasedTable","and","eq","exists","getTableName","isNotNull","isNull","like","notExists","notInArray","or","sql","PgUUID","APIError","getFieldByPath","QueryError","getNestedRelationshipReadConstraint","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","toSnakeCase","escapeSQLValue","getNameFromDrizzleTable","isValidStringID","DistinctSymbol","isRawConstraint","buildAndOrConditions","buildOperatorConstraint","getTableAlias","getTableColumnFromPath","resolveRelationshipPath","sanitizeQueryValue","parseParams","adapter","aliasTable","context","fields","joins","locale","parentIsLocalized","selectFields","selectLocale","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","has","val","originalOperator","relationshipPath","path","replace","field","hasMany","relationTo","push","buildHasManyRelationshipCondition","joinField","type","prefixJoinContainsWhere","prefix","columnName","columns","queryConstraints","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","split","value","resolvedColumn","forEach","col","constraintTable","indexOf","operators","equals","includes","blocksAsJSON","name","constraint","createJSONQuery","column","raw","segments","slice","unshift","jsonTable","getOwnPropertySymbols","jsonQuery","treatAsArray","treatRootAsArray","convertPathToJSONTraversal","operatorKeys","contains","wildcard","in","not_equals","not_in","not_like","formattedValue","map","v","escaped","String","join","jsonQuerySelector","rawSQLQuery","columnType","word","resolvedOperator","sanitizedQueryValue","isUUID","queryColumns","queryOperator","queryValue","wrapOperator","JSON","stringify","lng","lat","maxDistance","minDistance","geoConstraints","Number","isNaN","sort","rawSort","orConditions","resolvedQueryValue","some","filter","undefined","limitedBoundParameters","isInvalid","e","prefixedWhere","key","entries","nestedWhere","relationshipFieldPath","relationshipField","relationshipTableName","relationshipsSuffix","relatedCollection","payload","collections","relatedTableName","tableNameMap","get","config","slug","relationshipLocale","newAliasTable","relationshipTable","relatedTable","nestedJoins","relatedDocumentWhere","flattenedFields","outerTable","tables","relationshipRowConstraints","parent","id","isLocalized","relatedDocumentConstraints","relatedDocumentSubquery","drizzle","select","from","$dynamic","buildRelationshipRowsSubquery","relatedDocumentCheck","readConstraint","readableRelatedDocumentSubquery","buildReadableRelatedDocumentSubquery","readableRelatedTable","readableJoins","readableWhere","readableSubquery"],"mappings":"AAUA,SACEA,YAAY,EACZC,GAAG,EACHC,EAAE,EACFC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,UAAU,EACVC,EAAE,EACFC,GAAG,QACE,cAAa;AACpB,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,QAAQ,EAAEC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AAC9D,SAASC,mCAAmC,QAAQ,mBAAkB;AACtE,SACEC,8BAA8B,EAC9BC,yBAAyB,EACzBC,gBAAgB,QACX,iBAAgB;AACvB,OAAOC,iBAAiB,gBAAe;AAMvC,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,uBAAuB,QAA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b;IACA,MAAM8B,gBAAuC,EAAE;IAC/C,MAAMC,gBAAgB/J,YAAY;QAChCC;QACAC,YAAY2J;QACZ1J,SAAS;YAAEwG,MAAMM;QAAU;QAC3B7G,QAAQyH,kBAAkBM,MAAM,CAACQ,eAAe;QAChDtI,OAAOyJ;QACPxJ;QACAC,mBAAmB;QACnBC,cAAc,CAAC;QACfE,WAAWsH;QACXrH,OAAO+I;IACT;IAEA,IAAIM,mBAAmB,AAAC/J,QAAQmJ,OAAO,CACpCC,MAAM,CAAC;QAAEL,IAAIa,qBAAqBb,EAAE;IAAC,GACrCM,IAAI,CAACO,sBACLN,QAAQ;IAEX,KAAK,MAAMjE,QAAQwE,cAAe;QAChCE,mBAAmBA,gBAAgB,CAAC1E,KAAKhD,IAAI,IAAI,WAAW,CAACgD,KAAKvC,KAAK,EAAEuC,KAAKpE,SAAS;IACzF;IAEA,OAAO8I,iBAAiBrJ,KAAK,CAC3B1C,IACEC,GAAG2L,qBAAqBb,EAAE,EAAE,AAACT,iBAAyB,CAAC,GAAGrG,WAAW,EAAE,CAAC,CAAC,MACrE6H,gBAAgB;QAACA;KAAc,GAAG,EAAE;AAG9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20261125",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"@types/pg": "8.20.0",
|
|
56
56
|
"@types/to-snake-case": "1.0.0",
|
|
57
57
|
"esbuild": "0.27.1",
|
|
58
|
-
"payload": "4.0.0-canary.
|
|
58
|
+
"payload": "4.0.0-canary.20261125"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"payload": "4.0.0-canary.
|
|
61
|
+
"payload": "4.0.0-canary.20261125"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pnpm build:swc && pnpm build:types",
|