@payloadcms/db-postgres 3.0.0-alpha.48 → 3.0.0-alpha.50

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. package/README.md +1 -3
  2. package/dist/create.js +2 -2
  3. package/dist/create.js.map +1 -1
  4. package/dist/createGlobal.d.ts +1 -1
  5. package/dist/createGlobal.d.ts.map +1 -1
  6. package/dist/createGlobal.js +3 -3
  7. package/dist/createGlobal.js.map +1 -1
  8. package/dist/createGlobalVersion.d.ts +1 -1
  9. package/dist/createGlobalVersion.d.ts.map +1 -1
  10. package/dist/createGlobalVersion.js +2 -2
  11. package/dist/createGlobalVersion.js.map +1 -1
  12. package/dist/createVersion.js +2 -2
  13. package/dist/createVersion.js.map +1 -1
  14. package/dist/deleteOne.d.ts.map +1 -1
  15. package/dist/deleteOne.js +41 -14
  16. package/dist/deleteOne.js.map +1 -1
  17. package/dist/find/chainMethods.d.ts +3 -2
  18. package/dist/find/chainMethods.d.ts.map +1 -1
  19. package/dist/find/chainMethods.js.map +1 -1
  20. package/dist/find/findMany.d.ts.map +1 -1
  21. package/dist/find/findMany.js +31 -53
  22. package/dist/find/findMany.js.map +1 -1
  23. package/dist/findGlobal.js +1 -1
  24. package/dist/findGlobal.js.map +1 -1
  25. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  26. package/dist/queries/parseParams.js +1 -1
  27. package/dist/queries/parseParams.js.map +1 -1
  28. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  29. package/dist/queries/sanitizeQueryValue.js +4 -1
  30. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  31. package/dist/queries/selectDistinct.d.ts +23 -0
  32. package/dist/queries/selectDistinct.d.ts.map +1 -0
  33. package/dist/queries/selectDistinct.js +41 -0
  34. package/dist/queries/selectDistinct.js.map +1 -0
  35. package/dist/transform/read/hasManyText.d.ts +2 -2
  36. package/dist/transform/read/hasManyText.d.ts.map +1 -1
  37. package/dist/transform/read/hasManyText.js +1 -1
  38. package/dist/transform/read/hasManyText.js.map +1 -1
  39. package/dist/transform/read/index.d.ts.map +1 -1
  40. package/dist/transform/read/index.js +2 -2
  41. package/dist/transform/read/index.js.map +1 -1
  42. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  43. package/dist/transform/write/array.d.ts +2 -2
  44. package/dist/transform/write/array.d.ts.map +1 -1
  45. package/dist/transform/write/array.js +3 -3
  46. package/dist/transform/write/array.js.map +1 -1
  47. package/dist/transform/write/blocks.d.ts +2 -2
  48. package/dist/transform/write/blocks.d.ts.map +1 -1
  49. package/dist/transform/write/blocks.js +3 -3
  50. package/dist/transform/write/blocks.js.map +1 -1
  51. package/dist/transform/write/index.js +4 -4
  52. package/dist/transform/write/index.js.map +1 -1
  53. package/dist/transform/write/texts.js +2 -2
  54. package/dist/transform/write/texts.js.map +1 -1
  55. package/dist/transform/write/traverseFields.d.ts +2 -2
  56. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  57. package/dist/transform/write/traverseFields.js +21 -21
  58. package/dist/transform/write/traverseFields.js.map +1 -1
  59. package/dist/transform/write/types.d.ts +1 -1
  60. package/dist/transform/write/types.d.ts.map +1 -1
  61. package/dist/transform/write/types.js.map +1 -1
  62. package/dist/update.d.ts.map +1 -1
  63. package/dist/update.js +20 -45
  64. package/dist/update.js.map +1 -1
  65. package/dist/updateGlobal.d.ts +1 -1
  66. package/dist/updateGlobal.d.ts.map +1 -1
  67. package/dist/updateGlobal.js +3 -3
  68. package/dist/updateGlobal.js.map +1 -1
  69. package/dist/updateGlobalVersion.js +2 -2
  70. package/dist/updateGlobalVersion.js.map +1 -1
  71. package/dist/updateVersion.js +2 -2
  72. package/dist/updateVersion.js.map +1 -1
  73. package/dist/upsertRow/index.d.ts.map +1 -1
  74. package/dist/upsertRow/types.d.ts +1 -1
  75. package/dist/upsertRow/types.d.ts.map +1 -1
  76. package/dist/upsertRow/types.js.map +1 -1
  77. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  78. package/package.json +20 -7
  79. package/src/index.ts +150 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database'\nimport type { PayloadRequest, SanitizedGlobalConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where: whereArg,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = `_${toSnakeCase(global)}_v`\n const fields = buildVersionGlobalFields(globalConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n tableName,\n where,\n req,\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","upsertRow","updateGlobalVersion","id","global","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","slug","whereToUse","equals","tableName","fields","adapter","result","data","operation"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,OAAOC,QAAQ,EACY;IAE7B,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMgB,aAAaX,YAAY;QAAEN,IAAI;YAAEkB,QAAQlB;QAAG;IAAE;IACpD,MAAMmB,YAAY,CAAC,CAAC,EAAEvB,YAAYK,QAAQ,EAAE,CAAC;IAC7C,MAAMmB,SAASzB,yBAAyBgB;IAExC,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjCwB,SAAS,IAAI;QACbD;QACAlB;QACAiB;QACAd,OAAOY;IACT;IAEA,MAAMK,SAAS,MAAMxB,UAA8B;QACjDE;QACAqB,SAAS,IAAI;QACbE,MAAMnB;QACNG;QACAa;QACAI,WAAW;QACXL;QACAd;QACAF;IACF;IAEA,OAAOmB;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateGlobalVersionArgs } from 'payload/database'\nimport type { PayloadRequest, SanitizedGlobalConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where: whereArg,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = `_${toSnakeCase(global)}_v`\n const fields = buildVersionGlobalFields(globalConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","upsertRow","updateGlobalVersion","id","global","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","globalConfig","payload","globals","config","find","slug","whereToUse","equals","tableName","fields","adapter","result","data","operation"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,OAAOC,QAAQ,EACY;IAE7B,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMgB,aAAaX,YAAY;QAAEN,IAAI;YAAEkB,QAAQlB;QAAG;IAAE;IACpD,MAAMmB,YAAY,CAAC,CAAC,EAAEvB,YAAYK,QAAQ,EAAE,CAAC;IAC7C,MAAMmB,SAASzB,yBAAyBgB;IAExC,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjCwB,SAAS,IAAI;QACbD;QACAlB;QACAiB;QACAd,OAAOY;IACT;IAEA,MAAMK,SAAS,MAAMxB,UAA8B;QACjDE;QACAqB,SAAS,IAAI;QACbE,MAAMnB;QACNG;QACAa;QACAI,WAAW;QACXrB;QACAgB;QACAd;IACF;IAEA,OAAOiB;AACT"}
