@payloadcms/db-postgres 3.0.0-canary.98cbdb9 → 3.0.0-canary.98e0119
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +25 -6
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -19
- package/dist/index.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +72 -67
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/index.js +2 -2
- package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +9 -3
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/traverseFields.js +32 -32
- package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
- package/dist/types.d.ts +31 -106
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/license.md +22 -0
- package/package.json +19 -10
- package/dist/countDistinct.d.ts +0 -3
- package/dist/countDistinct.d.ts.map +0 -1
- package/dist/countDistinct.js +0 -24
- package/dist/countDistinct.js.map +0 -1
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
- package/dist/createJSONQuery/convertPathToJSONTraversal.js +0 -14
- package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
- package/dist/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
- package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
- package/dist/createJSONQuery/formatJSONPathSegment.js +0 -5
- package/dist/createJSONQuery/formatJSONPathSegment.js.map +0 -1
- package/dist/createJSONQuery/index.d.ts +0 -10
- package/dist/createJSONQuery/index.d.ts.map +0 -1
- package/dist/createJSONQuery/index.js +0 -54
- package/dist/createJSONQuery/index.js.map +0 -1
- package/dist/createMigration.d.ts +0 -3
- package/dist/createMigration.d.ts.map +0 -1
- package/dist/createMigration.js +0 -91
- package/dist/createMigration.js.map +0 -1
- package/dist/defaultSnapshot.d.ts +0 -3
- package/dist/defaultSnapshot.d.ts.map +0 -1
- package/dist/defaultSnapshot.js +0 -17
- package/dist/defaultSnapshot.js.map +0 -1
- package/dist/deleteWhere.d.ts +0 -3
- package/dist/deleteWhere.d.ts.map +0 -1
- package/dist/deleteWhere.js +0 -6
- package/dist/deleteWhere.js.map +0 -1
- package/dist/dropDatabase.d.ts +0 -3
- package/dist/dropDatabase.d.ts.map +0 -1
- package/dist/dropDatabase.js +0 -9
- package/dist/dropDatabase.js.map +0 -1
- package/dist/execute.d.ts +0 -3
- package/dist/execute.d.ts.map +0 -1
- package/dist/execute.js +0 -11
- package/dist/execute.js.map +0 -1
- package/dist/getMigrationTemplate.d.ts +0 -4
- package/dist/getMigrationTemplate.d.ts.map +0 -1
- package/dist/getMigrationTemplate.js +0 -13
- package/dist/getMigrationTemplate.js.map +0 -1
- package/dist/init.d.ts +0 -3
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -95
- package/dist/init.js.map +0 -1
- package/dist/insert.d.ts +0 -3
- package/dist/insert.d.ts.map +0 -1
- package/dist/insert.js +0 -12
- package/dist/insert.js.map +0 -1
- package/dist/requireDrizzleKit.d.ts +0 -3
- package/dist/requireDrizzleKit.d.ts.map +0 -1
- package/dist/requireDrizzleKit.js +0 -5
- package/dist/requireDrizzleKit.js.map +0 -1
- package/dist/schema/build.d.ts +0 -38
- package/dist/schema/build.d.ts.map +0 -1
- package/dist/schema/build.js +0 -369
- package/dist/schema/build.js.map +0 -1
- package/dist/schema/createIndex.d.ts +0 -12
- package/dist/schema/createIndex.d.ts.map +0 -1
- package/dist/schema/createIndex.js +0 -18
- package/dist/schema/createIndex.js.map +0 -1
- package/dist/schema/idToUUID.d.ts +0 -3
- package/dist/schema/idToUUID.d.ts.map +0 -1
- package/dist/schema/idToUUID.js +0 -11
- package/dist/schema/idToUUID.js.map +0 -1
- package/dist/schema/parentIDColumnMap.d.ts +0 -4
- package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
- package/dist/schema/parentIDColumnMap.js +0 -9
- package/dist/schema/parentIDColumnMap.js.map +0 -1
- package/dist/schema/setColumnID.d.ts +0 -11
- package/dist/schema/setColumnID.d.ts.map +0 -1
- package/dist/schema/setColumnID.js +0 -24
- package/dist/schema/setColumnID.js.map +0 -1
- package/dist/schema/traverseFields.d.ts +0 -36
- package/dist/schema/traverseFields.d.ts.map +0 -1
- package/dist/schema/traverseFields.js +0 -613
- package/dist/schema/traverseFields.js.map +0 -1
- package/dist/schema/withDefault.d.ts +0 -4
- package/dist/schema/withDefault.d.ts.map +0 -1
- package/dist/schema/withDefault.js +0 -10
- package/dist/schema/withDefault.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,aAAa,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,
|
1
|
+
{"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,aAAa,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAwEN,CAAA"}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
2
2
|
import { fetchAndResave } from './fetchAndResave/index.js';
|
3
3
|
export const migrateRelationships = async ({ adapter, collectionSlug, db, debug, fields, globalSlug, isVersions, pathsToQuery, payload, req, tableName })=>{
|
4
|
-
if (pathsToQuery.size === 0)
|
4
|
+
if (pathsToQuery.size === 0) {
|
5
|
+
return;
|
6
|
+
}
|
5
7
|
let offset = 0;
|
6
8
|
let paginationResult;
|
7
9
|
const where = Array.from(pathsToQuery).reduce((statement, path, i)=>{
|
@@ -14,7 +16,9 @@ export const migrateRelationships = async ({ adapter, collectionSlug, db, debug,
|
|
14
16
|
${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};
|
15
17
|
`;
|
16
18
|
paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`));
|
17
|
-
if (paginationResult.rows.length === 0)
|
19
|
+
if (paginationResult.rows.length === 0) {
|
20
|
+
return;
|
21
|
+
}
|
18
22
|
offset += 1;
|
19
23
|
const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE
|
20
24
|
(${where}) AND parent_id IN (${paginationResult.rows.map((row)=>row.parent_id).join(', ')});
|
@@ -28,7 +32,9 @@ export const migrateRelationships = async ({ adapter, collectionSlug, db, debug,
|
|
28
32
|
result.rows.forEach((row)=>{
|
29
33
|
const parentID = row.parent_id;
|
30
34
|
if (typeof parentID === 'string' || typeof parentID === 'number') {
|
31
|
-
if (!docsToResave[parentID])
|
35
|
+
if (!docsToResave[parentID]) {
|
36
|
+
docsToResave[parentID] = [];
|
37
|
+
}
|
32
38
|
docsToResave[parentID].push(row);
|
33
39
|
}
|
34
40
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: TransactionPg\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequest,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,IAAIH,aAAaI,IAAI,KAAK,GAAG;
|
1
|
+
{"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: TransactionPg\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) {\n return\n }\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) {\n return\n }\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) {\n docsToResave[parentID] = []\n }\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequest,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAM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,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAET,UAAU,CAAC;QAEnE,MAAMiB,eAA6B,CAAC;QAEpCD,OAAOZ,IAAI,CAACc,OAAO,CAAC,CAACP;YACnB,MAAMQ,WAAWR,IAAIC,SAAS;YAE9B,IAAI,OAAOO,aAAa,YAAY,OAAOA,aAAa,UAAU;gBAChE,IAAI,CAACF,YAAY,CAACE,SAAS,EAAE;oBAC3BF,YAAY,CAACE,SAAS,GAAG,EAAE;gBAC7B;gBACAF,YAAY,CAACE,SAAS,CAACC,IAAI,CAACT;YAC9B;QACF;QAEA,MAAM/B,eAAe;YACnBE;YACAC;YACAC;YACAC;YACAgC;YACA/B;YACAC;YACAC;YACAE;YACAC,KAAKA;YACLC;QACF;IACF;IAEA,MAAM6B,kBAAkB,CAAC,YAAY,EAAE7B,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,OAAO,EAAEP,MAAM,CAAC;IAC/F,IAAIX,OAAO;QACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;QACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
|
@@ -3,28 +3,6 @@ import toSnakeCase from 'to-snake-case';
|
|
3
3
|
export const traverseFields = (args)=>{
|
4
4
|
args.fields.forEach((field)=>{
|
5
5
|
switch(field.type){
|
6
|
-
case 'group':
|
7
|
-
{
|
8
|
-
let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`;
|
9
|
-
if (field.localized && args.payload.config.localization) {
|
10
|
-
newTableName += args.adapter.localesSuffix;
|
11
|
-
}
|
12
|
-
return traverseFields({
|
13
|
-
...args,
|
14
|
-
columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,
|
15
|
-
fields: field.fields,
|
16
|
-
newTableName,
|
17
|
-
path: `${args.path ? `${args.path}.` : ''}${field.name}`
|
18
|
-
});
|
19
|
-
}
|
20
|
-
case 'row':
|
21
|
-
case 'collapsible':
|
22
|
-
{
|
23
|
-
return traverseFields({
|
24
|
-
...args,
|
25
|
-
fields: field.fields
|
26
|
-
});
|
27
|
-
}
|
28
6
|
case 'array':
|
29
7
|
{
|
30
8
|
const newTableName = args.adapter.tableNameMap.get(`${args.newTableName}_${toSnakeCase(field.name)}`);
|
@@ -51,6 +29,38 @@ export const traverseFields = (args)=>{
|
|
51
29
|
});
|
52
30
|
});
|
53
31
|
}
|
32
|
+
case 'collapsible':
|
33
|
+
case 'row':
|
34
|
+
{
|
35
|
+
return traverseFields({
|
36
|
+
...args,
|
37
|
+
fields: field.fields
|
38
|
+
});
|
39
|
+
}
|
40
|
+
case 'group':
|
41
|
+
{
|
42
|
+
let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`;
|
43
|
+
if (field.localized && args.payload.config.localization) {
|
44
|
+
newTableName += args.adapter.localesSuffix;
|
45
|
+
}
|
46
|
+
return traverseFields({
|
47
|
+
...args,
|
48
|
+
columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,
|
49
|
+
fields: field.fields,
|
50
|
+
newTableName,
|
51
|
+
path: `${args.path ? `${args.path}.` : ''}${field.name}`
|
52
|
+
});
|
53
|
+
}
|
54
|
+
case 'relationship':
|
55
|
+
case 'upload':
|
56
|
+
{
|
57
|
+
if (typeof field.relationTo === 'string') {
|
58
|
+
if (field.type === 'upload' || !field.hasMany) {
|
59
|
+
args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return null;
|
63
|
+
}
|
54
64
|
case 'tabs':
|
55
65
|
{
|
56
66
|
return field.tabs.forEach((tab)=>{
|
@@ -68,16 +78,6 @@ export const traverseFields = (args)=>{
|
|
68
78
|
});
|
69
79
|
});
|
70
80
|
}
|
71
|
-
case 'relationship':
|
72
|
-
case 'upload':
|
73
|
-
{
|
74
|
-
if (typeof field.relationTo === 'string') {
|
75
|
-
if (field.type === 'upload' || !field.hasMany) {
|
76
|
-
args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
return null;
|
80
|
-
}
|
81
81
|
}
|
82
82
|
});
|
83
83
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: TransactionPg\n disableNotNull: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case '
|
1
|
+
{"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: TransactionPg\n disableNotNull: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case 'array': {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.newTableName}_${toSnakeCase(field.name)}`,\n )\n\n return traverseFields({\n ...args,\n columnPrefix: '',\n fields: field.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n }\n\n case 'blocks': {\n return field.blocks.forEach((block) => {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n traverseFields({\n ...args,\n columnPrefix: '',\n fields: block.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n })\n }\n case 'collapsible':\n\n case 'row': {\n return traverseFields({\n ...args,\n fields: field.fields,\n })\n }\n\n case 'group': {\n let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`\n\n if (field.localized && args.payload.config.localization) {\n newTableName += args.adapter.localesSuffix\n }\n\n return traverseFields({\n ...args,\n columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,\n fields: field.fields,\n newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}`,\n })\n }\n\n case 'relationship':\n\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`)\n }\n }\n\n return null\n }\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n args.columnPrefix = `${args.columnPrefix}_${toSnakeCase(tab.name)}_`\n args.path = `${args.path ? `${args.path}.` : ''}${tab.name}`\n args.newTableName = `${args.newTableName}_${toSnakeCase(tab.name)}`\n\n if (tab.localized && args.payload.config.localization) {\n args.newTableName += args.adapter.localesSuffix\n }\n }\n\n traverseFields({\n ...args,\n fields: tab.fields,\n })\n })\n }\n }\n })\n}\n"],"names":["tabHasName","toSnakeCase","traverseFields","args","fields","forEach","field","type","newTableName","adapter","tableNameMap","get","name","columnPrefix","parentTableName","path","blocks","block","rootTableName","slug","localized","payload","config","localization","localesSuffix","relationTo","h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GAAG,GAAG,EAAEe,IAAIlB,IAAI,CAAC,CAAC;4BAC5DT,KAAKK,YAAY,GAAG,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAY6B,IAAIlB,IAAI,EAAE,CAAC;4BAEnE,IAAIkB,IAAIV,SAAS,IAAIjB,KAAKkB,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;gCACrDpB,KAAKK,YAAY,IAAIL,KAAKM,OAAO,CAACe,aAAa;4BACjD;wBACF;wBAEAtB,eAAe;4BACb,GAAGC,IAAI;4BACPC,QAAQ0B,IAAI1B,MAAM;wBACpB;oBACF;gBACF;QACF;IACF;AACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import type { PgColumn, PgEnum, PgInsertOnConflictDoUpdateConfig, PgSchema, PgTableWithColumns, PgTransactionConfig, pgEnum } from 'drizzle-orm/pg-core';
|
7
|
-
import type { PgTableFn } from 'drizzle-orm/pg-core/table';
|
8
|
-
import type { Payload, PayloadRequest } from 'payload';
|
9
|
-
import type { Pool, PoolConfig, QueryResult } from 'pg';
|
1
|
+
import type { BasePostgresAdapter, GenericEnum, MigrateDownArgs, MigrateUpArgs, PostgresDB, PostgresSchemaHook } from '@payloadcms/drizzle/postgres';
|
2
|
+
import type { DrizzleAdapter } from '@payloadcms/drizzle/types';
|
3
|
+
import type { DrizzleConfig } from 'drizzle-orm';
|
4
|
+
import type { PgSchema, PgTableFn, PgTransactionConfig } from 'drizzle-orm/pg-core';
|
5
|
+
import type { Pool, PoolConfig } from 'pg';
|
10
6
|
export type Args = {
|
7
|
+
/**
|
8
|
+
* Transform the schema after it's built.
|
9
|
+
* You can use it to customize the schema with features that aren't supported by Payload.
|
10
|
+
* Examples may include: composite indices, generated columns, vectors
|
11
|
+
*/
|
12
|
+
afterSchemaInit?: PostgresSchemaHook[];
|
13
|
+
/**
|
14
|
+
* Transform the schema before it's built.
|
15
|
+
* You can use it to preserve an existing database schema and if there are any collissions Payload will override them.
|
16
|
+
* To generate Drizzle schema from the database, see [Drizzle Kit introspection](https://orm.drizzle.team/kit-docs/commands#introspect--pull)
|
17
|
+
*/
|
18
|
+
beforeSchemaInit?: PostgresSchemaHook[];
|
19
|
+
/**
|
20
|
+
* Pass `true` to disale auto database creation if it doesn't exist.
|
21
|
+
* @default false
|
22
|
+
*/
|
23
|
+
disableCreateDatabase?: boolean;
|
24
|
+
extensions?: string[];
|
11
25
|
idType?: 'serial' | 'uuid';
|
12
26
|
localesSuffix?: string;
|
13
27
|
logger?: DrizzleConfig['logger'];
|
@@ -25,111 +39,22 @@ export type Args = {
|
|
25
39
|
* @experimental This only works when there are not other tables or enums of the same name in the database under a different schema. Awaiting fix from Drizzle.
|
26
40
|
*/
|
27
41
|
schemaName?: string;
|
28
|
-
|
42
|
+
tablesFilter?: string[];
|
43
|
+
transactionOptions?: false | PgTransactionConfig;
|
29
44
|
versionsSuffix?: string;
|
30
45
|
};
|
31
|
-
export type GenericColumn = PgColumn<ColumnBaseConfig<ColumnDataType, string>, Record<string, unknown>>;
|
32
|
-
export type GenericColumns = {
|
33
|
-
[x: string]: GenericColumn;
|
34
|
-
};
|
35
|
-
export type GenericTable = PgTableWithColumns<{
|
36
|
-
columns: GenericColumns;
|
37
|
-
dialect: string;
|
38
|
-
name: string;
|
39
|
-
schema: string;
|
40
|
-
}>;
|
41
|
-
export type GenericEnum = PgEnum<[string, ...string[]]>;
|
42
|
-
export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
|
43
|
-
export type PostgresDB = NodePgDatabase<Record<string, unknown>>;
|
44
|
-
export type CountDistinct = (args: {
|
45
|
-
db: PostgresDB | TransactionPg;
|
46
|
-
joins: BuildQueryJoinAliases;
|
47
|
-
tableName: string;
|
48
|
-
where: SQL;
|
49
|
-
}) => Promise<number>;
|
50
|
-
export type DeleteWhere = (args: {
|
51
|
-
db: PostgresDB | TransactionPg;
|
52
|
-
tableName: string;
|
53
|
-
where: SQL;
|
54
|
-
}) => Promise<void>;
|
55
|
-
export type DropDatabase = (args: {
|
56
|
-
adapter: PostgresAdapter;
|
57
|
-
}) => Promise<void>;
|
58
|
-
export type Execute<T> = (args: {
|
59
|
-
db?: PostgresDB | TransactionPg;
|
60
|
-
drizzle?: PostgresDB;
|
61
|
-
raw?: string;
|
62
|
-
sql?: SQL<unknown>;
|
63
|
-
}) => Promise<QueryResult<Record<string, T>>>;
|
64
|
-
export type Insert = (args: {
|
65
|
-
db: PostgresDB | TransactionPg;
|
66
|
-
onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>;
|
67
|
-
tableName: string;
|
68
|
-
values: Record<string, unknown> | Record<string, unknown>[];
|
69
|
-
}) => Promise<Record<string, unknown>[]>;
|
70
|
-
type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operators' | 'relations'>;
|
71
|
-
type Schema = {
|
72
|
-
enum: typeof pgEnum;
|
73
|
-
table: PgTableFn;
|
74
|
-
} | PgSchema;
|
75
46
|
export type PostgresAdapter = {
|
76
|
-
countDistinct: CountDistinct;
|
77
|
-
defaultDrizzleSnapshot: DrizzleSnapshotJSON;
|
78
|
-
deleteWhere: DeleteWhere;
|
79
|
-
drizzle: PostgresDB;
|
80
|
-
dropDatabase: DropDatabase;
|
81
|
-
enums: Record<string, GenericEnum>;
|
82
|
-
execute: Execute<unknown>;
|
83
|
-
/**
|
84
|
-
* 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
|
85
|
-
* Used for returning properly formed errors from unique fields
|
86
|
-
*/
|
87
|
-
fieldConstraints: Record<string, Record<string, string>>;
|
88
|
-
idType: Args['idType'];
|
89
|
-
initializing: Promise<void>;
|
90
|
-
insert: Insert;
|
91
|
-
localesSuffix?: string;
|
92
|
-
logger: DrizzleConfig['logger'];
|
93
|
-
operators: Operators;
|
94
|
-
pgSchema?: Schema;
|
95
47
|
pool: Pool;
|
96
|
-
poolOptions:
|
97
|
-
|
98
|
-
down: (args: MigrateDownArgs) => Promise<void>;
|
99
|
-
name: string;
|
100
|
-
up: (args: MigrateUpArgs) => Promise<void>;
|
101
|
-
}[];
|
102
|
-
push: boolean;
|
103
|
-
rejectInitializing: () => void;
|
104
|
-
relations: Record<string, GenericRelation>;
|
105
|
-
relationshipsSuffix?: string;
|
106
|
-
resolveInitializing: () => void;
|
107
|
-
schemaName?: Args['schemaName'];
|
108
|
-
sessions: {
|
109
|
-
[id: string]: {
|
110
|
-
db: PostgresDB | TransactionPg;
|
111
|
-
reject: () => Promise<void>;
|
112
|
-
resolve: () => Promise<void>;
|
113
|
-
};
|
114
|
-
};
|
115
|
-
tableNameMap: Map<string, string>;
|
116
|
-
tables: Record<string, GenericTable>;
|
117
|
-
versionsSuffix?: string;
|
118
|
-
} & PostgresDrizzleAdapter;
|
119
|
-
export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar';
|
120
|
-
export type MigrateUpArgs = {
|
121
|
-
payload: Payload;
|
122
|
-
req?: Partial<PayloadRequest>;
|
123
|
-
};
|
124
|
-
export type MigrateDownArgs = {
|
125
|
-
payload: Payload;
|
126
|
-
req?: Partial<PayloadRequest>;
|
127
|
-
};
|
48
|
+
poolOptions: PoolConfig;
|
49
|
+
} & BasePostgresAdapter;
|
128
50
|
declare module 'payload' {
|
129
51
|
interface DatabaseAdapter extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>, DrizzleAdapter {
|
52
|
+
afterSchemaInit: PostgresSchemaHook[];
|
53
|
+
beforeSchemaInit: PostgresSchemaHook[];
|
130
54
|
beginTransaction: (options?: PgTransactionConfig) => Promise<null | number | string>;
|
131
55
|
drizzle: PostgresDB;
|
132
56
|
enums: Record<string, GenericEnum>;
|
57
|
+
extensions: Record<string, boolean>;
|
133
58
|
/**
|
134
59
|
* 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
|
135
60
|
* Used for returning properly formed errors from unique fields
|
@@ -156,8 +81,8 @@ declare module 'payload' {
|
|
156
81
|
schema: Record<string, unknown>;
|
157
82
|
schemaName?: Args['schemaName'];
|
158
83
|
tableNameMap: Map<string, string>;
|
84
|
+
tablesFilter?: string[];
|
159
85
|
versionsSuffix?: string;
|
160
86
|
}
|
161
87
|
}
|
162
|
-
export {};
|
163
88
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,kBAAkB,EACnB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACnF,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAE1C,MAAM,MAAM,IAAI,GAAG;IACjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,kBAAkB,EAAE,CAAA;IACtC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,kBAAkB,EAAE,CAAA;IACvC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,MAAM,CAAC,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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;QACxD,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtB,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;QAC/B,QAAQ,CAAC,EAAE;YAAE,KAAK,EAAE,SAAS,CAAA;SAAE,GAAG,QAAQ,CAAA;QAC1C,IAAI,EAAE,IAAI,CAAA;QACV,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACzB,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,IAAI,EAAE,OAAO,CAAA;QACb,kBAAkB,EAAE,MAAM,IAAI,CAAA;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAA;QAC5B,mBAAmB,EAAE,MAAM,IAAI,CAAA;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC/B,UAAU,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QAC/B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACjC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;QACvB,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB;CACF"}
|
package/dist/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n BasePostgresAdapter,\n GenericEnum,\n MigrateDownArgs,\n MigrateUpArgs,\n PostgresDB,\n PostgresSchemaHook,\n} from '@payloadcms/drizzle/postgres'\nimport type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { DrizzleConfig } from 'drizzle-orm'\nimport type { PgSchema, PgTableFn, PgTransactionConfig } from 'drizzle-orm/pg-core'\nimport type { Pool, PoolConfig } from 'pg'\n\nexport type Args = {\n /**\n * Transform the schema after it's built.\n * You can use it to customize the schema with features that aren't supported by Payload.\n * Examples may include: composite indices, generated columns, vectors\n */\n afterSchemaInit?: PostgresSchemaHook[]\n /**\n * Transform the schema before it's built.\n * You can use it to preserve an existing database schema and if there are any collissions Payload will override them.\n * To generate Drizzle schema from the database, see [Drizzle Kit introspection](https://orm.drizzle.team/kit-docs/commands#introspect--pull)\n */\n beforeSchemaInit?: PostgresSchemaHook[]\n /**\n * Pass `true` to disale auto database creation if it doesn't exist.\n * @default false\n */\n disableCreateDatabase?: boolean\n extensions?: string[]\n idType?: 'serial' | 'uuid'\n localesSuffix?: string\n logger?: DrizzleConfig['logger']\n migrationDir?: string\n pool: PoolConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push?: boolean\n relationshipsSuffix?: string\n /**\n * The schema name to use for the database\n * @experimental This only works when there are not other tables or enums of the same name in the database under a different schema. Awaiting fix from Drizzle.\n */\n schemaName?: string\n tablesFilter?: string[]\n transactionOptions?: false | PgTransactionConfig\n versionsSuffix?: string\n}\n\nexport type PostgresAdapter = {\n pool: Pool\n poolOptions: PoolConfig\n} & BasePostgresAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>,\n DrizzleAdapter {\n afterSchemaInit: PostgresSchemaHook[]\n\n beforeSchemaInit: PostgresSchemaHook[]\n beginTransaction: (options?: PgTransactionConfig) => Promise<null | number | string>\n drizzle: PostgresDB\n enums: Record<string, GenericEnum>\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: Args['idType']\n initializing: Promise<void>\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n pgSchema?: { table: PgTableFn } | PgSchema\n pool: Pool\n poolOptions: Args['pool']\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record<string, unknown>\n schemaName?: Args['schemaName']\n tableNameMap: Map<string, string>\n tablesFilter?: string[]\n versionsSuffix?: string\n }\n}\n"],"names":[],"mappings":"AAsDA,WAGuB"}
|
package/license.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-postgres",
|
3
|
-
"version": "3.0.0-canary.
|
3
|
+
"version": "3.0.0-canary.98e0119",
|
4
4
|
"description": "The officially supported Postgres database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -10,6 +10,13 @@
|
|
10
10
|
},
|
11
11
|
"license": "MIT",
|
12
12
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
13
|
+
"maintainers": [
|
14
|
+
{
|
15
|
+
"name": "Payload",
|
16
|
+
"email": "info@payloadcms.com",
|
17
|
+
"url": "https://payloadcms.com"
|
18
|
+
}
|
19
|
+
],
|
13
20
|
"type": "module",
|
14
21
|
"exports": {
|
15
22
|
".": {
|
@@ -35,25 +42,25 @@
|
|
35
42
|
"mock.js"
|
36
43
|
],
|
37
44
|
"dependencies": {
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"drizzle-
|
45
|
+
"@types/pg": "8.10.2",
|
46
|
+
"console-table-printer": "2.12.1",
|
47
|
+
"drizzle-kit": "0.28.0",
|
48
|
+
"drizzle-orm": "0.36.1",
|
41
49
|
"pg": "8.11.3",
|
42
50
|
"prompts": "2.4.2",
|
43
51
|
"to-snake-case": "1.0.0",
|
44
52
|
"uuid": "10.0.0",
|
45
|
-
"@payloadcms/drizzle": "3.0.0-canary.
|
53
|
+
"@payloadcms/drizzle": "3.0.0-canary.98e0119"
|
46
54
|
},
|
47
55
|
"devDependencies": {
|
48
56
|
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
|
49
|
-
"@types/pg": "8.10.2",
|
50
57
|
"@types/to-snake-case": "1.0.0",
|
51
|
-
"esbuild": "0.23.
|
52
|
-
"
|
53
|
-
"
|
58
|
+
"esbuild": "0.23.1",
|
59
|
+
"payload": "3.0.0-canary.98e0119",
|
60
|
+
"@payloadcms/eslint-config": "3.0.0-beta.112"
|
54
61
|
},
|
55
62
|
"peerDependencies": {
|
56
|
-
"payload": "3.0.0-canary.
|
63
|
+
"payload": "3.0.0-canary.98e0119"
|
57
64
|
},
|
58
65
|
"scripts": {
|
59
66
|
"build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm renamePredefinedMigrations",
|
@@ -61,6 +68,8 @@
|
|
61
68
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
62
69
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
63
70
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
71
|
+
"lint": "eslint .",
|
72
|
+
"lint:fix": "eslint . --fix",
|
64
73
|
"renamePredefinedMigrations": "node --no-deprecation --import @swc-node/register/esm-register ./scripts/renamePredefinedMigrations.ts"
|
65
74
|
}
|
66
75
|
}
|
package/dist/countDistinct.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAA;AAEhE,eAAO,MAAM,aAAa,EAAE,aAyB3B,CAAA"}
|
package/dist/countDistinct.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import { chainMethods } from '@payloadcms/drizzle';
|
2
|
-
import { sql } from 'drizzle-orm';
|
3
|
-
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
4
|
-
const chainedMethods = [];
|
5
|
-
joins.forEach(({ condition, table })=>{
|
6
|
-
chainedMethods.push({
|
7
|
-
args: [
|
8
|
-
table,
|
9
|
-
condition
|
10
|
-
],
|
11
|
-
method: 'leftJoin'
|
12
|
-
});
|
13
|
-
});
|
14
|
-
const countResult = await chainMethods({
|
15
|
-
methods: chainedMethods,
|
16
|
-
query: db.select({
|
17
|
-
count: sql`count
|
18
|
-
(DISTINCT ${this.tables[tableName].id})`
|
19
|
-
}).from(this.tables[tableName]).where(where)
|
20
|
-
});
|
21
|
-
return Number(countResult[0].count);
|
22
|
-
};
|
23
|
-
|
24
|
-
//# sourceMappingURL=countDistinct.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods, TransactionPg } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { sql } from 'drizzle-orm'\n\nimport type { CountDistinct, PostgresAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: PostgresAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: (db as TransactionPg)\n .select({\n count: sql<string>`count\n (DISTINCT ${this.tables[tableName].id})`,\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["chainMethods","sql","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","count","tables","id","from","Number"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sBAAqB;AAClD,SAASC,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzCH,MAAMI,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;QACjCH,eAAeI,IAAI,CAAC;YAClBC,MAAM;gBAACF;gBAAOD;aAAU;YACxBI,QAAQ;QACV;IACF;IAEA,MAAMC,cAAc,MAAMd,aAAa;QACrCe,SAASR;QACTS,OAAO,AAACb,GACLc,MAAM,CAAC;YACNC,OAAOjB,GAAW,CAAC;sBACL,EAAE,IAAI,CAACkB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC;QAC9C,GACCC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACI,KAAK;AACpC,EAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAUpE,CAAA"}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { formatJSONPathSegment } from './formatJSONPathSegment.js';
|
2
|
-
export const convertPathToJSONTraversal = (incomingSegments)=>{
|
3
|
-
const segments = [
|
4
|
-
...incomingSegments
|
5
|
-
];
|
6
|
-
segments.shift();
|
7
|
-
return segments.reduce((res, segment, i)=>{
|
8
|
-
const formattedSegment = formatJSONPathSegment(segment);
|
9
|
-
if (i + 1 === segments.length) return `${res}->>${formattedSegment}`;
|
10
|
-
return `${res}->${formattedSegment}`;
|
11
|
-
}, '');
|
12
|
-
};
|
13
|
-
|
14
|
-
//# sourceMappingURL=convertPathToJSONTraversal.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
type Args = {
|
2
|
-
operator: string;
|
3
|
-
pathSegments: string[];
|
4
|
-
treatAsArray?: string[];
|
5
|
-
treatRootAsArray?: boolean;
|
6
|
-
value: unknown;
|
7
|
-
};
|
8
|
-
export declare const createJSONQuery: ({ operator, pathSegments, treatAsArray, treatRootAsArray, value, }: Args) => string;
|
9
|
-
export {};
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
|