@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseParams } from './parseParams.js';
|
|
2
|
-
export function buildAndOrConditions({ adapter, aliasTable, context, fields, joins, locale, parentIsLocalized,
|
|
2
|
+
export function buildAndOrConditions({ adapter, aliasTable, context, fields, joins, locale, parentIsLocalized, selectFields, selectLocale, tableName, where }) {
|
|
3
3
|
const completedConditions = [];
|
|
4
4
|
// Loop over all AND / OR operations and add them to the AND / OR query param
|
|
5
5
|
// Operations should come through as an array
|
|
@@ -14,7 +14,6 @@ export function buildAndOrConditions({ adapter, aliasTable, context, fields, joi
|
|
|
14
14
|
joins,
|
|
15
15
|
locale,
|
|
16
16
|
parentIsLocalized,
|
|
17
|
-
req,
|
|
18
17
|
selectFields,
|
|
19
18
|
selectLocale,
|
|
20
19
|
tableName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type { FlattenedField,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type { FlattenedField, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\nimport type { QueryContext } from './parseParams.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport function buildAndOrConditions({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where,\n}: {\n adapter: DrizzleAdapter\n aliasTable?: Table\n collectionSlug?: string\n context: QueryContext\n fields: FlattenedField[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized: boolean\n selectFields: Record<string, GenericColumn>\n selectLocale?: boolean\n tableName: string\n where: Where[]\n}): SQL[] {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = parseParams({\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 (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","aliasTable","context","fields","joins","locale","parentIsLocalized","selectFields","selectLocale","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAOA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,SAASC,qBAAqB,EACnCC,OAAO,EACPC,UAAU,EACVC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EACZC,SAAS,EACTC,KAAK,EAeN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAASf,YAAY;gBACzBE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SQL, Table } from 'drizzle-orm';
|
|
2
|
-
import type { FlattenedField,
|
|
2
|
+
import type { FlattenedField, Sort } from 'payload';
|
|
3
3
|
import type { DrizzleAdapter, GenericColumn } from '../types.js';
|
|
4
4
|
import type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js';
|
|
5
5
|
type Args = {
|
|
@@ -10,7 +10,6 @@ type Args = {
|
|
|
10
10
|
locale?: string;
|
|
11
11
|
parentIsLocalized: boolean;
|
|
12
12
|
rawSort?: SQL;
|
|
13
|
-
req?: Partial<PayloadRequest>;
|
|
14
13
|
selectFields: Record<string, GenericColumn>;
|
|
15
14
|
sort?: Sort;
|
|
16
15
|
tableName: string;
|
|
@@ -18,6 +17,6 @@ type Args = {
|
|
|
18
17
|
/**
|
|
19
18
|
* Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary
|
|
20
19
|
*/
|
|
21
|
-
export declare const buildOrderBy: ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized, rawSort,
|
|
20
|
+
export declare const buildOrderBy: ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized, rawSort, selectFields, sort, tableName, }: Args) => BuildQueryResult['orderBy'];
|
|
22
21
|
export {};
|
|
23
22
|
//# sourceMappingURL=buildOrderBy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildOrderBy.d.ts","sourceRoot":"","sources":["../../src/queries/buildOrderBy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"buildOrderBy.d.ts","sourceRoot":"","sources":["../../src/queries/buildOrderBy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAInD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAK9E,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,+GAWtB,IAAI,KAAG,gBAAgB,CAAC,SAAS,CAgFnC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js
|
|
|
3
3
|
import { getTableColumnFromPath } from './getTableColumnFromPath.js';
|
|
4
4
|
/**
|
|
5
5
|
* Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary
|
|
6
|
-
*/ export const buildOrderBy = ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized, rawSort,
|
|
6
|
+
*/ export const buildOrderBy = ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized, rawSort, selectFields, sort, tableName })=>{
|
|
7
7
|
const orderBy = [];
|
|
8
8
|
const createdAt = adapter.tables[tableName]?.createdAt;
|
|
9
9
|
if (!sort) {
|
|
@@ -46,7 +46,6 @@ import { getTableColumnFromPath } from './getTableColumnFromPath.js';
|
|
|
46
46
|
locale,
|
|
47
47
|
parentIsLocalized,
|
|
48
48
|
pathSegments: sortProperty.replace(/__/g, '.').split('.'),
|
|
49
|
-
req,
|
|
50
49
|
selectFields,
|
|
51
50
|
tableName,
|
|
52
51
|
value: sortProperty
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildOrderBy.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type { FlattenedField,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildOrderBy.ts"],"sourcesContent":["import type { SQL, Table } from 'drizzle-orm'\nimport type { FlattenedField, Sort } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { DrizzleAdapter, GenericColumn } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryResult } from './buildQuery.js'\n\nimport { getNameFromDrizzleTable } from '../utilities/getNameFromDrizzleTable.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n joins: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized: boolean\n rawSort?: SQL\n selectFields: Record<string, GenericColumn>\n sort?: Sort\n tableName: string\n}\n\n/**\n * Gets the order by column and direction constructed from the sort argument adds the column to the select fields and joins if necessary\n */\nexport const buildOrderBy = ({\n adapter,\n aliasTable,\n fields,\n joins,\n locale,\n parentIsLocalized,\n rawSort,\n selectFields,\n sort,\n tableName,\n}: Args): BuildQueryResult['orderBy'] => {\n const orderBy: BuildQueryResult['orderBy'] = []\n\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (!sort) {\n if (createdAt) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n // In the case of Mongo, when sorting by a field that is not unique, the results are not guaranteed to be in the same order each time.\n // So we add a fallback sort to ensure that the results are always in the same order.\n let fallbackSort = '-id'\n\n if (createdAt) {\n fallbackSort = '-createdAt'\n }\n\n if (!(sort.includes(fallbackSort) || sort.includes(fallbackSort.replace('-', '')))) {\n sort.push(fallbackSort)\n }\n\n for (const sortItem of sort) {\n let sortProperty: string\n let sortDirection: 'asc' | 'desc'\n if (sortItem[0] === '-') {\n sortProperty = sortItem.substring(1)\n sortDirection = 'desc'\n } else {\n sortProperty = sortItem\n sortDirection = 'asc'\n }\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortProperty,\n fields,\n joins,\n locale,\n parentIsLocalized,\n pathSegments: sortProperty.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortProperty,\n })\n if (sortTable?.[sortTableColumnName]) {\n let order = sortDirection === 'asc' ? asc : desc\n\n if (rawSort) {\n order = () => rawSort\n }\n\n orderBy.push({\n column:\n aliasTable && tableName === getNameFromDrizzleTable(sortTable)\n ? aliasTable[sortTableColumnName]\n : sortTable[sortTableColumnName],\n order,\n })\n\n // Only add to selectFields if not already present (avoid duplicates from getTableColumnFromPath)\n const columnToAdd = sortTable[sortTableColumnName]\n const alreadyExists = Object.values(selectFields).some((col) => col === columnToAdd)\n if (!alreadyExists) {\n selectFields[sortTableColumnName] = columnToAdd\n }\n }\n } catch (_) {\n // continue\n }\n }\n\n return orderBy\n}\n"],"names":["asc","desc","getNameFromDrizzleTable","getTableColumnFromPath","buildOrderBy","adapter","aliasTable","fields","joins","locale","parentIsLocalized","rawSort","selectFields","sort","tableName","orderBy","createdAt","tables","fallbackSort","includes","replace","push","sortItem","sortProperty","sortDirection","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","split","value","order","column","columnToAdd","alreadyExists","Object","values","some","col","_"],"mappings":"AAGA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAKvC,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,sBAAsB,QAAQ,8BAA6B;AAepE;;CAEC,GACD,OAAO,MAAMC,eAAe,CAAC,EAC3BC,OAAO,EACPC,UAAU,EACVC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,iBAAiB,EACjBC,OAAO,EACPC,YAAY,EACZC,IAAI,EACJC,SAAS,EACJ;IACL,MAAMC,UAAuC,EAAE;IAE/C,MAAMC,YAAYX,QAAQY,MAAM,CA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B,IAAI,CAAC,CAACC,MAAQA,QAAQL;gBACxE,IAAI,CAACC,eAAe;oBAClBzB,YAAY,CAACe,oBAAoB,GAAGS;gBACtC;YACF;QACF,EAAE,OAAOM,GAAG;QACV,WAAW;QACb;IACF;IAEA,OAAO3B;AACT,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { asc, desc, SQL, Table } from 'drizzle-orm';
|
|
2
2
|
import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
|
-
import type { FlattenedField,
|
|
3
|
+
import type { FlattenedField, Sort, Where } from 'payload';
|
|
4
4
|
import type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js';
|
|
5
5
|
export type BuildQueryJoinAliases = {
|
|
6
6
|
condition: SQL;
|
|
@@ -16,7 +16,6 @@ type BuildQueryArgs = {
|
|
|
16
16
|
joins?: BuildQueryJoinAliases;
|
|
17
17
|
locale?: string;
|
|
18
18
|
parentIsLocalized?: boolean;
|
|
19
|
-
req?: Partial<PayloadRequest>;
|
|
20
19
|
selectLocale?: boolean;
|
|
21
20
|
sort?: Sort;
|
|
22
21
|
tableName: string;
|
|
@@ -31,6 +30,6 @@ export type BuildQueryResult = {
|
|
|
31
30
|
selectFields: Record<string, GenericColumn>;
|
|
32
31
|
where: SQL;
|
|
33
32
|
};
|
|
34
|
-
export declare const buildQuery: ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized,
|
|
33
|
+
export declare const buildQuery: ({ adapter, aliasTable, fields, joins, locale, parentIsLocalized, selectLocale, sort, tableName, where: incomingWhere, }: BuildQueryArgs) => BuildQueryResult;
|
|
35
34
|
export {};
|
|
36
35
|
//# sourceMappingURL=buildQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,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AAA;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,EAAE,CAAA;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AAED,eAAO,MAAM,UAAU,4HAWpB,cAAc,KAAG,gBA2CnB,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { buildOrderBy } from './buildOrderBy.js';
|
|
2
2
|
import { parseParams } from './parseParams.js';
|
|
3
|
-
export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joins = [], locale, parentIsLocalized,
|
|
3
|
+
export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joins = [], locale, parentIsLocalized, selectLocale, sort, tableName, where: incomingWhere }) {
|
|
4
4
|
const selectFields = {
|
|
5
|
-
id:
|
|
5
|
+
id: adapter.tables[tableName].id
|
|
6
6
|
};
|
|
7
7
|
let where;
|
|
8
8
|
const context = {
|
|
@@ -17,7 +17,6 @@ export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joi
|
|
|
17
17
|
joins,
|
|
18
18
|
locale,
|
|
19
19
|
parentIsLocalized,
|
|
20
|
-
req,
|
|
21
20
|
selectFields,
|
|
22
21
|
selectLocale,
|
|
23
22
|
tableName,
|
|
@@ -32,7 +31,6 @@ export const buildQuery = function buildQuery({ adapter, aliasTable, fields, joi
|
|
|
32
31
|
locale,
|
|
33
32
|
parentIsLocalized,
|
|
34
33
|
rawSort: context.rawSort,
|
|
35
|
-
req,
|
|
36
34
|
selectFields,
|
|
37
35
|
sort: context.sort,
|
|
38
36
|
tableName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { asc, desc, SQL, Table } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { FlattenedField,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { asc, desc, SQL, Table } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { FlattenedField, Sort, Where } from 'payload'\n\nimport type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js'\nimport type { QueryContext } from './parseParams.js'\n\nimport { buildOrderBy } from './buildOrderBy.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n // with parent\n isOneToMany?: boolean\n queryPath?: string\n table: GenericTable | PgTableWithColumns<any>\n type?: 'innerJoin' | 'leftJoin' | 'rightJoin'\n}[]\n\ntype BuildQueryArgs = {\n adapter: DrizzleAdapter\n aliasTable?: Table\n fields: FlattenedField[]\n joins?: BuildQueryJoinAliases\n locale?: string\n parentIsLocalized?: boolean\n selectLocale?: boolean\n sort?: Sort\n tableName: string\n where: Where\n}\n\nexport type BuildQueryResult = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }[]\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\n\nexport const buildQuery = function buildQuery({\n adapter,\n aliasTable,\n fields,\n joins = [],\n locale,\n parentIsLocalized,\n selectLocale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): BuildQueryResult {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n\n let where: SQL\n\n const context: QueryContext = { sort }\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = parseParams({\n adapter,\n aliasTable,\n context,\n fields,\n joins,\n locale,\n parentIsLocalized,\n selectFields,\n selectLocale,\n tableName,\n where: incomingWhere,\n })\n }\n\n const orderBy = buildOrderBy({\n adapter,\n aliasTable,\n fields,\n joins,\n locale,\n parentIsLocalized,\n rawSort: context.rawSort,\n selectFields,\n sort: context.sort,\n tableName,\n })\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n"],"names":["buildOrderBy","parseParams","buildQuery","adapter","aliasTable","fields","joins","locale","parentIsLocalized","selectLocale","sort","tableName","where","incomingWhere","selectFields","id","tables","context","Object","keys","length","orderBy","rawSort"],"mappings":"AAOA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AAkC9C,OAAO,MAAMC,aAAa,SAASA,WAAW,EAC5CC,OAAO,EACPC,UAAU,EACVC,MAAM,EACNC,QAAQ,EAAE,EACVC,MAAM,EACNC,iBAAiB,EACjBC,YAAY,EACZC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIZ,QAAQa,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IAEA,IAAIH;IAEJ,MAAMK,UAAwB;QAAEP;IAAK;IACrC,IAAIG,iBAAiBK,OAAOC,IAAI,CAACN,eAAeO,MAAM,GAAG,GAAG;QAC1DR,QAAQX,YAAY;YAClBE;YACAC;YACAa;YACAZ;YACAC;YACAC;YACAC;YACAM;YACAL;YACAE;YACAC,OAAOC;QACT;IACF;IAEA,MAAMQ,UAAUrB,aAAa;QAC3BG;QACAC;QACAC;QACAC;QACAC;QACAC;QACAc,SAASL,QAAQK,OAAO;QACxBR;QACAJ,MAAMO,QAAQP,IAAI;QAClBC;IACF;IAEA,OAAO;QACLL;QACAe;QACAP;QACAF;IACF;AACF,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SQL } from 'drizzle-orm';
|
|
2
2
|
import type { SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
|
|
3
|
-
import type { FlattenedField
|
|
3
|
+
import type { FlattenedField } from 'payload';
|
|
4
4
|
import { type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
5
5
|
import type { DrizzleAdapter, GenericColumn } from '../types.js';
|
|
6
6
|
import type { BuildQueryJoinAliases } from './buildQuery.js';
|
|
@@ -37,7 +37,6 @@ type Args = {
|
|
|
37
37
|
parentAliasTable?: PgTableWithColumns<any> | SQLiteTableWithColumns<any>;
|
|
38
38
|
parentIsLocalized: boolean;
|
|
39
39
|
pathSegments: string[];
|
|
40
|
-
req?: Partial<PayloadRequest>;
|
|
41
40
|
rootTableName?: string;
|
|
42
41
|
selectFields: Record<string, GenericColumn>;
|
|
43
42
|
selectLocale?: boolean;
|
|
@@ -63,6 +62,6 @@ type Args = {
|
|
|
63
62
|
*
|
|
64
63
|
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
65
64
|
*/
|
|
66
|
-
export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments,
|
|
65
|
+
export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix, value, }: Args) => TableColumn;
|
|
67
66
|
export {};
|
|
68
67
|
//# sourceMappingURL=getTableColumnFromPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAEV,cAAc,
|
|
1
|
+
{"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;A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AC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACxE,iBAAiB,EAAE,OAAO,CAAA;IAC1B,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AACD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,iUAmBhC,IAAI,KAAG,WAy9BT,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { and, eq, getTableName,
|
|
2
|
-
import { APIError,
|
|
1
|
+
import { and, eq, getTableName, like, sql } from 'drizzle-orm';
|
|
2
|
+
import { APIError, getFieldByPath } from 'payload';
|
|
3
3
|
import { fieldShouldBeLocalized, tabHasName } from 'payload/shared';
|
|
4
4
|
import toSnakeCase from 'to-snake-case';
|
|
5
5
|
import { validate as uuidValidate } from 'uuid';
|
|
@@ -9,77 +9,8 @@ import { jsonBuildObject } from '../utilities/json.js';
|
|
|
9
9
|
import { DistinctSymbol } from '../utilities/rawConstraint.js';
|
|
10
10
|
import { resolveBlockTableName } from '../utilities/validateExistingBlockIsIdentical.js';
|
|
11
11
|
import { addJoinTable } from './addJoinTable.js';
|
|
12
|
-
import { buildBranchVisibility } from './buildBranchVisibility.js';
|
|
13
12
|
import { getTableAlias } from './getTableAlias.js';
|
|
14
13
|
import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRelationshipPath.js';
|
|
15
|
-
const getRelationshipJoinCondition = ({ adapter, collectionSlug, relationshipID, req, table, value })=>{
|
|
16
|
-
const branchReadState = resolveBranchReadState({
|
|
17
|
-
collectionSlug,
|
|
18
|
-
req
|
|
19
|
-
});
|
|
20
|
-
const branchPredicate = branchReadState.useBranching ? null : getBranchPredicateSync({
|
|
21
|
-
collectionSlug,
|
|
22
|
-
req
|
|
23
|
-
});
|
|
24
|
-
const shouldMatchCanonicalID = Boolean(table._branchDocID && (branchReadState.useBranching || branchPredicate || value === DistinctSymbol));
|
|
25
|
-
const identityCondition = shouldMatchCanonicalID ? or(eq(table.id, relationshipID), eq(table._branchDocID, relationshipID)) : eq(table.id, relationshipID);
|
|
26
|
-
const branchCondition = getBranchTableCondition({
|
|
27
|
-
adapter,
|
|
28
|
-
collectionSlug,
|
|
29
|
-
req,
|
|
30
|
-
table
|
|
31
|
-
});
|
|
32
|
-
return branchCondition ? and(identityCondition, branchCondition) : identityCondition;
|
|
33
|
-
};
|
|
34
|
-
const getBranchTableCondition = ({ adapter, collectionSlug, req, table })=>{
|
|
35
|
-
const branchReadState = resolveBranchReadState({
|
|
36
|
-
collectionSlug,
|
|
37
|
-
req
|
|
38
|
-
});
|
|
39
|
-
if (branchReadState.useBranching) {
|
|
40
|
-
return buildBranchVisibility({
|
|
41
|
-
adapter,
|
|
42
|
-
branch: branchReadState.branch,
|
|
43
|
-
collectionSlug,
|
|
44
|
-
table
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
const branchPredicate = getBranchPredicateSync({
|
|
48
|
-
collectionSlug,
|
|
49
|
-
req
|
|
50
|
-
});
|
|
51
|
-
return branchPredicate ? buildBranchPredicateCondition({
|
|
52
|
-
table,
|
|
53
|
-
where: branchPredicate
|
|
54
|
-
}) : undefined;
|
|
55
|
-
};
|
|
56
|
-
const buildBranchPredicateCondition = ({ table, where })=>{
|
|
57
|
-
const conditions = [];
|
|
58
|
-
for (const [fieldName, condition] of Object.entries(where)){
|
|
59
|
-
if ((fieldName === 'and' || fieldName === 'or') && Array.isArray(condition)) {
|
|
60
|
-
const nestedConditions = condition.map((nestedWhere)=>buildBranchPredicateCondition({
|
|
61
|
-
table,
|
|
62
|
-
where: nestedWhere
|
|
63
|
-
})).filter((nestedCondition)=>Boolean(nestedCondition));
|
|
64
|
-
const nestedResult = fieldName === 'and' ? and(...nestedConditions) : or(...nestedConditions);
|
|
65
|
-
if (nestedResult) {
|
|
66
|
-
conditions.push(nestedResult);
|
|
67
|
-
}
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const column = table[fieldName];
|
|
71
|
-
if (!column || !condition || typeof condition !== 'object') {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if ('equals' in condition) {
|
|
75
|
-
conditions.push(condition.equals === null ? isNull(column) : eq(column, condition.equals));
|
|
76
|
-
}
|
|
77
|
-
if ('not_in' in condition && Array.isArray(condition.not_in) && condition.not_in.length > 0) {
|
|
78
|
-
conditions.push(notInArray(column, condition.not_in));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return conditions.length === 1 ? conditions[0] : and(...conditions);
|
|
82
|
-
};
|
|
83
14
|
/**
|
|
84
15
|
* Resolves a field path to the database table and column that store its value.
|
|
85
16
|
*
|
|
@@ -91,7 +22,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
91
22
|
* to the `movies` table. The returned column is `movies.name`.
|
|
92
23
|
*
|
|
93
24
|
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
94
|
-
*/ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments,
|
|
25
|
+
*/ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, parentAliasTable, parentIsLocalized, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, selectLocale, tableName, tableNameSuffix = '', value })=>{
|
|
95
26
|
const fieldPath = incomingSegments[0];
|
|
96
27
|
let locale = incomingLocale;
|
|
97
28
|
const rootTableName = incomingRootTableName || tableName;
|
|
@@ -100,7 +31,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
100
31
|
const field = fields.find((fieldToFind)=>fieldToFind.name === fieldPath);
|
|
101
32
|
let newTableName = tableName;
|
|
102
33
|
if (!field && fieldPath === 'id') {
|
|
103
|
-
|
|
34
|
+
selectFields.id = adapter.tables[newTableName].id;
|
|
104
35
|
return {
|
|
105
36
|
columnName: 'id',
|
|
106
37
|
constraints,
|
|
@@ -108,7 +39,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
108
39
|
name: 'id',
|
|
109
40
|
type: isUUIDType(adapter.idType) ? 'text' : 'number'
|
|
110
41
|
},
|
|
111
|
-
table:
|
|
42
|
+
table: adapter.tables[newTableName]
|
|
112
43
|
};
|
|
113
44
|
}
|
|
114
45
|
let localizedPathQuery = false;
|
|
@@ -175,7 +106,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
175
106
|
parentAliasTable: aliasTable,
|
|
176
107
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
177
108
|
pathSegments: pathSegments.slice(1),
|
|
178
|
-
req,
|
|
179
109
|
rootTableName,
|
|
180
110
|
selectFields,
|
|
181
111
|
selectLocale,
|
|
@@ -259,7 +189,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
259
189
|
locale,
|
|
260
190
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
261
191
|
pathSegments: pathSegments.slice(1),
|
|
262
|
-
req,
|
|
263
192
|
rootTableName,
|
|
264
193
|
selectFields: blockSelectFields,
|
|
265
194
|
selectLocale,
|
|
@@ -326,7 +255,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
326
255
|
locale,
|
|
327
256
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
328
257
|
pathSegments: pathSegments.slice(1),
|
|
329
|
-
req,
|
|
330
258
|
rootTableName,
|
|
331
259
|
selectFields,
|
|
332
260
|
selectLocale,
|
|
@@ -393,15 +321,8 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
393
321
|
tableName: relationshipTableName
|
|
394
322
|
}).newAliasTable;
|
|
395
323
|
if (!existingMainTable) {
|
|
396
|
-
const branchCondition = getBranchTableCondition({
|
|
397
|
-
adapter,
|
|
398
|
-
collectionSlug: field.collection,
|
|
399
|
-
req,
|
|
400
|
-
table: relationshipTable
|
|
401
|
-
});
|
|
402
|
-
const relationshipCondition = eq(aliasRelationshipTable.parent, relationshipTable.id);
|
|
403
324
|
joins.push({
|
|
404
|
-
condition:
|
|
325
|
+
condition: eq(aliasRelationshipTable.parent, relationshipTable.id),
|
|
405
326
|
queryPath: `${constraintPath}${field.name}`,
|
|
406
327
|
table: relationshipTable
|
|
407
328
|
});
|
|
@@ -417,7 +338,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
417
338
|
// A join reads from a different collection, so localization does not carry over
|
|
418
339
|
parentIsLocalized: false,
|
|
419
340
|
pathSegments: pathSegments.slice(1),
|
|
420
|
-
req,
|
|
421
341
|
rootTableName: relationshipTableName,
|
|
422
342
|
selectFields,
|
|
423
343
|
selectLocale,
|
|
@@ -448,29 +368,13 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
448
368
|
table: arrayAliasTable
|
|
449
369
|
});
|
|
450
370
|
joins.push({
|
|
451
|
-
condition: (
|
|
452
|
-
const relationshipCondition = eq(newAliasTable['id'], arrayAliasTable._parentID);
|
|
453
|
-
const branchCondition = getBranchTableCondition({
|
|
454
|
-
adapter,
|
|
455
|
-
collectionSlug: field.collection,
|
|
456
|
-
req,
|
|
457
|
-
table: newAliasTable
|
|
458
|
-
});
|
|
459
|
-
return branchCondition ? and(relationshipCondition, branchCondition) : relationshipCondition;
|
|
460
|
-
})(),
|
|
371
|
+
condition: eq(newAliasTable.id, arrayAliasTable._parentID),
|
|
461
372
|
queryPath: `${constraintPath}${field.name}`,
|
|
462
373
|
table: newAliasTable
|
|
463
374
|
});
|
|
464
375
|
} else {
|
|
465
|
-
const relationshipCondition = eq(newAliasTable[field.on.replaceAll('.', '_')], aliasTable ? aliasTable.id : adapter.tables[tableName].id);
|
|
466
|
-
const branchCondition = getBranchTableCondition({
|
|
467
|
-
adapter,
|
|
468
|
-
collectionSlug: field.collection,
|
|
469
|
-
req,
|
|
470
|
-
table: newAliasTable
|
|
471
|
-
});
|
|
472
376
|
joins.push({
|
|
473
|
-
condition:
|
|
377
|
+
condition: eq(newAliasTable[field.on.replaceAll('.', '_')], aliasTable ? aliasTable.id : adapter.tables[tableName].id),
|
|
474
378
|
queryPath: `${constraintPath}${field.name}`,
|
|
475
379
|
table: newAliasTable
|
|
476
380
|
});
|
|
@@ -499,7 +403,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
499
403
|
// A join reads from a different collection, so localization does not carry over
|
|
500
404
|
parentIsLocalized: false,
|
|
501
405
|
pathSegments: pathSegments.slice(1),
|
|
502
|
-
req,
|
|
503
406
|
selectFields,
|
|
504
407
|
tableName: newTableName,
|
|
505
408
|
value
|
|
@@ -560,8 +463,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
560
463
|
case 'upload':
|
|
561
464
|
{
|
|
562
465
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
563
|
-
const relationshipQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._rels`;
|
|
564
|
-
const targetQueryPath = `${getTableName(tableContainingField)}.${fieldStoragePath}._target`;
|
|
565
466
|
if (Array.isArray(field.relationTo) || field.hasMany) {
|
|
566
467
|
const relationshipPath = resolveRelationshipPath({
|
|
567
468
|
adapter,
|
|
@@ -576,7 +477,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
576
477
|
}
|
|
577
478
|
let relationshipFields;
|
|
578
479
|
const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
|
|
579
|
-
const existingJoin = joins.find((e)=>e.queryPath ===
|
|
480
|
+
const existingJoin = joins.find((e)=>e.queryPath === `${constraintPath}.${field.name}`);
|
|
580
481
|
let aliasRelationshipTable;
|
|
581
482
|
let aliasRelationshipTableName;
|
|
582
483
|
if (existingJoin) {
|
|
@@ -603,7 +504,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
603
504
|
addJoinTable({
|
|
604
505
|
condition: and(...conditions),
|
|
605
506
|
joins,
|
|
606
|
-
queryPath:
|
|
507
|
+
queryPath: `${constraintPath}.${field.name}`,
|
|
607
508
|
table: aliasRelationshipTable
|
|
608
509
|
});
|
|
609
510
|
} else {
|
|
@@ -611,7 +512,7 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
611
512
|
addJoinTable({
|
|
612
513
|
condition: and(eq(tableContainingField.id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, relationshipPath.path)),
|
|
613
514
|
joins,
|
|
614
|
-
queryPath:
|
|
515
|
+
queryPath: `${constraintPath}.${field.name}`,
|
|
615
516
|
table: aliasRelationshipTable
|
|
616
517
|
});
|
|
617
518
|
}
|
|
@@ -622,31 +523,15 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
622
523
|
newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
|
|
623
524
|
// parent to relationship join table
|
|
624
525
|
relationshipFields = relationshipConfig.flattenedFields;
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const relationshipID = aliasRelationshipTable[`${field.relationTo}ID`];
|
|
635
|
-
const condition = getRelationshipJoinCondition({
|
|
636
|
-
adapter,
|
|
637
|
-
collectionSlug: field.relationTo,
|
|
638
|
-
relationshipID,
|
|
639
|
-
req,
|
|
640
|
-
table: newAliasTable,
|
|
641
|
-
value
|
|
642
|
-
});
|
|
643
|
-
joins.push({
|
|
644
|
-
condition,
|
|
645
|
-
queryPath: targetQueryPath,
|
|
646
|
-
table: newAliasTable
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
if (newCollectionPath === '' || newCollectionPath === 'id' && !existingTargetJoin) {
|
|
526
|
+
({ newAliasTable } = getTableAlias({
|
|
527
|
+
adapter,
|
|
528
|
+
tableName: newTableName
|
|
529
|
+
}));
|
|
530
|
+
joins.push({
|
|
531
|
+
condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
|
|
532
|
+
table: newAliasTable
|
|
533
|
+
});
|
|
534
|
+
if (newCollectionPath === '' || newCollectionPath === 'id') {
|
|
650
535
|
return {
|
|
651
536
|
columnName: `${field.relationTo}ID`,
|
|
652
537
|
constraints,
|
|
@@ -749,23 +634,21 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
749
634
|
// A relationship jumps to a different collection, so localization does not carry over
|
|
750
635
|
parentIsLocalized: false,
|
|
751
636
|
pathSegments: pathSegments.slice(1),
|
|
752
|
-
req,
|
|
753
637
|
rootTableName: newTableName,
|
|
754
638
|
selectFields,
|
|
755
639
|
selectLocale,
|
|
756
640
|
tableName: newTableName,
|
|
757
641
|
value
|
|
758
642
|
});
|
|
759
|
-
} else if (pathSegments.length > 1 &&
|
|
643
|
+
} else if (pathSegments.length > 1 && !(pathSegments.length === 2 && pathSegments[1] === 'id')) {
|
|
760
644
|
// simple relationships
|
|
761
645
|
const columnName = `${columnPrefix}${field.name}`;
|
|
762
646
|
const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[field.relationTo].config.slug));
|
|
763
|
-
const
|
|
764
|
-
const newAliasTable = existingTargetJoin?.table ?? getTableAlias({
|
|
647
|
+
const { newAliasTable } = getTableAlias({
|
|
765
648
|
adapter,
|
|
766
649
|
tableName: newTableName
|
|
767
|
-
})
|
|
768
|
-
if (
|
|
650
|
+
});
|
|
651
|
+
if (isFieldLocalized && adapter.payload.config.localization) {
|
|
769
652
|
const { newAliasTable: aliasLocaleTable } = getTableAlias({
|
|
770
653
|
adapter,
|
|
771
654
|
tableName: `${rootTableName}${adapter.localesSuffix}`
|
|
@@ -785,32 +668,13 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
785
668
|
joins,
|
|
786
669
|
table: localesTable
|
|
787
670
|
});
|
|
788
|
-
const condition = getRelationshipJoinCondition({
|
|
789
|
-
adapter,
|
|
790
|
-
collectionSlug: field.relationTo,
|
|
791
|
-
relationshipID: localesTable[columnName],
|
|
792
|
-
req,
|
|
793
|
-
table: newAliasTable,
|
|
794
|
-
value
|
|
795
|
-
});
|
|
796
671
|
joins.push({
|
|
797
|
-
condition,
|
|
798
|
-
queryPath: targetQueryPath,
|
|
672
|
+
condition: eq(localesTable[columnName], newAliasTable.id),
|
|
799
673
|
table: newAliasTable
|
|
800
674
|
});
|
|
801
|
-
} else
|
|
802
|
-
const relationshipID = aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName];
|
|
803
|
-
const condition = getRelationshipJoinCondition({
|
|
804
|
-
adapter,
|
|
805
|
-
collectionSlug: field.relationTo,
|
|
806
|
-
relationshipID,
|
|
807
|
-
req,
|
|
808
|
-
table: newAliasTable,
|
|
809
|
-
value
|
|
810
|
-
});
|
|
675
|
+
} else {
|
|
811
676
|
joins.push({
|
|
812
|
-
condition,
|
|
813
|
-
queryPath: targetQueryPath,
|
|
677
|
+
condition: eq(newAliasTable.id, aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName]),
|
|
814
678
|
table: newAliasTable
|
|
815
679
|
});
|
|
816
680
|
}
|
|
@@ -826,7 +690,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
826
690
|
// A relationship jumps to a different collection, so localization does not carry over
|
|
827
691
|
parentIsLocalized: false,
|
|
828
692
|
pathSegments: pathSegments.slice(1),
|
|
829
|
-
req,
|
|
830
693
|
selectFields,
|
|
831
694
|
tableName: newTableName,
|
|
832
695
|
value
|
|
@@ -883,7 +746,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
883
746
|
locale,
|
|
884
747
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
885
748
|
pathSegments: pathSegments.slice(1),
|
|
886
|
-
req,
|
|
887
749
|
rootTableName,
|
|
888
750
|
selectFields,
|
|
889
751
|
selectLocale,
|
|
@@ -904,7 +766,6 @@ const buildBranchPredicateCondition = ({ table, where })=>{
|
|
|
904
766
|
locale,
|
|
905
767
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
906
768
|
pathSegments: pathSegments.slice(1),
|
|
907
|
-
req,
|
|
908
769
|
rootTableName,
|
|
909
770
|
selectFields,
|
|
910
771
|
selectLocale,
|