@@ -26,9 +26,9 @@ export async function updateVersion({ id, collection, locale, req = {}, versionD
26
26
  db,
27
27
  fields,
28
28
  operation: 'update',
29
+ req,
29
30
  tableName,
30
- where,
31
- req
31
+ where
32
32
  });
33
33
  return result;
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n collection,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where: whereArg,\n }: UpdateVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = `_${toSnakeCase(collection)}_v`\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n tableName,\n where,\n req,\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","upsertRow","updateVersion","id","collection","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","whereToUse","equals","tableName","fields","adapter","result","data","operation"],"mappings":"AAGA,SAASA,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,cAEpB,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,OAAOC,QAAQ,EACM;IAEvB,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMC,aAAaT,YAAY;QAAEN,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACpD,MAAMiB,YAAY,CAAC,CAAC,EAAErB,YAAYK,YAAY,EAAE,CAAC;IACjD,MAAMiB,SAASvB,6BAA6BgB;IAE5C,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjCsB,SAAS,IAAI;QACbD;QACAhB;QACAe;QACAZ,OAAOU;IACT;IAEA,MAAMK,SAAS,MAAMtB,UAA8B;QACjDE;QACAmB,SAAS,IAAI;QACbE,MAAMjB;QACNG;QACAW;QACAI,WAAW;QACXL;QACAZ;QACAF;IACF;IAEA,OAAOiB;AACT"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { TypeWithVersion, UpdateVersionArgs } from 'payload/database'\nimport type { PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload/types'\n\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: PostgresAdapter,\n {\n id,\n collection,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where: whereArg,\n }: UpdateVersionArgs<T>,\n) {\n const db = this.sessions[req.transactionID]?.db || this.drizzle\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = `_${toSnakeCase(collection)}_v`\n const fields = buildVersionCollectionFields(collectionConfig)\n\n const { where } = await buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n operation: 'update',\n req,\n tableName,\n where,\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","upsertRow","updateVersion","id","collection","locale","req","versionData","where","whereArg","db","sessions","transactionID","drizzle","collectionConfig","payload","collections","config","whereToUse","equals","tableName","fields","adapter","result","data","operation"],"mappings":"AAGA,SAASA,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,OAAO,eAAeC,cAEpB,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,OAAOC,QAAQ,EACM;IAEvB,MAAMC,KAAK,IAAI,CAACC,QAAQ,CAACL,IAAIM,aAAa,CAAC,EAAEF,MAAM,IAAI,CAACG,OAAO;IAC/D,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMC,aAAaT,YAAY;QAAEN,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACpD,MAAMiB,YAAY,CAAC,CAAC,EAAErB,YAAYK,YAAY,EAAE,CAAC;IACjD,MAAMiB,SAASvB,6BAA6BgB;IAE5C,MAAM,EAAEN,KAAK,EAAE,GAAG,MAAMR,WAAW;QACjCsB,SAAS,IAAI;QACbD;QACAhB;QACAe;QACAZ,OAAOU;IACT;IAEA,MAAMK,SAAS,MAAMtB,UAA8B;QACjDE;QACAmB,SAAS,IAAI;QACbE,MAAMjB;QACNG;QACAW;QACAI,WAAW;QACXnB;QACAc;QACAZ;IACF;IAEA,OAAOe;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAM/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAStC,eAAO,MAAM,SAAS,mHAYnB,IAAI,eAkUN,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAM/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAStC,eAAO,MAAM,SAAS,mHAYnB,IAAI,KAAG,QAAQ,CAAC,CAkUlB,CAAA"}
@@ -7,8 +7,8 @@ type BaseArgs = {
7
7
  db: DrizzleDB;
8
8
  fields: Field[];
9
9
  path?: string;
10
- tableName: string;
11
10
  req: PayloadRequest;
11
+ tableName: string;
12
12
  };
