@open-aih/payload-ddb 3.1.0 → 4.1.0

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.
Files changed (162) hide show
  1. package/README.md +141 -18
  2. package/dist/count.d.ts.map +1 -1
  3. package/dist/count.js +4 -2
  4. package/dist/count.js.map +1 -1
  5. package/dist/countGlobalVersions.d.ts.map +1 -1
  6. package/dist/countGlobalVersions.js +6 -1
  7. package/dist/countGlobalVersions.js.map +1 -1
  8. package/dist/countVersions.d.ts.map +1 -1
  9. package/dist/countVersions.js +6 -1
  10. package/dist/countVersions.js.map +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +31 -15
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts.map +1 -1
  15. package/dist/createGlobal.js +2 -14
  16. package/dist/createGlobal.js.map +1 -1
  17. package/dist/createGlobalVersion.d.ts +1 -1
  18. package/dist/createGlobalVersion.d.ts.map +1 -1
  19. package/dist/createGlobalVersion.js +3 -41
  20. package/dist/createGlobalVersion.js.map +1 -1
  21. package/dist/createVersion.d.ts +6 -5
  22. package/dist/createVersion.d.ts.map +1 -1
  23. package/dist/createVersion.js +8 -48
  24. package/dist/createVersion.js.map +1 -1
  25. package/dist/deleteMany.d.ts +1 -6
  26. package/dist/deleteMany.d.ts.map +1 -1
  27. package/dist/deleteMany.js +8 -19
  28. package/dist/deleteMany.js.map +1 -1
  29. package/dist/deleteOne.d.ts.map +1 -1
  30. package/dist/deleteOne.js +20 -24
  31. package/dist/deleteOne.js.map +1 -1
  32. package/dist/deleteVersions.d.ts.map +1 -1
  33. package/dist/deleteVersions.js +8 -14
  34. package/dist/deleteVersions.js.map +1 -1
  35. package/dist/find.d.ts.map +1 -1
  36. package/dist/find.js +15 -2
  37. package/dist/find.js.map +1 -1
  38. package/dist/findDistinct.d.ts.map +1 -1
  39. package/dist/findDistinct.js +3 -1
  40. package/dist/findDistinct.js.map +1 -1
  41. package/dist/findGlobal.d.ts.map +1 -1
  42. package/dist/findGlobal.js +3 -2
  43. package/dist/findGlobal.js.map +1 -1
  44. package/dist/findGlobalVersions.d.ts.map +1 -1
  45. package/dist/findGlobalVersions.js +10 -2
  46. package/dist/findGlobalVersions.js.map +1 -1
  47. package/dist/findOne.d.ts.map +1 -1
  48. package/dist/findOne.js +17 -6
  49. package/dist/findOne.js.map +1 -1
  50. package/dist/findVersions.d.ts.map +1 -1
  51. package/dist/findVersions.js +10 -2
  52. package/dist/findVersions.js.map +1 -1
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +7 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/queryDrafts.d.ts.map +1 -1
  58. package/dist/queryDrafts.js +24 -4
  59. package/dist/queryDrafts.js.map +1 -1
  60. package/dist/updateGlobal.d.ts +5 -4
  61. package/dist/updateGlobal.d.ts.map +1 -1
  62. package/dist/updateGlobal.js +22 -36
  63. package/dist/updateGlobal.js.map +1 -1
  64. package/dist/updateGlobalVersion.d.ts.map +1 -1
  65. package/dist/updateGlobalVersion.js +3 -49
  66. package/dist/updateGlobalVersion.js.map +1 -1
  67. package/dist/updateJobs.d.ts +21 -0
  68. package/dist/updateJobs.d.ts.map +1 -0
  69. package/dist/updateJobs.js +83 -0
  70. package/dist/updateJobs.js.map +1 -0
  71. package/dist/updateMany.d.ts +9 -3
  72. package/dist/updateMany.d.ts.map +1 -1
  73. package/dist/updateMany.js +47 -30
  74. package/dist/updateMany.js.map +1 -1
  75. package/dist/updateOne.d.ts +6 -1
  76. package/dist/updateOne.d.ts.map +1 -1
  77. package/dist/updateOne.js +49 -49
  78. package/dist/updateOne.js.map +1 -1
  79. package/dist/updateVersion.d.ts.map +1 -1
  80. package/dist/updateVersion.js +3 -52
  81. package/dist/updateVersion.js.map +1 -1
  82. package/dist/upsert.d.ts +6 -0
  83. package/dist/upsert.d.ts.map +1 -1
  84. package/dist/upsert.js +57 -41
  85. package/dist/upsert.js.map +1 -1
  86. package/dist/utilities/backfillUniqueGuards.d.ts +42 -0
  87. package/dist/utilities/backfillUniqueGuards.d.ts.map +1 -0
  88. package/dist/utilities/backfillUniqueGuards.js +39 -0
  89. package/dist/utilities/backfillUniqueGuards.js.map +1 -0
  90. package/dist/utilities/buildFilterExpression.d.ts +29 -14
  91. package/dist/utilities/buildFilterExpression.d.ts.map +1 -1
  92. package/dist/utilities/buildFilterExpression.js +55 -14
  93. package/dist/utilities/buildFilterExpression.js.map +1 -1
  94. package/dist/utilities/castWhere.d.ts +84 -0
  95. package/dist/utilities/castWhere.d.ts.map +1 -0
  96. package/dist/utilities/castWhere.js +254 -0
  97. package/dist/utilities/castWhere.js.map +1 -0
  98. package/dist/utilities/findFirst.d.ts +3 -2
  99. package/dist/utilities/findFirst.d.ts.map +1 -1
  100. package/dist/utilities/findFirst.js +14 -46
  101. package/dist/utilities/findFirst.js.map +1 -1
  102. package/dist/utilities/geo.d.ts +36 -0
  103. package/dist/utilities/geo.d.ts.map +1 -0
  104. package/dist/utilities/geo.js +108 -0
  105. package/dist/utilities/geo.js.map +1 -0
  106. package/dist/utilities/mapWithConcurrency.d.ts +12 -0
  107. package/dist/utilities/mapWithConcurrency.d.ts.map +1 -0
  108. package/dist/utilities/mapWithConcurrency.js +32 -0
  109. package/dist/utilities/mapWithConcurrency.js.map +1 -0
  110. package/dist/utilities/matchesWhere.d.ts +25 -5
  111. package/dist/utilities/matchesWhere.d.ts.map +1 -1
  112. package/dist/utilities/matchesWhere.js +150 -38
  113. package/dist/utilities/matchesWhere.js.map +1 -1
  114. package/dist/utilities/operators.d.ts +22 -12
  115. package/dist/utilities/operators.d.ts.map +1 -1
  116. package/dist/utilities/operators.js +36 -31
  117. package/dist/utilities/operators.js.map +1 -1
  118. package/dist/utilities/optimistic.d.ts +29 -0
  119. package/dist/utilities/optimistic.d.ts.map +1 -0
  120. package/dist/utilities/optimistic.js +58 -0
  121. package/dist/utilities/optimistic.js.map +1 -0
  122. package/dist/utilities/prepareWhere.d.ts +63 -0
  123. package/dist/utilities/prepareWhere.d.ts.map +1 -0
  124. package/dist/utilities/prepareWhere.js +198 -0
  125. package/dist/utilities/prepareWhere.js.map +1 -0
  126. package/dist/utilities/queryCount.d.ts +6 -3
  127. package/dist/utilities/queryCount.d.ts.map +1 -1
  128. package/dist/utilities/queryCount.js +16 -45
  129. package/dist/utilities/queryCount.js.map +1 -1
  130. package/dist/utilities/queryMatching.d.ts +8 -7
  131. package/dist/utilities/queryMatching.d.ts.map +1 -1
  132. package/dist/utilities/queryMatching.js +17 -54
  133. package/dist/utilities/queryMatching.js.map +1 -1
  134. package/dist/utilities/queryPartition.d.ts +26 -0
  135. package/dist/utilities/queryPartition.d.ts.map +1 -0
  136. package/dist/utilities/queryPartition.js +55 -0
  137. package/dist/utilities/queryPartition.js.map +1 -0
  138. package/dist/utilities/resolveJoins.d.ts +37 -0
  139. package/dist/utilities/resolveJoins.d.ts.map +1 -0
  140. package/dist/utilities/resolveJoins.js +195 -0
  141. package/dist/utilities/resolveJoins.js.map +1 -0
  142. package/dist/utilities/stripInternalKeys.d.ts +17 -3
  143. package/dist/utilities/stripInternalKeys.d.ts.map +1 -1
  144. package/dist/utilities/stripInternalKeys.js +25 -4
  145. package/dist/utilities/stripInternalKeys.js.map +1 -1
  146. package/dist/utilities/uniqueGuards.d.ts +39 -0
  147. package/dist/utilities/uniqueGuards.d.ts.map +1 -0
  148. package/dist/utilities/uniqueGuards.js +106 -0
  149. package/dist/utilities/uniqueGuards.js.map +1 -0
  150. package/dist/utilities/updateVersionRow.d.ts +19 -0
  151. package/dist/utilities/updateVersionRow.d.ts.map +1 -0
  152. package/dist/utilities/updateVersionRow.js +40 -0
  153. package/dist/utilities/updateVersionRow.js.map +1 -0
  154. package/dist/utilities/writeErrors.d.ts +11 -0
  155. package/dist/utilities/writeErrors.d.ts.map +1 -0
  156. package/dist/utilities/writeErrors.js +27 -0
  157. package/dist/utilities/writeErrors.js.map +1 -0
  158. package/dist/utilities/writeItems.d.ts +124 -0
  159. package/dist/utilities/writeItems.d.ts.map +1 -0
  160. package/dist/utilities/writeItems.js +383 -0
  161. package/dist/utilities/writeItems.js.map +1 -0
  162. package/package.json +21 -14
@@ -1,27 +1,23 @@
1
- import { TransactWriteCommand } from '@aws-sdk/lib-dynamodb';
2
1
  import { randomUUID } from 'node:crypto';
3
2
  import { findFirst } from './utilities/findFirst.js';
4
- import { normalizeForDynamo } from './utilities/normalizeForDynamo.js';
5
3
  import { projectVersionSnapshot } from './utilities/resolveSchema.js';
