@payloadcms/drizzle 4.0.0-internal.b6f3b9a → 4.0.0-internal.b8a92d2
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/exports/postgres.d.ts +2 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +2 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.d.ts +38 -0
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinQuery.js +135 -0
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts +20 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.js +301 -0
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +37 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.js +191 -0
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -0
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +19 -191
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +35 -13
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts +2 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +12 -2
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -7
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts +2 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +14 -3
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts +2 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +12 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.d.ts +2 -1
- package/dist/migrateStatus.d.ts.map +1 -1
- package/dist/migrateStatus.js +11 -6
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/createJSONQuery/index.js +3 -3
- package/dist/postgres/createJSONQuery/index.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
- package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
- package/dist/postgres/query/postgresUnaccent.js +40 -0
- package/dist/postgres/query/postgresUnaccent.js.map +1 -0
- package/dist/postgres/types.d.ts +13 -2
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/buildOperatorConstraint.d.ts +22 -0
- package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
- package/dist/queries/buildOperatorConstraint.js +63 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.d.ts +12 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +59 -27
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +7 -3
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +262 -10
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/resolveRelationshipPath.d.ts +36 -0
- package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
- package/dist/queries/resolveRelationshipPath.js +66 -0
- package/dist/queries/resolveRelationshipPath.js.map +1 -0
- package/dist/queries/validateOperatorHandlers.d.ts +8 -0
- package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
- package/dist/queries/validateOperatorHandlers.js +30 -0
- package/dist/queries/validateOperatorHandlers.js.map +1 -0
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +4 -5
- package/dist/schema/build.js.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +3 -2
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.js +6 -5
- package/dist/sqlite/createJSONQuery/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +8 -14
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +50 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +41 -1
- package/dist/updateOne.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 +25 -5
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.js +12 -8
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +3 -0
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/parseJSONPathSegment.d.ts +9 -0
- package/dist/utilities/parseJSONPathSegment.d.ts.map +1 -0
- package/dist/utilities/parseJSONPathSegment.js +17 -0
- package/dist/utilities/parseJSONPathSegment.js.map +1 -0
- package/dist/utilities/validateIdentifierLength.d.ts +5 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -1
- package/dist/utilities/validateIdentifierLength.js +4 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -1
- package/package.json +3 -3
- package/dist/schema/buildRawSchema.spec.js +0 -230
- package/dist/schema/buildRawSchema.spec.js.map +0 -1
- package/dist/upsertRow/handleUpsertError.spec.js +0 -42
- package/dist/upsertRow/handleUpsertError.spec.js.map +0 -1
- package/dist/utilities/isValidStringID.spec.js +0 -15
- package/dist/utilities/isValidStringID.spec.js.map +0 -1
- package/dist/utilities/validateIdentifierLength.spec.js +0 -19
- package/dist/utilities/validateIdentifierLength.spec.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/query/assertOperatorHandlerExtensionsInstalled.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\nimport { APIError } from 'payload'\n\nimport type { PostgresDB } from '../../types.js'\nimport type { PostgresOperatorHandler } from '../types.js'\n\ntype Args = {\n drizzle: PostgresDB\n operatorHandlers: PostgresOperatorHandler[]\n}\n\n/**\n * Confirms every Postgres extension named in an operator handler's `requiredExtensions` is\n * installed in the connected database. Runs once per connect, after `createExtensions` has had a\n * chance to install any extension declared in the adapter's `extensions` option - an extension\n * that was installed by hand, without ever being declared there, still satisfies this check.\n */\nexport const assertOperatorHandlerExtensionsInstalled = async ({\n drizzle,\n operatorHandlers,\n}: Args): Promise<void> => {\n const requiredExtensionsByHandler = operatorHandlers.flatMap((handler) =>\n (handler.requiredExtensions ?? []).map((extensionName) => ({ extensionName, handler })),\n )\n\n if (!requiredExtensionsByHandler.length) {\n return\n }\n\n const { rows: installedExtensionRows } = await drizzle.execute<{ extname: string }>(\n sql`SELECT extname FROM pg_extension`,\n )\n const installedExtensions = new Set(installedExtensionRows.map((row) => row.extname))\n\n for (const { extensionName, handler } of requiredExtensionsByHandler) {\n if (!installedExtensions.has(extensionName)) {\n throw new APIError(\n `Operator handler \"${handler.name}\" requires the \"${extensionName}\" Postgres extension, which is not installed on this database. Add it to the adapter's \"extensions\" option, or install it manually with CREATE EXTENSION.`,\n )\n }\n }\n}\n"],"names":["sql","APIError","assertOperatorHandlerExtensionsInstalled","drizzle","operatorHandlers","requiredExtensionsByHandler","flatMap","handler","requiredExtensions","map","extensionName","length","rows","installedExtensionRows","execute","installedExtensions","Set","row","extname","has","name"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,QAAQ,QAAQ,UAAS;AAUlC;;;;;CAKC,GACD,OAAO,MAAMC,2CAA2C,OAAO,EAC7DC,OAAO,EACPC,gBAAgB,EACX;IACL,MAAMC,8BAA8BD,iBAAiBE,OAAO,CAAC,CAACC,UAC5D,AAACA,CAAAA,QAAQC,kBAAkB,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC,gBAAmB,CAAA;gBAAEA;gBAAeH;YAAQ,CAAA;IAGtF,IAAI,CAACF,4BAA4BM,MAAM,EAAE;QACvC;IACF;IAEA,MAAM,EAAEC,MAAMC,sBAAsB,EAAE,GAAG,MAAMV,QAAQW,OAAO,CAC5Dd,GAAG,CAAC,gCAAgC,CAAC;IAEvC,MAAMe,sBAAsB,IAAIC,IAAIH,uBAAuBJ,GAAG,CAAC,CAACQ,MAAQA,IAAIC,OAAO;IAEnF,KAAK,MAAM,EAAER,aAAa,EAAEH,OAAO,EAAE,IAAIF,4BAA6B;QACpE,IAAI,CAACU,oBAAoBI,GAAG,CAACT,gBAAgB;YAC3C,MAAM,IAAIT,SACR,CAAC,kBAAkB,EAAEM,QAAQa,IAAI,CAAC,gBAAgB,EAAEV,cAAc,yJAAyJ,CAAC;QAEhO;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PostgresOperatorHandler } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Makes Postgres `contains`, `like`, and `not_like` text comparisons accent-insensitive by
|
|
4
|
+
* wrapping both operands in `unaccent(...)`. Requires the `unaccent` extension to be installed in
|
|
5
|
+
* the database - list it in the adapter's `extensions` option to have Payload install it for you.
|
|
6
|
+
*
|
|
7
|
+
* Skips native `uuid` columns: a default or custom UUID/UUIDv7 `id` field is reported as a
|
|
8
|
+
* `text`-type field by Payload even though it is stored as a `uuid` column, so `fieldTypes`
|
|
9
|
+
* alone cannot exclude it. A genuine custom `text`/`varchar` `id` column is not a `PgUUID`
|
|
10
|
+
* column and still receives accent-insensitive matching.
|
|
11
|
+
*/
|
|
12
|
+
export declare const postgresUnaccent: () => PostgresOperatorHandler;
|
|
13
|
+
//# sourceMappingURL=postgresUnaccent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresUnaccent.d.ts","sourceRoot":"","sources":["../../../src/postgres/query/postgresUnaccent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAE1D;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,QAAO,uBAelC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { PgUUID } from 'drizzle-orm/pg-core';
|
|
3
|
+
/**
|
|
4
|
+
* Makes Postgres `contains`, `like`, and `not_like` text comparisons accent-insensitive by
|
|
5
|
+
* wrapping both operands in `unaccent(...)`. Requires the `unaccent` extension to be installed in
|
|
6
|
+
* the database - list it in the adapter's `extensions` option to have Payload install it for you.
|
|
7
|
+
*
|
|
8
|
+
* Skips native `uuid` columns: a default or custom UUID/UUIDv7 `id` field is reported as a
|
|
9
|
+
* `text`-type field by Payload even though it is stored as a `uuid` column, so `fieldTypes`
|
|
10
|
+
* alone cannot exclude it. A genuine custom `text`/`varchar` `id` column is not a `PgUUID`
|
|
11
|
+
* column and still receives accent-insensitive matching.
|
|
12
|
+
*/ export const postgresUnaccent = ()=>({
|
|
13
|
+
name: 'postgres-unaccent',
|
|
14
|
+
fieldTypes: [
|
|
15
|
+
'text',
|
|
16
|
+
'textarea'
|
|
17
|
+
],
|
|
18
|
+
operators: [
|
|
19
|
+
'contains',
|
|
20
|
+
'like',
|
|
21
|
+
'not_like'
|
|
22
|
+
],
|
|
23
|
+
requiredExtensions: [
|
|
24
|
+
'unaccent'
|
|
25
|
+
],
|
|
26
|
+
transformOperands: ({ column, value })=>{
|
|
27
|
+
if (column instanceof PgUUID) {
|
|
28
|
+
return {
|
|
29
|
+
column,
|
|
30
|
+
value
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
column: sql`unaccent(${column})`,
|
|
35
|
+
value: sql`unaccent(${value})`
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=postgresUnaccent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/query/postgresUnaccent.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\nimport { PgUUID } from 'drizzle-orm/pg-core'\n\nimport type { PostgresOperatorHandler } from '../types.js'\n\n/**\n * Makes Postgres `contains`, `like`, and `not_like` text comparisons accent-insensitive by\n * wrapping both operands in `unaccent(...)`. Requires the `unaccent` extension to be installed in\n * the database - list it in the adapter's `extensions` option to have Payload install it for you.\n *\n * Skips native `uuid` columns: a default or custom UUID/UUIDv7 `id` field is reported as a\n * `text`-type field by Payload even though it is stored as a `uuid` column, so `fieldTypes`\n * alone cannot exclude it. A genuine custom `text`/`varchar` `id` column is not a `PgUUID`\n * column and still receives accent-insensitive matching.\n */\nexport const postgresUnaccent = (): PostgresOperatorHandler => ({\n name: 'postgres-unaccent',\n fieldTypes: ['text', 'textarea'],\n operators: ['contains', 'like', 'not_like'],\n requiredExtensions: ['unaccent'],\n transformOperands: ({ column, value }) => {\n if (column instanceof PgUUID) {\n return { column, value }\n }\n\n return {\n column: sql`unaccent(${column})`,\n value: sql`unaccent(${value})`,\n }\n },\n})\n"],"names":["sql","PgUUID","postgresUnaccent","name","fieldTypes","operators","requiredExtensions","transformOperands","column","value"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,MAAM,QAAQ,sBAAqB;AAI5C;;;;;;;;;CASC,GACD,OAAO,MAAMC,mBAAmB,IAAgC,CAAA;QAC9DC,MAAM;QACNC,YAAY;YAAC;YAAQ;SAAW;QAChCC,WAAW;YAAC;YAAY;YAAQ;SAAW;QAC3CC,oBAAoB;YAAC;SAAW;QAChCC,mBAAmB,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAE;YACnC,IAAID,kBAAkBP,QAAQ;gBAC5B,OAAO;oBAAEO;oBAAQC;gBAAM;YACzB;YAEA,OAAO;gBACLD,QAAQR,GAAG,CAAC,SAAS,EAAEQ,OAAO,CAAC,CAAC;gBAChCC,OAAOT,GAAG,CAAC,SAAS,EAAES,MAAM,CAAC,CAAC;YAChC;QACF;IACF,CAAA,EAAE"}
|
package/dist/postgres/types.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { SQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
|
7
7
|
import type { Payload, PayloadRequest } from 'payload';
|
|
8
8
|
import type { ClientConfig, QueryResult } from 'pg';
|
|
9
9
|
import type { extendDrizzleTable, Operators } from '../index.js';
|
|
10
|
-
import type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js';
|
|
10
|
+
import type { BuildQueryJoinAliases, DrizzleAdapter, DrizzleOperatorHandler, TransactionPg } from '../types.js';
|
|
11
11
|
export type BaseExtraConfig = Record<string, (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder>;
|
|
12
12
|
export type RelationMap = Map<string, {
|
|
13
13
|
localized: boolean;
|
|
@@ -80,6 +80,16 @@ type PostgresSchemaHookArgs = {
|
|
|
80
80
|
schema: PostgresSchema;
|
|
81
81
|
};
|
|
82
82
|
export type PostgresSchemaHook = (args: PostgresSchemaHookArgs) => PostgresSchema | Promise<PostgresSchema>;
|
|
83
|
+
export type PostgresOperatorHandler = {
|
|
84
|
+
/**
|
|
85
|
+
* Postgres extensions that must be installed in the database for this handler to be usable.
|
|
86
|
+
* Checked once, against the database, when the adapter connects.
|
|
87
|
+
*/
|
|
88
|
+
requiredExtensions?: string[];
|
|
89
|
+
} & DrizzleOperatorHandler;
|
|
90
|
+
export type PostgresQueryConfig = {
|
|
91
|
+
operatorHandlers?: PostgresOperatorHandler[];
|
|
92
|
+
};
|
|
83
93
|
export type BasePostgresAdapter = {
|
|
84
94
|
afterSchemaInit: PostgresSchemaHook[];
|
|
85
95
|
beforeSchemaInit: PostgresSchemaHook[];
|
|
@@ -104,6 +114,7 @@ export type BasePostgresAdapter = {
|
|
|
104
114
|
insert: Insert;
|
|
105
115
|
localesSuffix?: string;
|
|
106
116
|
logger: DrizzleConfig['logger'];
|
|
117
|
+
operatorHandlers: PostgresOperatorHandler[];
|
|
107
118
|
operators: Operators;
|
|
108
119
|
pgSchema: Schema;
|
|
109
120
|
poolOptions?: ClientConfig;
|
|
@@ -131,7 +142,7 @@ export type BasePostgresAdapter = {
|
|
|
131
142
|
tablesFilter?: string[];
|
|
132
143
|
versionsSuffix?: string;
|
|
133
144
|
} & PostgresDrizzleAdapter;
|
|
134
|
-
export type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operators' | 'relations'>;
|
|
145
|
+
export type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operatorHandlers' | 'operators' | 'relations'>;
|
|
135
146
|
export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar';
|
|
136
147
|
export type MigrateUpArgs = {
|
|
137
148
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/postgres/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,GAAG,EACJ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,gCAAgC,EAChC,QAAQ,EACR,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,E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AAM,CAAC,CAAA;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACpC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,sBAAsB,CAAA;AAE1B,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,cAAc,EACZ,eAAe,GACf,aAAa,GACb,SAAS,GACT,cAAc,GACd,SAAS,GACT,QAAQ,GACR,kBAAkB,GAClB,WAAW,GACX,WAAW,CACd,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;AAE/D,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;;;OAUG;IACH,EAAE,EAAE,UAAU,CAAA;IACd;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;OAUG;IACH,EAAE,EAAE,UAAU,CAAA;IACd;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/types.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n Relation,\n Relations,\n SQL,\n} from 'drizzle-orm'\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumn,\n PgEnum,\n pgEnum,\n PgInsertOnConflictDoUpdateConfig,\n PgSchema,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { SQLiteColumn } from 'drizzle-orm/sqlite-core'\nimport type { Payload, PayloadRequest } from 'payload'\nimport type { ClientConfig, QueryResult } from 'pg'\n\nimport type { extendDrizzleTable, Operators } from '../index.js'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/types.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n Relation,\n Relations,\n SQL,\n} from 'drizzle-orm'\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumn,\n PgEnum,\n pgEnum,\n PgInsertOnConflictDoUpdateConfig,\n PgSchema,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { SQLiteColumn } from 'drizzle-orm/sqlite-core'\nimport type { Payload, PayloadRequest } from 'payload'\nimport type { ClientConfig, QueryResult } from 'pg'\n\nimport type { extendDrizzleTable, Operators } from '../index.js'\nimport type {\n BuildQueryJoinAliases,\n DrizzleAdapter,\n DrizzleOperatorHandler,\n TransactionPg,\n} from '../types.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type CountDistinct = (args: {\n column?: PgColumn<any> | SQLiteColumn<any>\n db: PostgresDB | TransactionPg\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: PostgresDB | TransactionPg\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: BasePostgresAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: PostgresDB | TransactionPg\n drizzle?: PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) => Promise<QueryResult<Record<string, T>>>\n\nexport type Insert = (args: {\n db: PostgresDB | TransactionPg\n onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type CreateDatabase = (args?: {\n /**\n * Name of a database, defaults to the current one\n */\n name?: string\n /**\n * Schema to create in addition to 'public'. Defaults from adapter.schemaName if exists.\n */\n schemaName?: string\n}) => Promise<boolean>\n\ntype Schema =\n | {\n enum: typeof pgEnum\n table: PgTableFn<string>\n }\n | PgSchema\n\ntype PostgresSchema = {\n enums: Record<string, GenericEnum>\n relations: Record<string, GenericRelation>\n tables: Record<string, PgTableWithColumns<any>>\n}\n\ntype PostgresSchemaHookArgs = {\n adapter: PostgresDrizzleAdapter\n extendTable: typeof extendDrizzleTable\n schema: PostgresSchema\n}\n\nexport type PostgresSchemaHook = (\n args: PostgresSchemaHookArgs,\n) => PostgresSchema | Promise<PostgresSchema>\n\nexport type PostgresOperatorHandler = {\n /**\n * Postgres extensions that must be installed in the database for this handler to be usable.\n * Checked once, against the database, when the adapter connects.\n */\n requiredExtensions?: string[]\n} & DrizzleOperatorHandler\n\nexport type PostgresQueryConfig = {\n operatorHandlers?: PostgresOperatorHandler[]\n}\n\nexport type BasePostgresAdapter = {\n afterSchemaInit: PostgresSchemaHook[]\n beforeSchemaInit: PostgresSchemaHook[]\n countDistinct: CountDistinct\n createDatabase: CreateDatabase\n createExtensions: () => Promise<void>\n defaultDrizzleSnapshot: DrizzleSnapshotJSON\n deleteWhere: DeleteWhere\n disableCreateDatabase: boolean\n drizzle: PostgresDB\n dropDatabase: DropDatabase\n enums: Record<string, GenericEnum>\n execute: Execute<unknown>\n extensions: Record<string, boolean>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: 'serial' | 'uuid' | 'uuidv7'\n initializing: Promise<void>\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operatorHandlers: PostgresOperatorHandler[]\n operators: Operators\n pgSchema: Schema\n poolOptions?: ClientConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n readReplicaOptions?: string[]\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schemaName?: string\n sessions: {\n [id: string]: {\n db: PostgresDB | TransactionPg\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable>\n tablesFilter?: string[]\n versionsSuffix?: string\n} & PostgresDrizzleAdapter\n\nexport type PostgresDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'insert'\n | 'operatorHandlers'\n | 'operators'\n | 'relations'\n>\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type MigrateUpArgs = {\n /**\n * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: PostgresDB\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n\nexport type MigrateDownArgs = {\n /**\n * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: PostgresDB\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-postgres'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n"],"names":[],"mappings":"AAuPA,WA8BC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Column, SQL } from 'drizzle-orm';
|
|
2
|
+
import type { FlattenedField, Operator } from 'payload';
|
|
3
|
+
import type { DrizzleAdapter } from '../types.js';
|
|
4
|
+
import type { DrizzleResolvedOperator } from './operatorMap.js';
|
|
5
|
+
type Args = {
|
|
6
|
+
adapter: DrizzleAdapter;
|
|
7
|
+
column: Column | SQL;
|
|
8
|
+
field: FlattenedField;
|
|
9
|
+
locale?: string;
|
|
10
|
+
originalOperator: Operator;
|
|
11
|
+
path: string;
|
|
12
|
+
resolvedOperator: DrizzleResolvedOperator;
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Builds the final, user-facing SQL comparison for one query leaf: applies every matching
|
|
17
|
+
* operand-transform handler in configuration order, then either calls the single matching
|
|
18
|
+
* replacement handler or falls back to `adapter.operators[resolvedOperator]`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const buildOperatorConstraint: (args: Args) => SQL;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=buildOperatorConstraint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildOperatorConstraint.d.ts","sourceRoot":"","sources":["../../src/queries/buildOperatorConstraint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE/D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;IACpB,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,QAAQ,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,uBAAuB,CAAA;IACzC,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAsBD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,SAAU,IAAI,KAAG,GAuDpD,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
const isTransformHandler = (handler)=>typeof handler.transformOperands === 'function';
|
|
3
|
+
const isReplacementHandler = (handler)=>typeof handler.build === 'function';
|
|
4
|
+
const handlerMatches = (handler, args)=>{
|
|
5
|
+
if (!handler.operators.includes(args.resolvedOperator)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (handler.fieldTypes && !handler.fieldTypes.includes(args.field.type)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Builds the final, user-facing SQL comparison for one query leaf: applies every matching
|
|
15
|
+
* operand-transform handler in configuration order, then either calls the single matching
|
|
16
|
+
* replacement handler or falls back to `adapter.operators[resolvedOperator]`.
|
|
17
|
+
*/ export const buildOperatorConstraint = (args)=>{
|
|
18
|
+
const { adapter, field, locale, originalOperator, path, resolvedOperator } = args;
|
|
19
|
+
const matchingHandlers = (adapter.operatorHandlers ?? []).filter((handler)=>handlerMatches(handler, args));
|
|
20
|
+
const context = {
|
|
21
|
+
adapter,
|
|
22
|
+
column: args.column,
|
|
23
|
+
field,
|
|
24
|
+
locale,
|
|
25
|
+
originalOperator,
|
|
26
|
+
path,
|
|
27
|
+
resolvedOperator,
|
|
28
|
+
storage: 'column',
|
|
29
|
+
value: args.value
|
|
30
|
+
};
|
|
31
|
+
for (const handler of matchingHandlers.filter(isTransformHandler)){
|
|
32
|
+
let result;
|
|
33
|
+
try {
|
|
34
|
+
result = handler.transformOperands({
|
|
35
|
+
...context
|
|
36
|
+
});
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Operator handler "${handler.name}" threw while transforming operands for the "${resolvedOperator}" operator at path "${path}".`, {
|
|
39
|
+
cause: error
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!result || typeof result !== 'object' || !('column' in result) || !('value' in result)) {
|
|
43
|
+
throw new APIError(`Operator handler "${handler.name}" returned an invalid operand transform for the "${resolvedOperator}" operator at path "${path}". Expected an object with "column" and "value" properties.`);
|
|
44
|
+
}
|
|
45
|
+
context.column = result.column;
|
|
46
|
+
context.value = result.value;
|
|
47
|
+
}
|
|
48
|
+
const replacementHandler = matchingHandlers.find(isReplacementHandler);
|
|
49
|
+
if (replacementHandler) {
|
|
50
|
+
try {
|
|
51
|
+
return replacementHandler.build({
|
|
52
|
+
...context
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(`Operator handler "${replacementHandler.name}" threw while building the "${resolvedOperator}" comparison at path "${path}".`, {
|
|
56
|
+
cause: error
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return adapter.operators[resolvedOperator](context.column, context.value);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=buildOperatorConstraint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildOperatorConstraint.ts"],"sourcesContent":["import type { Column, SQL } from 'drizzle-orm'\nimport type { FlattenedField, Operator } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type {\n DrizzleAdapter,\n DrizzleOperandTransformHandler,\n DrizzleOperatorHandler,\n DrizzleOperatorHandlerContext,\n DrizzleOperatorReplacementHandler,\n} from '../types.js'\nimport type { DrizzleResolvedOperator } from './operatorMap.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n column: Column | SQL\n field: FlattenedField\n locale?: string\n originalOperator: Operator\n path: string\n resolvedOperator: DrizzleResolvedOperator\n value: unknown\n}\n\nconst isTransformHandler = (\n handler: DrizzleOperatorHandler,\n): handler is DrizzleOperandTransformHandler => typeof handler.transformOperands === 'function'\n\nconst isReplacementHandler = (\n handler: DrizzleOperatorHandler,\n): handler is DrizzleOperatorReplacementHandler => typeof handler.build === 'function'\n\nconst handlerMatches = (handler: DrizzleOperatorHandler, args: Args): boolean => {\n if (!handler.operators.includes(args.resolvedOperator)) {\n return false\n }\n\n if (handler.fieldTypes && !handler.fieldTypes.includes(args.field.type)) {\n return false\n }\n\n return true\n}\n\n/**\n * Builds the final, user-facing SQL comparison for one query leaf: applies every matching\n * operand-transform handler in configuration order, then either calls the single matching\n * replacement handler or falls back to `adapter.operators[resolvedOperator]`.\n */\nexport const buildOperatorConstraint = (args: Args): SQL => {\n const { adapter, field, locale, originalOperator, path, resolvedOperator } = args\n\n const matchingHandlers = (adapter.operatorHandlers ?? []).filter((handler) =>\n handlerMatches(handler, args),\n )\n\n const context: DrizzleOperatorHandlerContext = {\n adapter,\n column: args.column,\n field,\n locale,\n originalOperator,\n path,\n resolvedOperator,\n storage: 'column',\n value: args.value,\n }\n\n for (const handler of matchingHandlers.filter(isTransformHandler)) {\n let result: { column: Column | SQL; value: unknown }\n\n try {\n result = handler.transformOperands({ ...context })\n } catch (error) {\n throw new Error(\n `Operator handler \"${handler.name}\" threw while transforming operands for the \"${resolvedOperator}\" operator at path \"${path}\".`,\n { cause: error },\n )\n }\n\n if (!result || typeof result !== 'object' || !('column' in result) || !('value' in result)) {\n throw new APIError(\n `Operator handler \"${handler.name}\" returned an invalid operand transform for the \"${resolvedOperator}\" operator at path \"${path}\". Expected an object with \"column\" and \"value\" properties.`,\n )\n }\n\n context.column = result.column\n context.value = result.value\n }\n\n const replacementHandler = matchingHandlers.find(isReplacementHandler)\n\n if (replacementHandler) {\n try {\n return replacementHandler.build({ ...context })\n } catch (error) {\n throw new Error(\n `Operator handler \"${replacementHandler.name}\" threw while building the \"${resolvedOperator}\" comparison at path \"${path}\".`,\n { cause: error },\n )\n }\n }\n\n return adapter.operators[resolvedOperator](context.column, context.value)\n}\n"],"names":["APIError","isTransformHandler","handler","transformOperands","isReplacementHandler","build","handlerMatches","args","operators","includes","resolvedOperator","fieldTypes","field","type","buildOperatorConstraint","adapter","locale","originalOperator","path","matchingHandlers","operatorHandlers","filter","context","column","storage","value","result","error","Error","name","cause","replacementHandler","find"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAsBlC,MAAMC,qBAAqB,CACzBC,UAC8C,OAAOA,QAAQC,iBAAiB,KAAK;AAErF,MAAMC,uBAAuB,CAC3BF,UACiD,OAAOA,QAAQG,KAAK,KAAK;AAE5E,MAAMC,iBAAiB,CAACJ,SAAiCK;IACvD,IAAI,CAACL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G,OAAOH,MAAM;QAC9BD,QAAQG,KAAK,GAAGC,OAAOD,KAAK;IAC9B;IAEA,MAAMM,qBAAqBZ,iBAAiBa,IAAI,CAAC5B;IAEjD,IAAI2B,oBAAoB;QACtB,IAAI;YACF,OAAOA,mBAAmB1B,KAAK,CAAC;gBAAE,GAAGiB,OAAO;YAAC;QAC/C,EAAE,OAAOK,OAAO;YACd,MAAM,IAAIC,MACR,CAAC,kBAAkB,EAAEG,mBAAmBF,IAAI,CAAC,4BAA4B,EAAEnB,iBAAiB,sBAAsB,EAAEQ,KAAK,EAAE,CAAC,EAC5H;gBAAEY,OAAOH;YAAM;QAEnB;IACF;IAEA,OAAOZ,QAAQP,SAAS,CAACE,iBAAiB,CAACY,QAAQC,MAAM,EAAED,QAAQG,KAAK;AAC1E,EAAC"}
|
|
@@ -24,6 +24,7 @@ type TableColumn = {
|
|
|
24
24
|
};
|
|
25
25
|
type Args = {
|
|
26
26
|
adapter: DrizzleAdapter;
|
|
27
|
+
/** The current table when a query is being built with an alias, such as inside a subquery. */
|
|
27
28
|
aliasTable?: PgTableWithColumns<any> | SQLiteTableWithColumns<any>;
|
|
28
29
|
collectionPath: string;
|
|
29
30
|
columnPrefix?: string;
|
|
@@ -32,6 +33,7 @@ type Args = {
|
|
|
32
33
|
fields: FlattenedField[];
|
|
33
34
|
joins: BuildQueryJoinAliases;
|
|
34
35
|
locale?: string;
|
|
36
|
+
/** The aliased table that owns a field nested inside an array or block. */
|
|
35
37
|
parentAliasTable?: PgTableWithColumns<any> | SQLiteTableWithColumns<any>;
|
|
36
38
|
parentIsLocalized: boolean;
|
|
37
39
|
pathSegments: string[];
|
|
@@ -49,9 +51,16 @@ type Args = {
|
|
|
49
51
|
value: unknown;
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
54
|
+
* Resolves a field path to the database table and column that store its value.
|
|
55
|
+
*
|
|
56
|
+
* While walking through relationships, arrays, and blocks, the function adds the joins required
|
|
57
|
+
* to reach the final column. Table aliases are used when the path is resolved inside a subquery.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* Resolving `movies.name` adds joins from the parent collection to its relationship table and then
|
|
61
|
+
* to the `movies` table. The returned column is `movies.name`.
|
|
62
|
+
*
|
|
63
|
+
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
55
64
|
*/
|
|
56
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;
|
|
57
66
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,
|
|
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,EAIf,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAM7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAW5D,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAC5D,KAAK,EAAE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,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"}
|
|
@@ -10,14 +10,23 @@ import { DistinctSymbol } from '../utilities/rawConstraint.js';
|
|
|
10
10
|
import { resolveBlockTableName } from '../utilities/validateExistingBlockIsIdentical.js';
|
|
11
11
|
import { addJoinTable } from './addJoinTable.js';
|
|
12
12
|
import { getTableAlias } from './getTableAlias.js';
|
|
13
|
+
import { appendFieldToStoragePath, resolveRelationshipPath } from './resolveRelationshipPath.js';
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Resolves a field path to the database table and column that store its value.
|
|
16
|
+
*
|
|
17
|
+
* While walking through relationships, arrays, and blocks, the function adds the joins required
|
|
18
|
+
* to reach the final column. Table aliases are used when the path is resolved inside a subquery.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* Resolving `movies.name` adds joins from the parent collection to its relationship table and then
|
|
22
|
+
* to the `movies` table. The returned column is `movies.name`.
|
|
23
|
+
*
|
|
24
|
+
* @returns The final field and column, plus any extra constraints discovered while resolving it.
|
|
17
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 })=>{
|
|
18
26
|
const fieldPath = incomingSegments[0];
|
|
19
27
|
let locale = incomingLocale;
|
|
20
28
|
const rootTableName = incomingRootTableName || tableName;
|
|
29
|
+
const tableContainingField = parentAliasTable ?? aliasTable ?? adapter.tables[rootTableName];
|
|
21
30
|
let constraintPath = incomingConstraintPath || '';
|
|
22
31
|
const field = fields.find((fieldToFind)=>fieldToFind.name === fieldPath);
|
|
23
32
|
let newTableName = tableName;
|
|
@@ -38,6 +47,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
38
47
|
const pathSegments = [
|
|
39
48
|
...incomingSegments
|
|
40
49
|
];
|
|
50
|
+
const fieldStoragePath = appendFieldToStoragePath({
|
|
51
|
+
field,
|
|
52
|
+
path: constraintPath
|
|
53
|
+
});
|
|
41
54
|
const isFieldLocalized = fieldShouldBeLocalized({
|
|
42
55
|
field,
|
|
43
56
|
parentIsLocalized
|
|
@@ -57,7 +70,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
57
70
|
{
|
|
58
71
|
newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
|
|
59
72
|
const arrayParentTable = aliasTable || adapter.tables[tableName];
|
|
60
|
-
constraintPath = `${
|
|
73
|
+
constraintPath = `${fieldStoragePath}.`;
|
|
61
74
|
if (locale && isFieldLocalized && adapter.payload.config.localization) {
|
|
62
75
|
const conditions = [
|
|
63
76
|
eq(arrayParentTable.id, adapter.tables[newTableName]._parentID)
|
|
@@ -140,7 +153,6 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
140
153
|
const hasBlockField = field.blocks.some((_block)=>{
|
|
141
154
|
const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block;
|
|
142
155
|
newTableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`));
|
|
143
|
-
constraintPath = `${constraintPath}${field.name}.%.`;
|
|
144
156
|
let result;
|
|
145
157
|
const blockConstraints = [];
|
|
146
158
|
const blockSelectFields = {};
|
|
@@ -170,7 +182,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
170
182
|
result = getTableColumnFromPath({
|
|
171
183
|
adapter,
|
|
172
184
|
collectionPath,
|
|
173
|
-
constraintPath
|
|
185
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
174
186
|
constraints: blockConstraints,
|
|
175
187
|
fields: block.flattenedFields,
|
|
176
188
|
joins: newJoins,
|
|
@@ -236,7 +248,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
236
248
|
aliasTable,
|
|
237
249
|
collectionPath,
|
|
238
250
|
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
239
|
-
constraintPath: `${
|
|
251
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
240
252
|
constraints,
|
|
241
253
|
fields: field.flattenedFields,
|
|
242
254
|
joins,
|
|
@@ -257,6 +269,15 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
257
269
|
throw new APIError('Not supported');
|
|
258
270
|
}
|
|
259
271
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
272
|
+
// Filtering through a polymorphic `on` relationship is not supported: it is stored in the
|
|
273
|
+
// `_rels` table with no direct column to correlate on, which would otherwise build invalid SQL.
|
|
274
|
+
const onRelationshipField = getFieldByPath({
|
|
275
|
+
fields: adapter.payload.collections[field.collection].config.flattenedFields,
|
|
276
|
+
path: field.on
|
|
277
|
+
})?.field;
|
|
278
|
+
if (onRelationshipField && (onRelationshipField.type === 'relationship' || onRelationshipField.type === 'upload') && Array.isArray(onRelationshipField.relationTo)) {
|
|
279
|
+
throw new APIError('Not supported');
|
|
280
|
+
}
|
|
260
281
|
if (field.hasMany) {
|
|
261
282
|
const relationTableName = `${adapter.tableNameMap.get(toSnakeCase(field.collection))}${adapter.relationshipsSuffix}`;
|
|
262
283
|
const existingTable = joins.find((e)=>e.queryPath === `${constraintPath}${field.name}._rels`);
|
|
@@ -273,7 +294,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
273
294
|
}
|
|
274
295
|
if (!existingTable) {
|
|
275
296
|
addJoinTable({
|
|
276
|
-
condition: and(eq(
|
|
297
|
+
condition: and(eq(tableContainingField.id, aliasRelationshipTable[`${relationshipField.field.relationTo}ID`]), like(aliasRelationshipTable.path, field.on)),
|
|
277
298
|
joins,
|
|
278
299
|
queryPath: `${constraintPath}${field.name}._rels`,
|
|
279
300
|
table: aliasRelationshipTable
|
|
@@ -311,10 +332,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
311
332
|
aliasTable: relationshipTable,
|
|
312
333
|
collectionPath: newCollectionPath,
|
|
313
334
|
constraints,
|
|
314
|
-
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
315
335
|
fields: relationshipFields,
|
|
316
336
|
joins,
|
|
317
337
|
locale,
|
|
338
|
+
// A join reads from a different collection, so localization does not carry over
|
|
318
339
|
parentIsLocalized: false,
|
|
319
340
|
pathSegments: pathSegments.slice(1),
|
|
320
341
|
rootTableName: relationshipTableName,
|
|
@@ -379,7 +400,8 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
379
400
|
fields: adapter.payload.collections[field.collection].config.flattenedFields,
|
|
380
401
|
joins,
|
|
381
402
|
locale,
|
|
382
|
-
|
|
403
|
+
// A join reads from a different collection, so localization does not carry over
|
|
404
|
+
parentIsLocalized: false,
|
|
383
405
|
pathSegments: pathSegments.slice(1),
|
|
384
406
|
selectFields,
|
|
385
407
|
tableName: newTableName,
|
|
@@ -398,14 +420,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
398
420
|
columnName = 'number';
|
|
399
421
|
}
|
|
400
422
|
newTableName = `${rootTableName}_${tableType}`;
|
|
401
|
-
const existingTable = joins.find((e)=>e.queryPath ===
|
|
423
|
+
const existingTable = joins.find((e)=>e.queryPath === fieldStoragePath);
|
|
402
424
|
const table = existingTable?.table ?? getTableAlias({
|
|
403
425
|
adapter,
|
|
404
426
|
tableName: newTableName
|
|
405
427
|
}).newAliasTable;
|
|
406
428
|
const joinConstraints = [
|
|
407
|
-
eq(
|
|
408
|
-
like(table.path,
|
|
429
|
+
eq(tableContainingField.id, table.parent),
|
|
430
|
+
like(table.path, fieldStoragePath)
|
|
409
431
|
];
|
|
410
432
|
if (locale && isFieldLocalized && adapter.payload.config.localization) {
|
|
411
433
|
const conditions = [
|
|
@@ -417,14 +439,14 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
417
439
|
addJoinTable({
|
|
418
440
|
condition: and(...conditions),
|
|
419
441
|
joins,
|
|
420
|
-
queryPath:
|
|
442
|
+
queryPath: fieldStoragePath,
|
|
421
443
|
table
|
|
422
444
|
});
|
|
423
445
|
} else {
|
|
424
446
|
addJoinTable({
|
|
425
447
|
condition: and(...joinConstraints),
|
|
426
448
|
joins,
|
|
427
|
-
queryPath:
|
|
449
|
+
queryPath: fieldStoragePath,
|
|
428
450
|
table
|
|
429
451
|
});
|
|
430
452
|
}
|
|
@@ -442,6 +464,17 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
442
464
|
{
|
|
443
465
|
const newCollectionPath = pathSegments.slice(1).join('.');
|
|
444
466
|
if (Array.isArray(field.relationTo) || field.hasMany) {
|
|
467
|
+
const relationshipPath = resolveRelationshipPath({
|
|
468
|
+
adapter,
|
|
469
|
+
fields,
|
|
470
|
+
locale,
|
|
471
|
+
parentIsLocalized,
|
|
472
|
+
path: field.name,
|
|
473
|
+
pathPrefix: constraintPath
|
|
474
|
+
});
|
|
475
|
+
if (!relationshipPath) {
|
|
476
|
+
throw new APIError(`Relationship path could not be resolved: ${collectionPath}`);
|
|
477
|
+
}
|
|
445
478
|
let relationshipFields;
|
|
446
479
|
const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
|
|
447
480
|
const existingJoin = joins.find((e)=>e.queryPath === `${constraintPath}.${field.name}`);
|
|
@@ -458,18 +491,16 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
458
491
|
aliasRelationshipTable = res.newAliasTable;
|
|
459
492
|
aliasRelationshipTableName = res.newAliasTableName;
|
|
460
493
|
}
|
|
461
|
-
if (selectLocale &&
|
|
494
|
+
if (selectLocale && relationshipPath.isLocalized && adapter.payload.config.localization) {
|
|
462
495
|
selectFields._locale = aliasRelationshipTable.locale;
|
|
463
496
|
}
|
|
464
497
|
// Join in the relationships table
|
|
465
|
-
if (locale &&
|
|
498
|
+
if (relationshipPath.locale && relationshipPath.locale !== 'all' && relationshipPath.isLocalized && adapter.payload.config.localization) {
|
|
466
499
|
const conditions = [
|
|
467
|
-
eq(
|
|
468
|
-
like(aliasRelationshipTable.path,
|
|
500
|
+
eq(tableContainingField.id, aliasRelationshipTable.parent),
|
|
501
|
+
like(aliasRelationshipTable.path, relationshipPath.path)
|
|
469
502
|
];
|
|
470
|
-
|
|
471
|
-
conditions.push(eq(aliasRelationshipTable.locale, locale));
|
|
472
|
-
}
|
|
503
|
+
conditions.push(eq(aliasRelationshipTable.locale, relationshipPath.locale));
|
|
473
504
|
addJoinTable({
|
|
474
505
|
condition: and(...conditions),
|
|
475
506
|
joins,
|
|
@@ -479,7 +510,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
479
510
|
} else {
|
|
480
511
|
// Join in the relationships table
|
|
481
512
|
addJoinTable({
|
|
482
|
-
condition: and(eq(
|
|
513
|
+
condition: and(eq(tableContainingField.id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, relationshipPath.path)),
|
|
483
514
|
joins,
|
|
484
515
|
queryPath: `${constraintPath}.${field.name}`,
|
|
485
516
|
table: aliasRelationshipTable
|
|
@@ -597,10 +628,10 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
597
628
|
aliasTable: newAliasTable,
|
|
598
629
|
collectionPath: newCollectionPath,
|
|
599
630
|
constraints,
|
|
600
|
-
// relationshipFields are fields from a different collection => no parentIsLocalized
|
|
601
631
|
fields: relationshipFields,
|
|
602
632
|
joins,
|
|
603
633
|
locale,
|
|
634
|
+
// A relationship jumps to a different collection, so localization does not carry over
|
|
604
635
|
parentIsLocalized: false,
|
|
605
636
|
pathSegments: pathSegments.slice(1),
|
|
606
637
|
rootTableName: newTableName,
|
|
@@ -623,7 +654,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
623
654
|
tableName: `${rootTableName}${adapter.localesSuffix}`
|
|
624
655
|
});
|
|
625
656
|
const condtions = [
|
|
626
|
-
eq(aliasLocaleTable._parentID,
|
|
657
|
+
eq(aliasLocaleTable._parentID, tableContainingField.id)
|
|
627
658
|
];
|
|
628
659
|
if (selectLocale) {
|
|
629
660
|
selectFields._locale = aliasLocaleTable._locale;
|
|
@@ -656,7 +687,8 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
656
687
|
fields: adapter.payload.collections[field.relationTo].config.flattenedFields,
|
|
657
688
|
joins,
|
|
658
689
|
locale,
|
|
659
|
-
|
|
690
|
+
// A relationship jumps to a different collection, so localization does not carry over
|
|
691
|
+
parentIsLocalized: false,
|
|
660
692
|
pathSegments: pathSegments.slice(1),
|
|
661
693
|
selectFields,
|
|
662
694
|
tableName: newTableName,
|
|
@@ -707,7 +739,7 @@ import { getTableAlias } from './getTableAlias.js';
|
|
|
707
739
|
aliasTable,
|
|
708
740
|
collectionPath,
|
|
709
741
|
columnPrefix: `${columnPrefix}${field.name}_`,
|
|
710
|
-
constraintPath: `${
|
|
742
|
+
constraintPath: `${fieldStoragePath}.`,
|
|
711
743
|
constraints,
|
|
712
744
|
fields: field.flattenedFields,
|
|
713
745
|
joins,
|