13
13
  type CreateArgs = BaseArgs & {
14
14
  id?: never;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE5E,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,SAAS,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE5E,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,SAAS,CAAA;IACb,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,KAAK,UAAU,GAAG,QAAQ,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, PayloadRequest } from 'payload/types'\n\nimport type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'\n\ntype BaseArgs = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n db: DrizzleDB\n fields: Field[]\n path?: string\n tableName: string\n req: PayloadRequest\n}\n\ntype CreateArgs = BaseArgs & {\n id?: never\n operation: 'create'\n upsertTarget?: never\n where?: never\n}\n\ntype UpdateArgs = BaseArgs & {\n id?: number | string\n operation: 'update'\n upsertTarget?: GenericColumn\n where?: SQL<unknown>\n}\n\nexport type Args = CreateArgs | UpdateArgs\n"],"names":[],"mappings":"AA6BA,WAA0C"}
1
+ {"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, PayloadRequest } from 'payload/types'\n\nimport type { DrizzleDB, GenericColumn, PostgresAdapter } from '../types.js'\n\ntype BaseArgs = {\n adapter: PostgresAdapter\n data: Record<string, unknown>\n db: DrizzleDB\n fields: Field[]\n path?: string\n req: PayloadRequest\n tableName: string\n}\n\ntype CreateArgs = BaseArgs & {\n id?: never\n operation: 'create'\n upsertTarget?: never\n where?: never\n}\n\ntype UpdateArgs = BaseArgs & {\n id?: number | string\n operation: 'update'\n upsertTarget?: GenericColumn\n where?: SQL<unknown>\n}\n\nexport type Args = CreateArgs | UpdateArgs\n"],"names":[],"mappings":"AA6BA,WAA0C"}
@@ -1 +1 @@
1
- {"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,UAAU,MAAM,MAI3E,CAAA"}
1
+ {"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,UAAU,MAAM,KAAG,CAI9E,CAAA"}
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@payloadcms/db-postgres",
3
- "version": "3.0.0-alpha.48",
3
+ "version": "3.0.0-alpha.50",
4
4
  "description": "The officially supported Postgres database adapter for Payload",