4
+ import { putVersionAsLatest } from './utilities/writeItems.js';
6
5
  /**
7
6
  * Insert a new version for a collection's parent doc, maintaining the
8
7
  * `latest=true` invariant per parent.
9
8
  *
10
9
  * Two round trips:
11
10
  * 1. `Query` the versions partition for the previous `latest=true` row.
12
- * 2. `TransactWriteItems` to flip that row's `latest` to false and put the
13
- * new row in one atomic call. If a crash occurs mid-flow neither
14
- * mutation lands, so we never end up with two `latest=true` rows or
15
- * zero. The Update carries `attribute_exists(pk)` so the transaction
16
- * fails cleanly if the previous row was deleted between (1) and (2).
11
+ * 2. `putVersionAsLatest` flips that row's `latest` to false and puts the
12
+ * new row in one atomic `TransactWriteItems` call. If a crash occurs
13
+ * mid-flow neither mutation lands, so we never end up with two
14
+ * `latest=true` rows or zero. The flip carries `attribute_exists(pk)` so
15
+ * the transaction fails cleanly if the previous row was deleted between
16
+ * (1) and (2).
17
17
  *
18
18
  * `autosave` is persisted on the row even though it isn't surfaced in
19
19
  * `TypeWithVersion` — `findVersions` filters by it.
20
20
  */ export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, returning, snapshot, updatedAt, versionData }) {
21
- const docClient = this.docClient;
22
- if (!docClient) {
23
- throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
24
- }
25
21
  const partition = this.resolveVersionsPartition(collectionSlug);
26
22
  const previousLatest = await findFirst(this, {
27
23
  partition,
@@ -63,43 +59,7 @@ import { projectVersionSnapshot } from './utilities/resolveSchema.js';
63
59
  publishedLocale
64
60
  } : {}
65
61
  };
66
- const putItem = normalizeForDynamo({
67
- ...item,
68
- pk: partition,
69
- sk: id
70
- });
71
- const transactItems = [];
72
- if (previousLatest) {
73
- transactItems.push({
74
- Update: {
75
- TableName: this.tableName,
76
- Key: {
77
- pk: partition,
78
- sk: String(previousLatest['id'])
79
- },
80
- UpdateExpression: 'SET #latest = :false',
81
- ExpressionAttributeNames: {
82
- '#latest': 'latest'
83
- },
84
- ExpressionAttributeValues: {
85
- ':false': false
86
- },
87
- // Fail the whole transaction if the previous row was deleted between
88
- // our read and this transaction. Better to error and let the caller
89
- // retry than to silently leave the new version with a phantom flip.
90
- ConditionExpression: 'attribute_exists(pk)'
91
- }
92
- });
93
- }
94
- transactItems.push({
95
- Put: {
96
- TableName: this.tableName,
97
- Item: putItem
98
- }
99
- });
100
- await docClient.send(new TransactWriteCommand({
101
- TransactItems: transactItems
102
- }));
62
+ await putVersionAsLatest(this, partition, item, previousLatest);
103
63
  return returning === false ? null : item;
104
64
  };