5
- "repository": "https://github.com/payloadcms/payload",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/payloadcms/payload.git",
8
+ "directory": "packages/db-postgres"
9
+ },
6
10
  "license": "MIT",
7
11
  "homepage": "https://payloadcms.com",
8
12
  "type": "module",
@@ -26,14 +30,23 @@
26
30
  "devDependencies": {
27
31
  "@types/pg": "8.10.2",
28
32
  "@types/to-snake-case": "1.0.0",
29
- "@payloadcms/eslint-config": "1.1.1",
30
- "payload": "3.0.0-alpha.48"
33
+ "payload": "3.0.0-alpha.50",
34
+ "@payloadcms/eslint-config": "1.1.1"
31
35
  },
32
36
  "peerDependencies": {
33
- "payload": "3.0.0-alpha.48"
37
+ "payload": "3.0.0-alpha.50"
34
38
  },
35
- "publishConfig": {
36
- "registry": "https://registry.npmjs.org/"
39
+ "exports": {
40
+ ".": {
41
+ "import": "./dist/index.js",
42
+ "require": "./dist/index.js",
43
+ "types": "./dist/index.d.ts"
44
+ },
45
+ "./types": {
46
+ "import": "./dist/types.js",
47
+ "require": "./dist/types.js",
48
+ "types": "./dist/types.d.ts"
49
+ }
37
50
  },
38
51
  "files": [
39
52
  "dist",
package/src/index.ts ADDED
@@ -0,0 +1,150 @@
1
+ import type { Payload } from 'payload'
2
+ import type { DatabaseAdapterObj } from 'payload/database'
3
+
4
+ import fs from 'fs'
5
+ import path from 'path'
6
+ import { createDatabaseAdapter } from 'payload/database'
7
+
8
+ import type { Args, PostgresAdapter } from './types.js'
9
+
10
+ import { connect } from './connect.js'
11
+ import { create } from './create.js'
12
+ import { createGlobal } from './createGlobal.js'
13
+ import { createGlobalVersion } from './createGlobalVersion.js'
14
+ import { createMigration } from './createMigration.js'
15
+ import { createVersion } from './createVersion.js'
16
+ import { deleteMany } from './deleteMany.js'
17
+ import { deleteOne } from './deleteOne.js'
18
+ import { deleteVersions } from './deleteVersions.js'
19
+ import { destroy } from './destroy.js'
20
+ import { find } from './find.js'
21
+ import { findGlobal } from './findGlobal.js'
22
+ import { findGlobalVersions } from './findGlobalVersions.js'
23
+ import { findOne } from './findOne.js'
24
+ import { findVersions } from './findVersions.js'
25
+ import { init } from './init.js'
26
+ import { migrate } from './migrate.js'
27
+ import { migrateDown } from './migrateDown.js'
28
+ import { migrateFresh } from './migrateFresh.js'
29
+ import { migrateRefresh } from './migrateRefresh.js'
30
+ import { migrateReset } from './migrateReset.js'
31
+ import { migrateStatus } from './migrateStatus.js'
32
+ import { queryDrafts } from './queryDrafts.js'
33
+ import { beginTransaction } from './transactions/beginTransaction.js'
34
+ import { commitTransaction } from './transactions/commitTransaction.js'
35
+ import { rollbackTransaction } from './transactions/rollbackTransaction.js'
36
+ import { updateOne } from './update.js'
37
+ import { updateGlobal } from './updateGlobal.js'
38
+ import { updateGlobalVersion } from './updateGlobalVersion.js'
39
+ import { updateVersion } from './updateVersion.js'
40
+
41
+ export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
42
+
43
+ export function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {
44
+ function adapter({ payload }: { payload: Payload }) {
45
+ const migrationDir = findMigrationDir(args.migrationDir)
46
+ const idType = args.idType || 'serial'
47
+
48
+ return createDatabaseAdapter<PostgresAdapter>({
49
+ name: 'postgres',
50
+
51
+ // Postgres-specific
52
+ drizzle: undefined,
53
+ enums: {},
54
+ fieldConstraints: {},
55
+ idType,
56
+ logger: args.logger,
57
+ pgSchema: undefined,
58
+ pool: undefined,
59
+ poolOptions: args.pool,
60
+ push: args.push,
61
+ relations: {},
62
+ schema: {},
63
+ schemaName: args.schemaName,
64
+ sessions: {},
65
+ tables: {},
66
+
67
+ // DatabaseAdapter
68
+ beginTransaction,
69
+ commitTransaction,
70
+ connect,
71
+ create,
72
+ createGlobal,
73
+ createGlobalVersion,
74
+ createMigration,
75
+ createVersion,
76
+ /**
77
+ * This represents how a default ID is treated in Payload as were a field type
78
+ */
79
+ defaultIDType: idType === 'serial' ? 'number' : 'text',
80
+ deleteMany,
81
+ deleteOne,
82
+ deleteVersions,
83
+ destroy,
84
+ find,
85
+ findGlobal,
86
+ findGlobalVersions,
87
+ findOne,
88
+ findVersions,
89
+ init,
90
+ migrate,
91
+ migrateDown,
92
+ migrateFresh,
93
+ migrateRefresh,
94
+ migrateReset,
95
+ migrateStatus,
96
+ migrationDir,
97
+ payload,
98
+ queryDrafts,
99
+ rollbackTransaction,
100
+ updateGlobal,
101
+ updateGlobalVersion,
102
+ updateOne,
103
+ updateVersion,
104
+ })
105
+ }
106
+
107
+ return {
108
+ defaultIDType: 'number',
109
+ init: adapter,
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Attempt to find migrations directory.
115
+ *
116
+ * Checks for the following directories in order:
117
+ * - `migrationDir` argument from Payload config
118
+ * - `src/migrations`
119
+ * - `dist/migrations`
120
+ * - `migrations`
121
+ *
122
+ * Defaults to `src/migrations`
123
+ *
124
+ * @param migrationDir
125
+ * @returns
126
+ */
127
+ function findMigrationDir(migrationDir?: string): string {
128
+ const cwd = process.cwd()
129
+ const srcDir = path.resolve(cwd, 'src/migrations')
130
+ const distDir = path.resolve(cwd, 'dist/migrations')
131
+ const relativeMigrations = path.resolve(cwd, 'migrations')
132
+
133
+ // Use arg if provided
134
+ if (migrationDir) return migrationDir
135
+
136
+ // Check other common locations
137
+ if (fs.existsSync(srcDir)) {
138
+ return srcDir
139
+ }
140
+
141
+ if (fs.existsSync(distDir)) {
142
+ return distDir
143
+ }
144
+
145
+ if (fs.existsSync(relativeMigrations)) {
146
+ return relativeMigrations
147
+ }
148
+
149
+ return srcDir
150
+ }