105
65
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion } from 'payload'\n\nimport { TransactWriteCommand } from '@aws-sdk/lib-dynamodb'\nimport { randomUUID } from 'node:crypto'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { findFirst } from './utilities/findFirst.js'\nimport { normalizeForDynamo } from './utilities/normalizeForDynamo.js'\nimport { projectVersionSnapshot } from './utilities/resolveSchema.js'\n\n/**\n * Insert a new version for a collection's parent doc, maintaining the\n * `latest=true` invariant per parent.\n *\n * Two round trips:\n * 1. `Query` the versions partition for the previous `latest=true` row.\n * 2. `TransactWriteItems` to flip that row's `latest` to false and put the\n * new row in one atomic call. If a crash occurs mid-flow neither\n * mutation lands, so we never end up with two `latest=true` rows or\n * zero. The Update carries `attribute_exists(pk)` so the transaction\n * fails cleanly if the previous row was deleted between (1) and (2).\n *\n * `autosave` is persisted on the row even though it isn't surfaced in\n * `TypeWithVersion` — `findVersions` filters by it.\n */\nexport const createVersion: CreateVersion = async function createVersion(\n this: DynamoAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const partition = this.resolveVersionsPartition(collectionSlug)\n\n const previousLatest = await findFirst(this, {\n partition,\n where: { and: [{ parent: { equals: parent } }, { latest: { equals: true } }] },\n })\n\n const id = randomUUID()\n // Project the snapshot against the parent collection's schema so that any\n // unknown keys (e.g. registration-form `confirm-password`) don't ride into\n // the version row alongside the legitimate doc state.\n const sanitizedVersionData = projectVersionSnapshot(\n this,\n { kind: 'collection', slug: collectionSlug },\n versionData as Record<string, unknown>,\n )\n const item: Record<string, unknown> = {\n id,\n parent,\n version: sanitizedVersionData,\n createdAt,\n updatedAt,\n latest: true,\n autosave,\n ...(snapshot ? { snapshot: true } : {}),\n ...(publishedLocale !== undefined ? { publishedLocale } : {}),\n }\n\n const putItem = normalizeForDynamo({\n ...item,\n pk: partition,\n sk: id,\n })\n\n const transactItems: NonNullable<\n ConstructorParameters<typeof TransactWriteCommand>[0]['TransactItems']\n > = []\n\n if (previousLatest) {\n transactItems.push({\n Update: {\n TableName: this.tableName,\n Key: { pk: partition, sk: String(previousLatest['id']) },\n UpdateExpression: 'SET #latest = :false',\n ExpressionAttributeNames: { '#latest': 'latest' },\n ExpressionAttributeValues: { ':false': false },\n // Fail the whole transaction if the previous row was deleted between\n // our read and this transaction. Better to error and let the caller\n // retry than to silently leave the new version with a phantom flip.\n ConditionExpression: 'attribute_exists(pk)',\n },\n })\n }\n\n transactItems.push({\n Put: {\n TableName: this.tableName,\n Item: putItem,\n },\n })\n\n await docClient.send(new TransactWriteCommand({ TransactItems: transactItems }))\n\n return returning === false ? (null as never) : (item as never)\n}\n"],"names":["TransactWriteCommand","randomUUID","findFirst","normalizeForDynamo","projectVersionSnapshot","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","returning","snapshot","updatedAt","versionData","docClient","Error","partition","resolveVersionsPartition","previousLatest","where","and","equals","latest","id","sanitizedVersionData","kind","slug","item","version","undefined","putItem","pk","sk","transactItems","push","Update","TableName","tableName","Key","String","UpdateExpression","ExpressionAttributeNames","ExpressionAttributeValues","ConditionExpression","Put","Item","send","TransactItems"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,wBAAuB;AAC5D,SAASC,UAAU,QAAQ,cAAa;AAIxC,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,sBAAsB,QAAQ,+BAA8B;AAErE;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,YAAY,IAAI,CAACC,wBAAwB,CAACX;IAEhD,MAAMY,iBAAiB,MAAMjB,UAAU,IAAI,EAAE;QAC3Ce;QACAG,OAAO;YAAEC,KAAK;gBAAC;oBAAEZ,QAAQ;wBAAEa,QAAQb;oBAAO;gBAAE;gBAAG;oBAAEc,QAAQ;wBAAED,QAAQ;oBAAK;gBAAE;aAAE;QAAC;IAC/E;IAEA,MAAME,KAAKvB;IACX,0EAA0E;IAC1E,2EAA2E;IAC3E,sDAAsD;IACtD,MAAMwB,uBAAuBrB,uBAC3B,IAAI,EACJ;QAAEsB,MAAM;QAAcC,MAAMpB;IAAe,GAC3CO;IAEF,MAAMc,OAAgC;QACpCJ;QACAf;QACAoB,SAASJ;QACTjB;QACAK;QACAU,QAAQ;QACRjB;QACA,GAAIM,WAAW;YAAEA,UAAU;QAAK,IAAI,CAAC,CAAC;QACtC,GAAIF,oBAAoBoB,YAAY;YAAEpB;QAAgB,IAAI,CAAC,CAAC;IAC9D;IAEA,MAAMqB,UAAU5B,mBAAmB;QACjC,GAAGyB,IAAI;QACPI,IAAIf;QACJgB,IAAIT;IACN;IAEA,MAAMU,gBAEF,EAAE;IAEN,IAAIf,gBAAgB;QAClBe,cAAcC,IAAI,CAAC;YACjBC,QAAQ;gBACNC,WAAW,IAAI,CAACC,SAAS;gBACzBC,KAAK;oBAAEP,IAAIf;oBAAWgB,IAAIO,OAAOrB,cAAc,CAAC,KAAK;gBAAE;gBACvDsB,kBAAkB;gBAClBC,0BAA0B;oBAAE,WAAW;gBAAS;gBAChDC,2BAA2B;oBAAE,UAAU;gBAAM;gBAC7C,qEAAqE;gBACrE,oEAAoE;gBACpE,oEAAoE;gBACpEC,qBAAqB;YACvB;QACF;IACF;IAEAV,cAAcC,IAAI,CAAC;QACjBU,KAAK;YACHR,WAAW,IAAI,CAACC,SAAS;YACzBQ,MAAMf;QACR;IACF;IAEA,MAAMhB,UAAUgC,IAAI,CAAC,IAAI/C,qBAAqB;QAAEgD,eAAed;IAAc;IAE7E,OAAOvB,cAAc,QAAS,OAAkBiB;AAClD,EAAC"}
1
+ {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion } from 'payload'\n\nimport { randomUUID } from 'node:crypto'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { findFirst } from './utilities/findFirst.js'\nimport { projectVersionSnapshot } from './utilities/resolveSchema.js'\nimport { putVersionAsLatest } from './utilities/writeItems.js'\n\n/**\n * Insert a new version for a collection's parent doc, maintaining the\n * `latest=true` invariant per parent.\n *\n * Two round trips:\n * 1. `Query` the versions partition for the previous `latest=true` row.\n * 2. `putVersionAsLatest` flips that row's `latest` to false and puts the\n * new row in one atomic `TransactWriteItems` call. If a crash occurs\n * mid-flow neither mutation lands, so we never end up with two\n * `latest=true` rows or zero. The flip carries `attribute_exists(pk)` so\n * the transaction fails cleanly if the previous row was deleted between\n * (1) and (2).\n *\n * `autosave` is persisted on the row even though it isn't surfaced in\n * `TypeWithVersion` — `findVersions` filters by it.\n */\nexport const createVersion: CreateVersion = async function createVersion(\n this: DynamoAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const partition = this.resolveVersionsPartition(collectionSlug)\n\n const previousLatest = await findFirst(this, {\n partition,\n where: { and: [{ parent: { equals: parent } }, { latest: { equals: true } }] },\n })\n\n const id = randomUUID()\n // Project the snapshot against the parent collection's schema so that any\n // unknown keys (e.g. registration-form `confirm-password`) don't ride into\n // the version row alongside the legitimate doc state.\n const sanitizedVersionData = projectVersionSnapshot(\n this,\n { kind: 'collection', slug: collectionSlug },\n versionData as Record<string, unknown>,\n )\n const item: Record<string, unknown> = {\n id,\n parent,\n version: sanitizedVersionData,\n createdAt,\n updatedAt,\n latest: true,\n autosave,\n ...(snapshot ? { snapshot: true } : {}),\n ...(publishedLocale !== undefined ? { publishedLocale } : {}),\n }\n\n await putVersionAsLatest(this, partition, item, previousLatest)\n\n return returning === false ? (null as never) : (item as never)\n}\n"],"names":["randomUUID","findFirst","projectVersionSnapshot","putVersionAsLatest","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","returning","snapshot","updatedAt","versionData","partition","resolveVersionsPartition","previousLatest","where","and","equals","latest","id","sanitizedVersionData","kind","slug","item","version","undefined"],"mappings":"AAEA,SAASA,UAAU,QAAQ,cAAa;AAIxC,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,sBAAsB,QAAQ,+BAA8B;AACrE,SAASC,kBAAkB,QAAQ,4BAA2B;AAE9D;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,YAAY,IAAI,CAACC,wBAAwB,CAACT;IAEhD,MAAMU,iBAAiB,MAAMf,UAAU,IAAI,EAAE;QAC3Ca;QACAG,OAAO;YAAEC,KAAK;gBAAC;oBAAEV,QAAQ;wBAAEW,QAAQX;oBAAO;gBAAE;gBAAG;oBAAEY,QAAQ;wBAAED,QAAQ;oBAAK;gBAAE;aAAE;QAAC;IAC/E;IAEA,MAAME,KAAKrB;IACX,0EAA0E;IAC1E,2EAA2E;IAC3E,sDAAsD;IACtD,MAAMsB,uBAAuBpB,uBAC3B,IAAI,EACJ;QAAEqB,MAAM;QAAcC,MAAMlB;IAAe,GAC3CO;IAEF,MAAMY,OAAgC;QACpCJ;QACAb;QACAkB,SAASJ;QACTf;QACAK;QACAQ,QAAQ;QACRf;QACA,GAAIM,WAAW;YAAEA,UAAU;QAAK,IAAI,CAAC,CAAC;QACtC,GAAIF,oBAAoBkB,YAAY;YAAElB;QAAgB,IAAI,CAAC,CAAC;IAC9D;IAEA,MAAMN,mBAAmB,IAAI,EAAEW,WAAWW,MAAMT;IAEhD,OAAON,cAAc,QAAS,OAAkBe;AAClD,EAAC"}
@@ -1,12 +1,7 @@
1
1
  import type { DeleteMany } from 'payload';
2
2
  /**
3
3
  * v1 strategy: query-and-collect matches, then delete each by composite key
4
- * in parallel.
5
- *
6
- * `BatchWriteItem` could halve the request count (25 deletes per call) but
7
- * has partial-failure semantics that need retry logic — out of scope until
8
- * we wire up retries. Sequential parallel `DeleteCommand`s are simple and
9
- * correct.
4
+ * in parallel. See `deleteItems` for why this isn't a `BatchWriteItem`.
10
5
  */
11
6
  export declare const deleteMany: DeleteMany;
12
7
  //# sourceMappingURL=deleteMany.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,EAAE,UAsBxB,CAAA"}
1
+ {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AASzC;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,UAexB,CAAA"}
@@ -1,27 +1,16 @@
1
- import { DeleteCommand } from '@aws-sdk/lib-dynamodb';
1
+ import { prepareCollectionWhere } from './utilities/prepareWhere.js';
2
2
  import { queryMatching } from './utilities/queryMatching.js';
3
+ import { hasUniqueFields } from './utilities/uniqueGuards.js';
4
+ import { deleteItems } from './utilities/writeItems.js';
3
5
  /**
4
6
  * v1 strategy: query-and-collect matches, then delete each by composite key
5
- * in parallel.
6
- *
7
- * `BatchWriteItem` could halve the request count (25 deletes per call) but
8
- * has partial-failure semantics that need retry logic — out of scope until
9
- * we wire up retries. Sequential parallel `DeleteCommand`s are simple and
10
- * correct.
11
- */ export const deleteMany = async function deleteMany({ collection, where }) {
12
- const docClient = this.docClient;
13
- if (!docClient) {
14
- throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
15
- }
7
+ * in parallel. See `deleteItems` for why this isn't a `BatchWriteItem`.
8
+ */ export const deleteMany = async function deleteMany({ collection, where: rawWhere }) {
9
+ const where = await prepareCollectionWhere(this, collection, rawWhere);
16
10
  const partition = this.resolvePartition(collection);
17
11
  const matched = await queryMatching(this, partition, where);
18
- await Promise.all(matched.map((target)=>docClient.send(new DeleteCommand({
19
- TableName: this.tableName,
20
- Key: {
21
- pk: partition,
22
- sk: String(target['id'])
23
- }
24
- }))));
12
+ await deleteItems(this, partition, matched, // Unique guards are released together with the documents that hold them.
13
+ hasUniqueFields(this, collection) ? collection : undefined);
25
14
  };
26
15
 
27
16
  //# sourceMappingURL=deleteMany.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload'\n\nimport { DeleteCommand } from '@aws-sdk/lib-dynamodb'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * v1 strategy: query-and-collect matches, then delete each by composite key\n * in parallel.\n *\n * `BatchWriteItem` could halve the request count (25 deletes per call) but\n * has partial-failure semantics that need retry logic — out of scope until\n * we wire up retries. Sequential parallel `DeleteCommand`s are simple and\n * correct.\n */\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: DynamoAdapter,\n { collection, where },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const partition = this.resolvePartition(collection)\n const matched = await queryMatching(this, partition, where)\n\n await Promise.all(\n matched.map((target) =>\n docClient.send(\n new DeleteCommand({\n TableName: this.tableName,\n Key: { pk: partition, sk: String(target['id']) },\n }),\n ),\n ),\n )\n}\n"],"names":["DeleteCommand","queryMatching","deleteMany","collection","where","docClient","Error","partition","resolvePartition","matched","Promise","all","map","target","send","TableName","tableName","Key","pk","sk","String"],"mappings":"AAEA,SAASA,aAAa,QAAQ,wBAAuB;AAIrD,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;;;;CAQC,GACD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,KAAK,EAAE;IAErB,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,YAAY,IAAI,CAACC,gBAAgB,CAACL;IACxC,MAAMM,UAAU,MAAMR,cAAc,IAAI,EAAEM,WAAWH;IAErD,MAAMM,QAAQC,GAAG,CACfF,QAAQG,GAAG,CAAC,CAACC,SACXR,UAAUS,IAAI,CACZ,IAAId,cAAc;YAChBe,WAAW,IAAI,CAACC,SAAS;YACzBC,KAAK;gBAAEC,IAAIX;gBAAWY,IAAIC,OAAOP,MAAM,CAAC,KAAK;YAAE;QACjD;AAIR,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { prepareCollectionWhere } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\nimport { hasUniqueFields } from './utilities/uniqueGuards.js'\nimport { deleteItems } from './utilities/writeItems.js'\n\n/**\n * v1 strategy: query-and-collect matches, then delete each by composite key\n * in parallel. See `deleteItems` for why this isn't a `BatchWriteItem`.\n */\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: DynamoAdapter,\n { collection, where: rawWhere },\n) {\n const where = await prepareCollectionWhere(this, collection, rawWhere)\n const partition = this.resolvePartition(collection)\n const matched = await queryMatching(this, partition, where)\n\n await deleteItems(\n this,\n partition,\n matched,\n // Unique guards are released together with the documents that hold them.\n hasUniqueFields(this, collection) ? collection : undefined,\n )\n}\n"],"names":["prepareCollectionWhere","queryMatching","hasUniqueFields","deleteItems","deleteMany","collection","where","rawWhere","partition","resolvePartition","matched","undefined"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,WAAW,QAAQ,4BAA2B;AAEvD;;;CAGC,GACD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,OAAOC,QAAQ,EAAE;IAE/B,MAAMD,QAAQ,MAAMN,uBAAuB,IAAI,EAAEK,YAAYE;IAC7D,MAAMC,YAAY,IAAI,CAACC,gBAAgB,CAACJ;IACxC,MAAMK,UAAU,MAAMT,cAAc,IAAI,EAAEO,WAAWF;IAErD,MAAMH,YACJ,IAAI,EACJK,WACAE,SACA,yEAAyE;IACzER,gBAAgB,IAAI,EAAEG,cAAcA,aAAaM;AAErD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SA4CvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SAsCvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,30 +1,27 @@
1
- import { DeleteCommand } from '@aws-sdk/lib-dynamodb';
2
1
  import { findFirst } from './utilities/findFirst.js';
3
- import { stripInternalKeys } from './utilities/stripInternalKeys.js';
2
+ import { prepareCollectionWhere } from './utilities/prepareWhere.js';
3
+ import { hasUniqueFields } from './utilities/uniqueGuards.js';
4
4
  import { whereToId } from './utilities/whereToId.js';
5
- export const deleteOne = async function deleteOne({ collection, returning, where }) {
6
- const docClient = this.docClient;
7
- if (!docClient) {
8
- throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
9
- }
5
+ import { deleteItem } from './utilities/writeItems.js';
6
+ export const deleteOne = async function deleteOne({ collection, returning, where: rawWhere }) {
7
+ const where = await prepareCollectionWhere(this, collection, rawWhere);
10
8
  const partition = this.resolvePartition(collection);
11
9
  const idFromWhere = whereToId(where);
10
+ // Releasing a document's unique guards needs its values, so those
11
+ // collections always read the document first.
12
+ const guarded = hasUniqueFields(this, collection);
12
13
  // Fast path — pure id-equality lets us delete and capture the doc in one call.
13
- if (idFromWhere !== null) {
14
- const result = await docClient.send(new DeleteCommand({
15
- TableName: this.tableName,
16
- Key: {
17
- pk: partition,
18
- sk: String(idFromWhere)
19
- },
20
- ReturnValues: 'ALL_OLD'
21
- }));
14
+ if (idFromWhere !== null && !guarded) {
15
+ const deleted = await deleteItem(this, partition, idFromWhere, {
16
+ returnOld: true
17
+ });
22
18
  if (returning === false) {
23
19
  return null;
24
20
  }
25
- return result.Attributes ? stripInternalKeys(result.Attributes) : null;
21
+ return deleted;
26
22
  }
27
- // Slow path — locate by query, then delete by composite key.
23
+ // Slow path — locate (a `GetItem` when `where` is an id), then delete by
24
+ // composite key.
28
25
  const found = await findFirst(this, {
29
26
  partition,
30
27
  where
@@ -32,13 +29,12 @@ export const deleteOne = async function deleteOne({ collection, returning, where
32
29
  if (!found) {
33
30
  return null;
34
31
  }
35
- await docClient.send(new DeleteCommand({
36
- TableName: this.tableName,
37
- Key: {
38
- pk: partition,
39
- sk: String(found['id'])
32
+ await deleteItem(this, partition, found['id'], guarded ? {
33
+ unique: {
34
+ collection,
35
+ doc: found
40
36
  }
41
- }));
37
+ } : {});
42
38
  if (returning === false) {
43
39
  return null;
44
40
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload'\n\nimport { DeleteCommand } from '@aws-sdk/lib-dynamodb'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { findFirst } from './utilities/findFirst.js'\nimport { stripInternalKeys } from './utilities/stripInternalKeys.js'\nimport { whereToId } from './utilities/whereToId.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: DynamoAdapter,\n { collection, returning, where },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const partition = this.resolvePartition(collection)\n const idFromWhere = whereToId(where)\n\n // Fast path — pure id-equality lets us delete and capture the doc in one call.\n if (idFromWhere !== null) {\n const result = await docClient.send(\n new DeleteCommand({\n TableName: this.tableName,\n Key: { pk: partition, sk: String(idFromWhere) },\n ReturnValues: 'ALL_OLD',\n }),\n )\n if (returning === false) {\n return null as never\n }\n return (result.Attributes ? stripInternalKeys(result.Attributes) : null) as never\n }\n\n // Slow path — locate by query, then delete by composite key.\n const found = await findFirst(this, { partition, where })\n if (!found) {\n return null as never\n }\n\n await docClient.send(\n new DeleteCommand({\n TableName: this.tableName,\n Key: { pk: partition, sk: String(found['id']) },\n }),\n )\n\n if (returning === false) {\n return null as never\n }\n return found as never\n}\n"],"names":["DeleteCommand","findFirst","stripInternalKeys","whereToId","deleteOne","collection","returning","where","docClient","Error","partition","resolvePartition","idFromWhere","result","send","TableName","tableName","Key","pk","sk","String","ReturnValues","Attributes","found"],"mappings":"AAEA,SAASA,aAAa,QAAQ,wBAAuB;AAIrD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAEhC,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,YAAY,IAAI,CAACC,gBAAgB,CAACN;IACxC,MAAMO,cAAcT,UAAUI;IAE9B,+EAA+E;IAC/E,IAAIK,gBAAgB,MAAM;QACxB,MAAMC,SAAS,MAAML,UAAUM,IAAI,CACjC,IAAId,cAAc;YAChBe,WAAW,IAAI,CAACC,SAAS;YACzBC,KAAK;gBAAEC,IAAIR;gBAAWS,IAAIC,OAAOR;YAAa;YAC9CS,cAAc;QAChB;QAEF,IAAIf,cAAc,OAAO;YACvB,OAAO;QACT;QACA,OAAQO,OAAOS,UAAU,GAAGpB,kBAAkBW,OAAOS,UAAU,IAAI;IACrE;IAEA,6DAA6D;IAC7D,MAAMC,QAAQ,MAAMtB,UAAU,IAAI,EAAE;QAAES;QAAWH;IAAM;IACvD,IAAI,CAACgB,OAAO;QACV,OAAO;IACT;IAEA,MAAMf,UAAUM,IAAI,CAClB,IAAId,cAAc;QAChBe,WAAW,IAAI,CAACC,SAAS;QACzBC,KAAK;YAAEC,IAAIR;YAAWS,IAAIC,OAAOG,KAAK,CAAC,KAAK;QAAE;IAChD;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IACA,OAAOiB;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { findFirst } from './utilities/findFirst.js'\nimport { prepareCollectionWhere } from './utilities/prepareWhere.js'\nimport { hasUniqueFields } from './utilities/uniqueGuards.js'\nimport { whereToId } from './utilities/whereToId.js'\nimport { deleteItem } from './utilities/writeItems.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: DynamoAdapter,\n { collection, returning, where: rawWhere },\n) {\n const where = await prepareCollectionWhere(this, collection, rawWhere)\n const partition = this.resolvePartition(collection)\n const idFromWhere = whereToId(where)\n // Releasing a document's unique guards needs its values, so those\n // collections always read the document first.\n const guarded = hasUniqueFields(this, collection)\n\n // Fast path — pure id-equality lets us delete and capture the doc in one call.\n if (idFromWhere !== null && !guarded) {\n const deleted = await deleteItem(this, partition, idFromWhere, { returnOld: true })\n if (returning === false) {\n return null as never\n }\n return deleted as never\n }\n\n // Slow path — locate (a `GetItem` when `where` is an id), then delete by\n // composite key.\n const found = await findFirst(this, { partition, where })\n if (!found) {\n return null as never\n }\n\n await deleteItem(\n this,\n partition,\n found['id'],\n guarded ? { unique: { collection, doc: found } } : {},\n )\n\n if (returning === false) {\n return null as never\n }\n return found as never\n}\n"],"names":["findFirst","prepareCollectionWhere","hasUniqueFields","whereToId","deleteItem","deleteOne","collection","returning","where","rawWhere","partition","resolvePartition","idFromWhere","guarded","deleted","returnOld","found","unique","doc"],"mappings":"AAIA,SAASA,SAAS,QAAQ,2BAA0B;AACpD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAOC,QAAQ,EAAE;IAE1C,MAAMD,QAAQ,MAAMP,uBAAuB,IAAI,EAAEK,YAAYG;IAC7D,MAAMC,YAAY,IAAI,CAACC,gBAAgB,CAACL;IACxC,MAAMM,cAAcT,UAAUK;IAC9B,kEAAkE;IAClE,8CAA8C;IAC9C,MAAMK,UAAUX,gBAAgB,IAAI,EAAEI;IAEtC,+EAA+E;IAC/E,IAAIM,gBAAgB,QAAQ,CAACC,SAAS;QACpC,MAAMC,UAAU,MAAMV,WAAW,IAAI,EAAEM,WAAWE,aAAa;YAAEG,WAAW;QAAK;QACjF,IAAIR,cAAc,OAAO;YACvB,OAAO;QACT;QACA,OAAOO;IACT;IAEA,yEAAyE;IACzE,iBAAiB;IACjB,MAAME,QAAQ,MAAMhB,UAAU,IAAI,EAAE;QAAEU;QAAWF;IAAM;IACvD,IAAI,CAACQ,OAAO;QACV,OAAO;IACT;IAEA,MAAMZ,WACJ,IAAI,EACJM,WACAM,KAAK,CAAC,KAAK,EACXH,UAAU;QAAEI,QAAQ;YAAEX;YAAYY,KAAKF;QAAM;IAAE,IAAI,CAAC;IAGtD,IAAIT,cAAc,OAAO;QACvB,OAAO;IACT;IACA,OAAOS;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQ7C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,cA2B5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQ7C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,cAsB5B,CAAA"}
@@ -1,28 +1,22 @@
1
- import { DeleteCommand } from '@aws-sdk/lib-dynamodb';
1
+ import { prepareVersionsWhere } from './utilities/prepareWhere.js';
2
2
  import { queryMatching } from './utilities/queryMatching.js';
3
+ import { deleteItems } from './utilities/writeItems.js';
3
4
  /**
4
5
  * Same query + parallel delete pattern as `deleteMany`, but routes to the
5
6
  * versions partition for either a collection (`collection`) or a global
6
7
  * (`globalSlug`). Payload guarantees exactly one of those two slugs is
7
8
  * present.
8
- */ export const deleteVersions = async function deleteVersions({ collection, globalSlug, where }) {
9
- const docClient = this.docClient;
10
- if (!docClient) {
11
- throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
12
- }
9
+ */ export const deleteVersions = async function deleteVersions({ collection, globalSlug, locale, where }) {
13
10
  const slug = collection ?? globalSlug;
14
11
  if (!slug) {
15
12
  throw new Error('payload-ddb: deleteVersions requires either `collection` or `globalSlug`.');
16
13
  }
17
14
  const partition = this.resolveVersionsPartition(slug);
18
- const matched = await queryMatching(this, partition, where);
19
- await Promise.all(matched.map((target)=>docClient.send(new DeleteCommand({
20
- TableName: this.tableName,
21
- Key: {
22
- pk: partition,
23
- sk: String(target['id'])
24
- }
25
- }))));
15
+ const matched = await queryMatching(this, partition, await prepareVersionsWhere(this, {
16
+ kind: collection ? 'collection' : 'global',
17
+ slug
18
+ }, where, locale));
19
+ await deleteItems(this, partition, matched);
26
20
  };
27
21
 
28
22
  //# sourceMappingURL=deleteVersions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload'\n\nimport { DeleteCommand } from '@aws-sdk/lib-dynamodb'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * Same query + parallel delete pattern as `deleteMany`, but routes to the\n * versions partition for either a collection (`collection`) or a global\n * (`globalSlug`). Payload guarantees exactly one of those two slugs is\n * present.\n */\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: DynamoAdapter,\n { collection, globalSlug, where },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const slug = collection ?? globalSlug\n if (!slug) {\n throw new Error('payload-ddb: deleteVersions requires either `collection` or `globalSlug`.')\n }\n\n const partition = this.resolveVersionsPartition(slug)\n const matched = await queryMatching(this, partition, where)\n\n await Promise.all(\n matched.map((target) =>\n docClient.send(\n new DeleteCommand({\n TableName: this.tableName,\n Key: { pk: partition, sk: String(target['id']) },\n }),\n ),\n ),\n )\n}\n"],"names":["DeleteCommand","queryMatching","deleteVersions","collection","globalSlug","where","docClient","Error","slug","partition","resolveVersionsPartition","matched","Promise","all","map","target","send","TableName","tableName","Key","pk","sk","String"],"mappings":"AAEA,SAASA,aAAa,QAAQ,wBAAuB;AAIrD,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;CAKC,GACD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,UAAU,EAAEC,KAAK,EAAE;IAEjC,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,OAAOL,cAAcC;IAC3B,IAAI,CAACI,MAAM;QACT,MAAM,IAAID,MAAM;IAClB;IAEA,MAAME,YAAY,IAAI,CAACC,wBAAwB,CAACF;IAChD,MAAMG,UAAU,MAAMV,cAAc,IAAI,EAAEQ,WAAWJ;IAErD,MAAMO,QAAQC,GAAG,CACfF,QAAQG,GAAG,CAAC,CAACC,SACXT,UAAUU,IAAI,CACZ,IAAIhB,cAAc;YAChBiB,WAAW,IAAI,CAACC,SAAS;YACzBC,KAAK;gBAAEC,IAAIX;gBAAWY,IAAIC,OAAOP,MAAM,CAAC,KAAK;YAAE;QACjD;AAIR,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { prepareVersionsWhere } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\nimport { deleteItems } from './utilities/writeItems.js'\n\n/**\n * Same query + parallel delete pattern as `deleteMany`, but routes to the\n * versions partition for either a collection (`collection`) or a global\n * (`globalSlug`). Payload guarantees exactly one of those two slugs is\n * present.\n */\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: DynamoAdapter,\n { collection, globalSlug, locale, where },\n) {\n const slug = collection ?? globalSlug\n if (!slug) {\n throw new Error('payload-ddb: deleteVersions requires either `collection` or `globalSlug`.')\n }\n\n const partition = this.resolveVersionsPartition(slug)\n const matched = await queryMatching(\n this,\n partition,\n await prepareVersionsWhere(\n this,\n { kind: collection ? 'collection' : 'global', slug },\n where,\n locale,\n ),\n )\n\n await deleteItems(this, partition, matched)\n}\n"],"names":["prepareVersionsWhere","queryMatching","deleteItems","deleteVersions","collection","globalSlug","locale","where","slug","Error","partition","resolveVersionsPartition","matched","kind"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,8BAA6B;AAClE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,WAAW,QAAQ,4BAA2B;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,UAAU,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEzC,MAAMC,OAAOJ,cAAcC;IAC3B,IAAI,CAACG,MAAM;QACT,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,YAAY,IAAI,CAACC,wBAAwB,CAACH;IAChD,MAAMI,UAAU,MAAMX,cACpB,IAAI,EACJS,WACA,MAAMV,qBACJ,IAAI,EACJ;QAAEa,MAAMT,aAAa,eAAe;QAAUI;IAAK,GACnDD,OACAD;IAIJ,MAAMJ,YAAY,IAAI,EAAEQ,WAAWE;AACrC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAA;AAQlD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,EAAE,IAyClB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAA;AAUlD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,EAAE,IA4ClB,CAAA"}
package/dist/find.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { applySorts } from './utilities/applySorts.js';
2
2
  import { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js';
3
+ import { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js';
3
4
  import { queryMatching } from './utilities/queryMatching.js';
5
+ import { resolveJoins } from './utilities/resolveJoins.js';
4
6
  /**
5
7
  * v2 strategy: paginated `Query` over the collection's partition (`pk = slug`)
6
8
  * with `where` translated to `FilterExpression`, then in-memory sort and page
@@ -17,13 +19,17 @@ import { queryMatching } from './utilities/queryMatching.js';
17
19
  * (e.g. `email` for auth, `slug` for public-facing collections).
18
20
  * - Stream pages instead of materializing all matches when `pagination=false`
19
21
  * and `limit` is small.
20
- */ export const find = async function find({ collection, limit = 10, page = 1, pagination = true, sort, where }) {
22
+ */ export const find = async function find({ collection, joins, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere }) {
23
+ const where = await prepareCollectionWhere(this, collection, rawWhere, locale);
21
24
  const matched = await queryMatching(this, this.resolvePartition(collection), where);
22
25
  if (collectionHasDrafts(this, collection)) {
23
26
  const supplements = await fetchDraftsOnlySupplements(this, collection, matched, where);
24
27
  matched.push(...supplements);
25
28
  }
26
- applySorts(matched, sort);
29
+ applySorts(matched, prepareSort(this, {
30
+ kind: 'collection',
31
+ slug: collection
32
+ }, sort, locale));
27
33
  const totalDocs = matched.length;
28
34
  // `limit: 0` disables the cap. When pagination is false, limit/page still
29
35
  // control the slice; the flag only gates total-count metadata.
@@ -32,6 +38,13 @@ import { queryMatching } from './utilities/queryMatching.js';
32
38
  const start = useLimit ? (safePage - 1) * limit : 0;
33
39
  const end = useLimit ? start + limit : totalDocs;
34
40
  const docs = matched.slice(start, end);
41
+ // Only the page being returned — joins cost a query per target collection.
42
+ await resolveJoins(this, {
43
+ collectionSlug: collection,
44
+ docs,
45
+ joins,
46
+ locale
47
+ });
35
48
  const effectiveLimit = useLimit ? limit : totalDocs;
36
49
  const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1;
37
50
  const hasNextPage = pagination && useLimit && safePage < totalPages;
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * v2 strategy: paginated `Query` over the collection's partition (`pk = slug`)\n * with `where` translated to `FilterExpression`, then in-memory sort and page\n * slice. `Query` reads only the rows in this collection's partition, so we no\n * longer pay to walk the whole table.\n *\n * For collections with `versions.drafts: true`, also pull `latest=true` rows\n * from the versions partition and union in any whose parent isn't already\n * represented in the main partition. This catches drafts-only docs (created\n * but never published) that would otherwise be invisible to `find`.\n *\n * Optimizations to land later:\n * - Use `Query` against a GSI when the predicate matches an indexed key\n * (e.g. `email` for auth, `slug` for public-facing collections).\n * - Stream pages instead of materializing all matches when `pagination=false`\n * and `limit` is small.\n */\nexport const find: Find = async function find(\n this: DynamoAdapter,\n { collection, limit = 10, page = 1, pagination = true, sort, where },\n) {\n const matched = await queryMatching(this, this.resolvePartition(collection), where)\n\n if (collectionHasDrafts(this, collection)) {\n const supplements = await fetchDraftsOnlySupplements(this, collection, matched, where)\n matched.push(...supplements)\n }\n\n applySorts(matched, sort)\n\n const totalDocs = matched.length\n // `limit: 0` disables the cap. When pagination is false, limit/page still\n // control the slice; the flag only gates total-count metadata.\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","collectionHasDrafts","fetchDraftsOnlySupplements","queryMatching","find","collection","limit","page","pagination","sort","where","matched","resolvePartition","supplements","push","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,gCAA+B;AAC/F,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EAAEC,UAAU,EAAEC,QAAQ,EAAE,EAAEC,OAAO,CAAC,EAAEC,aAAa,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAEpE,MAAMC,UAAU,MAAMR,cAAc,IAAI,EAAE,IAAI,CAACS,gBAAgB,CAACP,aAAaK;IAE7E,IAAIT,oBAAoB,IAAI,EAAEI,aAAa;QACzC,MAAMQ,cAAc,MAAMX,2BAA2B,IAAI,EAAEG,YAAYM,SAASD;QAChFC,QAAQG,IAAI,IAAID;IAClB;IAEAb,WAAWW,SAASF;IAEpB,MAAMM,YAAYJ,QAAQK,MAAM;IAChC,0EAA0E;IAC1E,+DAA+D;IAC/D,MAAMC,WAAWX,QAAQ;IACzB,MAAMY,WAAWD,WAAWE,KAAKC,GAAG,CAAC,GAAGb,QAAQ;IAEhD,MAAMc,QAAQJ,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKZ,QAAQ;IAClD,MAAMgB,MAAML,WAAWI,QAAQf,QAAQS;IACvC,MAAMQ,OAAOZ,QAAQa,KAAK,CAACH,OAAOC;IAElC,MAAMG,iBAAiBR,WAAWX,QAAQS;IAC1C,MAAMW,aAAalB,cAAcS,WAAWE,KAAKC,GAAG,CAAC,GAAGD,KAAKQ,IAAI,CAACZ,YAAYT,UAAU;IACxF,MAAMsB,cAAcpB,cAAcS,YAAYC,WAAWQ;IACzD,MAAMG,cAAcrB,cAAcS,YAAYC,WAAW;IAEzD,MAAMY,SAAiD;QACrDP;QACAK;QACAC;QACAvB,OAAOmB;QACPM,UAAUH,cAAcV,WAAW,IAAI;QACvCX,MAAMW;QACNc,eAAef,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKZ,QAAQ,IAAI;QACvD2B,UAAUJ,cAAcX,WAAW,IAAI;QACvCH;QACAW;IACF;IACA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js'\nimport { prepareCollectionWhere, prepareSort } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\n\n/**\n * v2 strategy: paginated `Query` over the collection's partition (`pk = slug`)\n * with `where` translated to `FilterExpression`, then in-memory sort and page\n * slice. `Query` reads only the rows in this collection's partition, so we no\n * longer pay to walk the whole table.\n *\n * For collections with `versions.drafts: true`, also pull `latest=true` rows\n * from the versions partition and union in any whose parent isn't already\n * represented in the main partition. This catches drafts-only docs (created\n * but never published) that would otherwise be invisible to `find`.\n *\n * Optimizations to land later:\n * - Use `Query` against a GSI when the predicate matches an indexed key\n * (e.g. `email` for auth, `slug` for public-facing collections).\n * - Stream pages instead of materializing all matches when `pagination=false`\n * and `limit` is small.\n */\nexport const find: Find = async function find(\n this: DynamoAdapter,\n { collection, joins, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere },\n) {\n const where = await prepareCollectionWhere(this, collection, rawWhere, locale)\n const matched = await queryMatching(this, this.resolvePartition(collection), where)\n\n if (collectionHasDrafts(this, collection)) {\n const supplements = await fetchDraftsOnlySupplements(this, collection, matched, where)\n matched.push(...supplements)\n }\n\n applySorts(matched, prepareSort(this, { kind: 'collection', slug: collection }, sort, locale))\n\n const totalDocs = matched.length\n // `limit: 0` disables the cap. When pagination is false, limit/page still\n // control the slice; the flag only gates total-count metadata.\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n // Only the page being returned — joins cost a query per target collection.\n await resolveJoins(this, { collectionSlug: collection, docs, joins, locale })\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","collectionHasDrafts","fetchDraftsOnlySupplements","prepareCollectionWhere","prepareSort","queryMatching","resolveJoins","find","collection","joins","limit","locale","page","pagination","sort","where","rawWhere","matched","resolvePartition","supplements","push","kind","slug","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","collectionSlug","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,gCAA+B;AAC/F,SAASC,sBAAsB,EAAEC,WAAW,QAAQ,8BAA6B;AACjF,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,8BAA6B;AAE1D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EAAEC,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,EAAEC,MAAM,EAAEC,OAAO,CAAC,EAAEC,aAAa,IAAI,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAE;IAE7F,MAAMD,QAAQ,MAAMZ,uBAAuB,IAAI,EAAEK,YAAYQ,UAAUL;IACvE,MAAMM,UAAU,MAAMZ,cAAc,IAAI,EAAE,IAAI,CAACa,gBAAgB,CAACV,aAAaO;IAE7E,IAAId,oBAAoB,IAAI,EAAEO,aAAa;QACzC,MAAMW,cAAc,MAAMjB,2BAA2B,IAAI,EAAEM,YAAYS,SAASF;QAChFE,QAAQG,IAAI,IAAID;IAClB;IAEAnB,WAAWiB,SAASb,YAAY,IAAI,EAAE;QAAEiB,MAAM;QAAcC,MAAMd;IAAW,GAAGM,MAAMH;IAEtF,MAAMY,YAAYN,QAAQO,MAAM;IAChC,0EAA0E;IAC1E,+DAA+D;IAC/D,MAAMC,WAAWf,QAAQ;IACzB,MAAMgB,WAAWD,WAAWE,KAAKC,GAAG,CAAC,GAAGhB,QAAQ;IAEhD,MAAMiB,QAAQJ,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKhB,QAAQ;IAClD,MAAMoB,MAAML,WAAWI,QAAQnB,QAAQa;IACvC,MAAMQ,OAAOd,QAAQe,KAAK,CAACH,OAAOC;IAClC,2EAA2E;IAC3E,MAAMxB,aAAa,IAAI,EAAE;QAAE2B,gBAAgBzB;QAAYuB;QAAMtB;QAAOE;IAAO;IAE3E,MAAMuB,iBAAiBT,WAAWf,QAAQa;IAC1C,MAAMY,aAAatB,cAAcY,WAAWE,KAAKC,GAAG,CAAC,GAAGD,KAAKS,IAAI,CAACb,YAAYb,UAAU;IACxF,MAAM2B,cAAcxB,cAAcY,YAAYC,WAAWS;IACzD,MAAMG,cAAczB,cAAcY,YAAYC,WAAW;IAEzD,MAAMa,SAAiD;QACrDR;QACAM;QACAC;QACA5B,OAAOwB;QACPM,UAAUH,cAAcX,WAAW,IAAI;QACvCd,MAAMc;QACNe,eAAehB,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKhB,QAAQ,IAAI;QACvDgC,UAAUJ,cAAcZ,WAAW,IAAI;QACvCH;QACAY;IACF;IACA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findDistinct.d.ts","sourceRoot":"","sources":["../src/findDistinct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAyB,MAAM,SAAS,CAAA;AAQlE;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,EAAE,YA4C1B,CAAA"}
1
+ {"version":3,"file":"findDistinct.d.ts","sourceRoot":"","sources":["../src/findDistinct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAyB,MAAM,SAAS,CAAA;AASlE;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,EAAE,YA6C1B,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { applySorts } from './utilities/applySorts.js';
2
2
  import { getByPath } from './utilities/getByPath.js';
3
+ import { prepareCollectionWhere } from './utilities/prepareWhere.js';
3
4
  import { queryMatching } from './utilities/queryMatching.js';
4
5
  /**
5
6
  * v2 strategy: paginated `Query` over the collection's partition, JS `where`
@@ -10,7 +11,8 @@ import { queryMatching } from './utilities/queryMatching.js';
10
11
  * by reference, so if you `findDistinct` over a non-primitive field you'll
11
12
  * get one entry per item (no real dedup). Stringification-based dedup can
12
13
  * land if it turns out to matter.
13
- */ export const findDistinct = async function findDistinct({ collection, field, limit = 10, page = 1, sort, where }) {
14
+ */ export const findDistinct = async function findDistinct({ collection, field, limit = 10, locale, page = 1, sort, where: rawWhere }) {
15
+ const where = await prepareCollectionWhere(this, collection, rawWhere, locale);
14
16
  const matched = await queryMatching(this, this.resolvePartition(collection), where);
15
17
  const seen = new Set();
16
18
  const values = [];
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findDistinct.ts"],"sourcesContent":["import type { FindDistinct, PaginatedDistinctDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { getByPath } from './utilities/getByPath.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * v2 strategy: paginated `Query` over the collection's partition, JS `where`\n * filter has already been pushed down via `FilterExpression`, then dedup via\n * `Set` and sort + paginate the resulting value list.\n *\n * Dedup uses primitive equality. Object- or array-valued fields would compare\n * by reference, so if you `findDistinct` over a non-primitive field you'll\n * get one entry per item (no real dedup). Stringification-based dedup can\n * land if it turns out to matter.\n */\nexport const findDistinct: FindDistinct = async function findDistinct(\n this: DynamoAdapter,\n { collection, field, limit = 10, page = 1, sort, where },\n) {\n const matched = await queryMatching(this, this.resolvePartition(collection), where)\n\n const seen = new Set<unknown>()\n const values: Record<string, unknown>[] = []\n for (const item of matched) {\n const value = getByPath(item, field)\n if (value === undefined) continue\n if (seen.has(value)) continue\n seen.add(value)\n values.push({ [field]: value })\n }\n\n applySorts(values, sort)\n\n const totalDocs = values.length\n const useLimit = limit > 0\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const paged = values.slice(start, end)\n\n const hasNextPage = useLimit && safePage < totalPages\n const hasPrevPage = useLimit && safePage > 1\n\n const result: PaginatedDistinctDocs<Record<string, unknown>> = {\n values: paged,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result\n}\n"],"names":["applySorts","getByPath","queryMatching","findDistinct","collection","field","limit","page","sort","where","matched","resolvePartition","seen","Set","values","item","value","undefined","has","add","push","totalDocs","length","useLimit","effectiveLimit","totalPages","Math","max","ceil","safePage","start","end","paged","slice","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;;;;;CASC,GACD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,EAAEC,OAAO,CAAC,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAExD,MAAMC,UAAU,MAAMR,cAAc,IAAI,EAAE,IAAI,CAACS,gBAAgB,CAACP,aAAaK;IAE7E,MAAMG,OAAO,IAAIC;IACjB,MAAMC,SAAoC,EAAE;IAC5C,KAAK,MAAMC,QAAQL,QAAS;QAC1B,MAAMM,QAAQf,UAAUc,MAAMV;QAC9B,IAAIW,UAAUC,WAAW;QACzB,IAAIL,KAAKM,GAAG,CAACF,QAAQ;QACrBJ,KAAKO,GAAG,CAACH;QACTF,OAAOM,IAAI,CAAC;YAAE,CAACf,MAAM,EAAEW;QAAM;IAC/B;IAEAhB,WAAWc,QAAQN;IAEnB,MAAMa,YAAYP,OAAOQ,MAAM;IAC/B,MAAMC,WAAWjB,QAAQ;IACzB,MAAMkB,iBAAiBD,WAAWjB,QAAQe;IAC1C,MAAMI,aAAaF,WAAWG,KAAKC,GAAG,CAAC,GAAGD,KAAKE,IAAI,CAACP,YAAYf,UAAU;IAC1E,MAAMuB,WAAWN,WAAWG,KAAKC,GAAG,CAAC,GAAGpB,QAAQ;IAEhD,MAAMuB,QAAQP,WAAW,AAACM,CAAAA,WAAW,CAAA,IAAKvB,QAAQ;IAClD,MAAMyB,MAAMR,WAAWO,QAAQxB,QAAQe;IACvC,MAAMW,QAAQlB,OAAOmB,KAAK,CAACH,OAAOC;IAElC,MAAMG,cAAcX,YAAYM,WAAWJ;IAC3C,MAAMU,cAAcZ,YAAYM,WAAW;IAE3C,MAAMO,SAAyD;QAC7DtB,QAAQkB;QACRE;QACAC;QACA7B,OAAOkB;QACPa,UAAUH,cAAcL,WAAW,IAAI;QACvCtB,MAAMsB;QACNS,eAAef,WAAW,AAACM,CAAAA,WAAW,CAAA,IAAKvB,QAAQ,IAAI;QACvDiC,UAAUJ,cAAcN,WAAW,IAAI;QACvCR;QACAI;IACF;IACA,OAAOW;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findDistinct.ts"],"sourcesContent":["import type { FindDistinct, PaginatedDistinctDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { getByPath } from './utilities/getByPath.js'\nimport { prepareCollectionWhere } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\n/**\n * v2 strategy: paginated `Query` over the collection's partition, JS `where`\n * filter has already been pushed down via `FilterExpression`, then dedup via\n * `Set` and sort + paginate the resulting value list.\n *\n * Dedup uses primitive equality. Object- or array-valued fields would compare\n * by reference, so if you `findDistinct` over a non-primitive field you'll\n * get one entry per item (no real dedup). Stringification-based dedup can\n * land if it turns out to matter.\n */\nexport const findDistinct: FindDistinct = async function findDistinct(\n this: DynamoAdapter,\n { collection, field, limit = 10, locale, page = 1, sort, where: rawWhere },\n) {\n const where = await prepareCollectionWhere(this, collection, rawWhere, locale)\n const matched = await queryMatching(this, this.resolvePartition(collection), where)\n\n const seen = new Set<unknown>()\n const values: Record<string, unknown>[] = []\n for (const item of matched) {\n const value = getByPath(item, field)\n if (value === undefined) continue\n if (seen.has(value)) continue\n seen.add(value)\n values.push({ [field]: value })\n }\n\n applySorts(values, sort)\n\n const totalDocs = values.length\n const useLimit = limit > 0\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const paged = values.slice(start, end)\n\n const hasNextPage = useLimit && safePage < totalPages\n const hasPrevPage = useLimit && safePage > 1\n\n const result: PaginatedDistinctDocs<Record<string, unknown>> = {\n values: paged,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result\n}\n"],"names":["applySorts","getByPath","prepareCollectionWhere","queryMatching","findDistinct","collection","field","limit","locale","page","sort","where","rawWhere","matched","resolvePartition","seen","Set","values","item","value","undefined","has","add","push","totalDocs","length","useLimit","effectiveLimit","totalPages","Math","max","ceil","safePage","start","end","paged","slice","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,aAAa,QAAQ,+BAA8B;AAE5D;;;;;;;;;CASC,GACD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,QAAQ,EAAE,EAAEC,MAAM,EAAEC,OAAO,CAAC,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAE;IAE1E,MAAMD,QAAQ,MAAMT,uBAAuB,IAAI,EAAEG,YAAYO,UAAUJ;IACvE,MAAMK,UAAU,MAAMV,cAAc,IAAI,EAAE,IAAI,CAACW,gBAAgB,CAACT,aAAaM;IAE7E,MAAMI,OAAO,IAAIC;IACjB,MAAMC,SAAoC,EAAE;IAC5C,KAAK,MAAMC,QAAQL,QAAS;QAC1B,MAAMM,QAAQlB,UAAUiB,MAAMZ;QAC9B,IAAIa,UAAUC,WAAW;QACzB,IAAIL,KAAKM,GAAG,CAACF,QAAQ;QACrBJ,KAAKO,GAAG,CAACH;QACTF,OAAOM,IAAI,CAAC;YAAE,CAACjB,MAAM,EAAEa;QAAM;IAC/B;IAEAnB,WAAWiB,QAAQP;IAEnB,MAAMc,YAAYP,OAAOQ,MAAM;IAC/B,MAAMC,WAAWnB,QAAQ;IACzB,MAAMoB,iBAAiBD,WAAWnB,QAAQiB;IAC1C,MAAMI,aAAaF,WAAWG,KAAKC,GAAG,CAAC,GAAGD,KAAKE,IAAI,CAACP,YAAYjB,UAAU;IAC1E,MAAMyB,WAAWN,WAAWG,KAAKC,GAAG,CAAC,GAAGrB,QAAQ;IAEhD,MAAMwB,QAAQP,WAAW,AAACM,CAAAA,WAAW,CAAA,IAAKzB,QAAQ;IAClD,MAAM2B,MAAMR,WAAWO,QAAQ1B,QAAQiB;IACvC,MAAMW,QAAQlB,OAAOmB,KAAK,CAACH,OAAOC;IAElC,MAAMG,cAAcX,YAAYM,WAAWJ;IAC3C,MAAMU,cAAcZ,YAAYM,WAAW;IAE3C,MAAMO,SAAyD;QAC7DtB,QAAQkB;QACRE;QACAC;QACA/B,OAAOoB;QACPa,UAAUH,cAAcL,WAAW,IAAI;QACvCvB,MAAMuB;QACNS,eAAef,WAAW,AAACM,CAAAA,WAAW,CAAA,IAAKzB,QAAQ,IAAI;QACvDmC,UAAUJ,cAAcN,WAAW,IAAI;QACvCR;QACAI;IACF;IACA,OAAOW;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AASzC;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,UAyBxB,CAAA"}
1
+ {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUzC;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,UAyBxB,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { GetCommand } from '@aws-sdk/lib-dynamodb';
2
2
  import { matchesWhere } from './utilities/matchesWhere.js';
3
+ import { prepareGlobalWhere } from './utilities/prepareWhere.js';
3
4
  import { stripInternalKeys } from './utilities/stripInternalKeys.js';
4
5
  /**
5
6
  * Globals are singleton documents. Each lives at `pk = slug, sk = slug`, so
@@ -8,7 +9,7 @@ import { stripInternalKeys } from './utilities/stripInternalKeys.js';
8
9
  * The optional `where` is applied as a post-filter via `matchesWhere` —
9
10
  * Payload uses it sparingly (mostly for guards) and the row is already
10
11
  * in-memory, so a JS check is fine.
11
- */ export const findGlobal = async function findGlobal({ slug, where }) {
12
+ */ export const findGlobal = async function findGlobal({ slug, locale, where }) {
12
13
  const docClient = this.docClient;
13
14
  if (!docClient) {
14
15
  throw new Error('payload-ddb: docClient is not initialized — call connect() first.');
@@ -25,7 +26,7 @@ import { stripInternalKeys } from './utilities/stripInternalKeys.js';
25
26
  return null;
26
27
  }
27
28
  const item = stripInternalKeys(result.Item);
28
- if (where && !matchesWhere(item, where)) {
29
+ if (where && !matchesWhere(item, await prepareGlobalWhere(this, slug, where, locale))) {
29
30
  return null;
30
31
  }
31
32
  return item;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport { GetCommand } from '@aws-sdk/lib-dynamodb'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { matchesWhere } from './utilities/matchesWhere.js'\nimport { stripInternalKeys } from './utilities/stripInternalKeys.js'\n\n/**\n * Globals are singleton documents. Each lives at `pk = slug, sk = slug`, so\n * reads are a single `GetItem`.\n *\n * The optional `where` is applied as a post-filter via `matchesWhere` —\n * Payload uses it sparingly (mostly for guards) and the row is already\n * in-memory, so a JS check is fine.\n */\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: DynamoAdapter,\n { slug, where },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const result = await docClient.send(\n new GetCommand({\n TableName: this.tableName,\n Key: { pk: this.resolvePartition(slug), sk: slug },\n ConsistentRead: true,\n }),\n )\n\n if (!result.Item) {\n return null as never\n }\n const item = stripInternalKeys(result.Item)\n if (where && !matchesWhere(item, where)) {\n return null as never\n }\n return item as never\n}\n"],"names":["GetCommand","matchesWhere","stripInternalKeys","findGlobal","slug","where","docClient","Error","result","send","TableName","tableName","Key","pk","resolvePartition","sk","ConsistentRead","Item","item"],"mappings":"AAEA,SAASA,UAAU,QAAQ,wBAAuB;AAIlD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,iBAAiB,QAAQ,mCAAkC;AAEpE;;;;;;;CAOC,GACD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAEf,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,SAAS,MAAMF,UAAUG,IAAI,CACjC,IAAIT,WAAW;QACbU,WAAW,IAAI,CAACC,SAAS;QACzBC,KAAK;YAAEC,IAAI,IAAI,CAACC,gBAAgB,CAACV;YAAOW,IAAIX;QAAK;QACjDY,gBAAgB;IAClB;IAGF,IAAI,CAACR,OAAOS,IAAI,EAAE;QAChB,OAAO;IACT;IACA,MAAMC,OAAOhB,kBAAkBM,OAAOS,IAAI;IAC1C,IAAIZ,SAAS,CAACJ,aAAaiB,MAAMb,QAAQ;QACvC,OAAO;IACT;IACA,OAAOa;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport { GetCommand } from '@aws-sdk/lib-dynamodb'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { matchesWhere } from './utilities/matchesWhere.js'\nimport { prepareGlobalWhere } from './utilities/prepareWhere.js'\nimport { stripInternalKeys } from './utilities/stripInternalKeys.js'\n\n/**\n * Globals are singleton documents. Each lives at `pk = slug, sk = slug`, so\n * reads are a single `GetItem`.\n *\n * The optional `where` is applied as a post-filter via `matchesWhere` —\n * Payload uses it sparingly (mostly for guards) and the row is already\n * in-memory, so a JS check is fine.\n */\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: DynamoAdapter,\n { slug, locale, where },\n) {\n const docClient = this.docClient\n if (!docClient) {\n throw new Error('payload-ddb: docClient is not initialized — call connect() first.')\n }\n\n const result = await docClient.send(\n new GetCommand({\n TableName: this.tableName,\n Key: { pk: this.resolvePartition(slug), sk: slug },\n ConsistentRead: true,\n }),\n )\n\n if (!result.Item) {\n return null as never\n }\n const item = stripInternalKeys(result.Item)\n if (where && !matchesWhere(item, await prepareGlobalWhere(this, slug, where, locale))) {\n return null as never\n }\n return item as never\n}\n"],"names":["GetCommand","matchesWhere","prepareGlobalWhere","stripInternalKeys","findGlobal","slug","locale","where","docClient","Error","result","send","TableName","tableName","Key","pk","resolvePartition","sk","ConsistentRead","Item","item"],"mappings":"AAEA,SAASA,UAAU,QAAQ,wBAAuB;AAIlD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,kBAAkB,QAAQ,8BAA6B;AAChE,SAASC,iBAAiB,QAAQ,mCAAkC;AAEpE;;;;;;;CAOC,GACD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEvB,MAAMC,YAAY,IAAI,CAACA,SAAS;IAChC,IAAI,CAACA,WAAW;QACd,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,SAAS,MAAMF,UAAUG,IAAI,CACjC,IAAIX,WAAW;QACbY,WAAW,IAAI,CAACC,SAAS;QACzBC,KAAK;YAAEC,IAAI,IAAI,CAACC,gBAAgB,CAACX;YAAOY,IAAIZ;QAAK;QACjDa,gBAAgB;IAClB;IAGF,IAAI,CAACR,OAAOS,IAAI,EAAE;QAChB,OAAO;IACT;IACA,MAAMC,OAAOjB,kBAAkBO,OAAOS,IAAI;IAC1C,IAAIZ,SAAS,CAACN,aAAamB,MAAM,MAAMlB,mBAAmB,IAAI,EAAEG,MAAME,OAAOD,UAAU;QACrF,OAAO;IACT;IACA,OAAOc;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,SAAS,CAAA;AAOhE,eAAO,MAAM,kBAAkB,EAAE,kBAkChC,CAAA"}
1
+ {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,SAAS,CAAA;AAQhE,eAAO,MAAM,kBAAkB,EAAE,kBAmChC,CAAA"}
@@ -1,9 +1,17 @@
1
1
  import { applySorts } from './utilities/applySorts.js';
2
+ import { prepareSort, prepareVersionsWhere } from './utilities/prepareWhere.js';
2
3
  import { queryMatching } from './utilities/queryMatching.js';
3
- export const findGlobalVersions = async function findGlobalVersions({ global, limit = 10, page = 1, pagination = true, sort, where }) {
4
+ export const findGlobalVersions = async function findGlobalVersions({ global, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere }) {
5
+ const where = await prepareVersionsWhere(this, {
6
+ kind: 'global',
7
+ slug: global
8
+ }, rawWhere, locale);
4
9
  const partition = this.resolveVersionsPartition(global);
5
10
  const matched = await queryMatching(this, partition, where);
6
- applySorts(matched, sort);
11
+ applySorts(matched, prepareSort(this, {
12
+ kind: 'globalVersions',
13
+ slug: global
14
+ }, sort, locale));
7
15
  const totalDocs = matched.length;
8
16
  const useLimit = limit > 0;
9
17
  const safePage = useLimit ? Math.max(1, page) : 1;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: DynamoAdapter,\n { global, limit = 10, page = 1, pagination = true, sort, where },\n) {\n const partition = this.resolveVersionsPartition(global)\n const matched = await queryMatching(this, partition, where)\n applySorts(matched, sort)\n\n const totalDocs = matched.length\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","queryMatching","findGlobalVersions","global","limit","page","pagination","sort","where","partition","resolveVersionsPartition","matched","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,aAAa,QAAQ,+BAA8B;AAE5D,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,QAAQ,EAAE,EAAEC,OAAO,CAAC,EAAEC,aAAa,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAEhE,MAAMC,YAAY,IAAI,CAACC,wBAAwB,CAACP;IAChD,MAAMQ,UAAU,MAAMV,cAAc,IAAI,EAAEQ,WAAWD;IACrDR,WAAWW,SAASJ;IAEpB,MAAMK,YAAYD,QAAQE,MAAM;IAChC,MAAMC,WAAWV,QAAQ;IACzB,MAAMW,WAAWD,WAAWE,KAAKC,GAAG,CAAC,GAAGZ,QAAQ;IAEhD,MAAMa,QAAQJ,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKX,QAAQ;IAClD,MAAMe,MAAML,WAAWI,QAAQd,QAAQQ;IACvC,MAAMQ,OAAOT,QAAQU,KAAK,CAACH,OAAOC;IAElC,MAAMG,iBAAiBR,WAAWV,QAAQQ;IAC1C,MAAMW,aAAajB,cAAcQ,WAAWE,KAAKC,GAAG,CAAC,GAAGD,KAAKQ,IAAI,CAACZ,YAAYR,UAAU;IACxF,MAAMqB,cAAcnB,cAAcQ,YAAYC,WAAWQ;IACzD,MAAMG,cAAcpB,cAAcQ,YAAYC,WAAW;IAEzD,MAAMY,SAAiD;QACrDP;QACAK;QACAC;QACAtB,OAAOkB;QACPM,UAAUH,cAAcV,WAAW,IAAI;QACvCV,MAAMU;QACNc,eAAef,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKX,QAAQ,IAAI;QACvD0B,UAAUJ,cAAcX,WAAW,IAAI;QACvCH;QACAW;IACF;IACA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions, PaginatedDocs } from 'payload'\n\nimport type { DynamoAdapter } from './types.js'\n\nimport { applySorts } from './utilities/applySorts.js'\nimport { prepareSort, prepareVersionsWhere } from './utilities/prepareWhere.js'\nimport { queryMatching } from './utilities/queryMatching.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: DynamoAdapter,\n { global, limit = 10, locale, page = 1, pagination = true, sort, where: rawWhere },\n) {\n const where = await prepareVersionsWhere(this, { kind: 'global', slug: global }, rawWhere, locale)\n const partition = this.resolveVersionsPartition(global)\n const matched = await queryMatching(this, partition, where)\n applySorts(matched, prepareSort(this, { kind: 'globalVersions', slug: global }, sort, locale))\n\n const totalDocs = matched.length\n const useLimit = limit > 0\n const safePage = useLimit ? Math.max(1, page) : 1\n\n const start = useLimit ? (safePage - 1) * limit : 0\n const end = useLimit ? start + limit : totalDocs\n const docs = matched.slice(start, end)\n\n const effectiveLimit = useLimit ? limit : totalDocs\n const totalPages = pagination && useLimit ? Math.max(1, Math.ceil(totalDocs / limit)) : 1\n const hasNextPage = pagination && useLimit && safePage < totalPages\n const hasPrevPage = pagination && useLimit && safePage > 1\n\n const result: PaginatedDocs<Record<string, unknown>> = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: effectiveLimit,\n nextPage: hasNextPage ? safePage + 1 : null,\n page: safePage,\n pagingCounter: useLimit ? (safePage - 1) * limit + 1 : 1,\n prevPage: hasPrevPage ? safePage - 1 : null,\n totalDocs,\n totalPages,\n }\n return result as never\n}\n"],"names":["applySorts","prepareSort","prepareVersionsWhere","queryMatching","findGlobalVersions","global","limit","locale","page","pagination","sort","where","rawWhere","kind","slug","partition","resolveVersionsPartition","matched","totalDocs","length","useLimit","safePage","Math","max","start","end","docs","slice","effectiveLimit","totalPages","ceil","hasNextPage","hasPrevPage","result","nextPage","pagingCounter","prevPage"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,EAAEC,oBAAoB,QAAQ,8BAA6B;AAC/E,SAASC,aAAa,QAAQ,+BAA8B;AAE5D,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,QAAQ,EAAE,EAAEC,MAAM,EAAEC,OAAO,CAAC,EAAEC,aAAa,IAAI,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAE;IAElF,MAAMD,QAAQ,MAAMT,qBAAqB,IAAI,EAAE;QAAEW,MAAM;QAAUC,MAAMT;IAAO,GAAGO,UAAUL;IAC3F,MAAMQ,YAAY,IAAI,CAACC,wBAAwB,CAACX;IAChD,MAAMY,UAAU,MAAMd,cAAc,IAAI,EAAEY,WAAWJ;IACrDX,WAAWiB,SAAShB,YAAY,IAAI,EAAE;QAAEY,MAAM;QAAkBC,MAAMT;IAAO,GAAGK,MAAMH;IAEtF,MAAMW,YAAYD,QAAQE,MAAM;IAChC,MAAMC,WAAWd,QAAQ;IACzB,MAAMe,WAAWD,WAAWE,KAAKC,GAAG,CAAC,GAAGf,QAAQ;IAEhD,MAAMgB,QAAQJ,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKf,QAAQ;IAClD,MAAMmB,MAAML,WAAWI,QAAQlB,QAAQY;IACvC,MAAMQ,OAAOT,QAAQU,KAAK,CAACH,OAAOC;IAElC,MAAMG,iBAAiBR,WAAWd,QAAQY;IAC1C,MAAMW,aAAapB,cAAcW,WAAWE,KAAKC,GAAG,CAAC,GAAGD,KAAKQ,IAAI,CAACZ,YAAYZ,UAAU;IACxF,MAAMyB,cAActB,cAAcW,YAAYC,WAAWQ;IACzD,MAAMG,cAAcvB,cAAcW,YAAYC,WAAW;IAEzD,MAAMY,SAAiD;QACrDP;QACAK;QACAC;QACA1B,OAAOsB;QACPM,UAAUH,cAAcV,WAAW,IAAI;QACvCb,MAAMa;QACNc,eAAef,WAAW,AAACC,CAAAA,WAAW,CAAA,IAAKf,QAAQ,IAAI;QACvD8B,UAAUJ,cAAcX,WAAW,IAAI;QACvCH;QACAW;IACF;IACA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,OAcrB,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAStC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,OAgBrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -1,22 +1,33 @@
1
1
  import { collectionHasDrafts, fetchDraftsOnlySupplements } from './utilities/draftsFallback.js';
2
2
  import { findFirst } from './utilities/findFirst.js';
3
+ import { prepareCollectionWhere } from './utilities/prepareWhere.js';
4
+ import { resolveJoins } from './utilities/resolveJoins.js';
3
5
  /**
4
6
  * Locate one doc in `collection` matching `where`. For drafts-enabled
5
7
  * collections, fall back to the `latest=true` version row when no main
6
8
  * partition row matches — that's how drafts-only docs (saved but never
7
9
  * published) become findable.
8
- */ export const findOne = async function findOne({ collection, where }) {
10
+ */ export const findOne = async function findOne({ collection, joins, locale, where: rawWhere }) {
11
+ const where = await prepareCollectionWhere(this, collection, rawWhere, locale);
9
12
  const partition = this.resolvePartition(collection);
10
- const found = await findFirst(this, {
13
+ let doc = await findFirst(this, {
11
14
  partition,
12
15
  where
13
16
  });
14
- if (found) return found;
15
- if (collectionHasDrafts(this, collection)) {
17
+ if (!doc && collectionHasDrafts(this, collection)) {
16
18
  const supplements = await fetchDraftsOnlySupplements(this, collection, [], where);
17
- if (supplements.length > 0) return supplements[0];
19
+ doc = supplements[0] ?? null;
18
20
  }
19
- return null;
21
+ if (!doc) return null;
22
+ await resolveJoins(this, {
23
+ collectionSlug: collection,
24
+ docs: [
25
+ doc
26
+ ],
27
+ joins,
28
+ locale
29
+ });
30
+ return doc;
20
31
  };
21
32
 
22
33
  //# sourceMappingURL=findOne.js.map