@payloadcms/figma 0.0.1-alpha.43 → 0.0.1-alpha.45

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 (94) hide show
  1. package/dist/api/control-plane.d.ts.map +1 -1
  2. package/dist/api/control-plane.js +90 -54
  3. package/dist/api/control-plane.js.map +1 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +6 -0
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/debug.d.ts +8 -0
  8. package/dist/commands/debug.d.ts.map +1 -0
  9. package/dist/commands/debug.js +156 -0
  10. package/dist/commands/debug.js.map +1 -0
  11. package/dist/commands/init.d.ts.map +1 -1
  12. package/dist/commands/init.js +17 -14
  13. package/dist/commands/init.js.map +1 -1
  14. package/dist/db-content-api/generated/content-api-types.d.ts +3 -0
  15. package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -1
  16. package/dist/db-content-api/generated/content-api-types.js.map +1 -1
  17. package/dist/db-content-api/index.d.ts +2 -0
  18. package/dist/db-content-api/index.d.ts.map +1 -1
  19. package/dist/db-content-api/index.js +118 -52
  20. package/dist/db-content-api/index.js.map +1 -1
  21. package/dist/db-content-api/temp-utilities/types.d.ts +22 -0
  22. package/dist/db-content-api/temp-utilities/types.d.ts.map +1 -0
  23. package/dist/db-content-api/temp-utilities/types.js +15 -0
  24. package/dist/db-content-api/temp-utilities/types.js.map +1 -0
  25. package/dist/db-content-api/utilities/data/index.d.ts +14 -4
  26. package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
  27. package/dist/db-content-api/utilities/data/index.js +16 -8
  28. package/dist/db-content-api/utilities/data/index.js.map +1 -1
  29. package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +23 -0
  30. package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts.map +1 -0
  31. package/dist/db-content-api/utilities/data/transformPublishedLocale.js +42 -0
  32. package/dist/db-content-api/utilities/data/transformPublishedLocale.js.map +1 -0
  33. package/dist/db-content-api/utilities/locale/index.d.ts +10 -0
  34. package/dist/db-content-api/utilities/locale/index.d.ts.map +1 -0
  35. package/dist/db-content-api/utilities/locale/index.js +21 -0
  36. package/dist/db-content-api/utilities/locale/index.js.map +1 -0
  37. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts.map +1 -1
  38. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +11 -0
  39. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js.map +1 -1
  40. package/dist/db-content-api/utilities/meta/buildMeta.d.ts +18 -3
  41. package/dist/db-content-api/utilities/meta/buildMeta.d.ts.map +1 -1
  42. package/dist/db-content-api/utilities/meta/buildMeta.js +4 -1
  43. package/dist/db-content-api/utilities/meta/buildMeta.js.map +1 -1
  44. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +8 -2
  45. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts.map +1 -1
  46. package/dist/db-content-api/utilities/meta/buildPathTypes.js +41 -11
  47. package/dist/db-content-api/utilities/meta/buildPathTypes.js.map +1 -1
  48. package/dist/db-content-api/utilities/where.d.ts +8 -0
  49. package/dist/db-content-api/utilities/where.d.ts.map +1 -1
  50. package/dist/db-content-api/utilities/where.js +6 -0
  51. package/dist/db-content-api/utilities/where.js.map +1 -1
  52. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  53. package/dist/oauth/endpoints/getLoginEndpoint.js +18 -13
  54. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  55. package/dist/storage-content-api/utilities/index.d.ts +1 -1
  56. package/dist/storage-content-api/utilities/index.d.ts.map +1 -1
  57. package/dist/storage-content-api/utilities/index.js +1 -1
  58. package/dist/storage-content-api/utilities/index.js.map +1 -1
  59. package/dist/templates/README.md +1 -1
  60. package/dist/types/config.d.ts +2 -1
  61. package/dist/types/config.d.ts.map +1 -1
  62. package/dist/types/config.js +0 -2
  63. package/dist/types/config.js.map +1 -1
  64. package/dist/types.d.ts +0 -1
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js.map +1 -1
  67. package/dist/utils/lambda-config.d.ts +1 -1
  68. package/dist/utils/lambda-config.d.ts.map +1 -1
  69. package/dist/utils/lambda-config.js +2 -2
  70. package/dist/utils/lambda-config.js.map +1 -1
  71. package/dist/utils/messages.d.ts +1 -1
  72. package/dist/utils/messages.d.ts.map +1 -1
  73. package/dist/utils/messages.js +1 -0
  74. package/dist/utils/messages.js.map +1 -1
  75. package/dist/utils/package-manager.d.ts +24 -0
  76. package/dist/utils/package-manager.d.ts.map +1 -1
  77. package/dist/utils/package-manager.js +53 -0
  78. package/dist/utils/package-manager.js.map +1 -1
  79. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  80. package/dist/utils/payload-config-ast.js +7 -0
  81. package/dist/utils/payload-config-ast.js.map +1 -1
  82. package/dist/utils/payload-config-modifier.d.ts +1 -1
  83. package/dist/utils/payload-config-modifier.d.ts.map +1 -1
  84. package/dist/utils/payload-config-modifier.js +4 -3
  85. package/dist/utils/payload-config-modifier.js.map +1 -1
  86. package/dist/utils/project.d.ts +3 -2
  87. package/dist/utils/project.d.ts.map +1 -1
  88. package/dist/utils/project.js +4 -2
  89. package/dist/utils/project.js.map +1 -1
  90. package/package.json +1 -1
  91. package/dist/db-content-api/utilities/meta/index.d.ts +0 -5
  92. package/dist/db-content-api/utilities/meta/index.d.ts.map +0 -1
  93. package/dist/db-content-api/utilities/meta/index.js +0 -5
  94. package/dist/db-content-api/utilities/meta/index.js.map +0 -1
@@ -7,33 +7,10 @@ import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocum
7
7
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
8
8
  import { dataToContentAPI } from './utilities/data/index.js';
9
9
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
10
- import { buildMeta } from './utilities/meta/index.js';
10
+ import { addFallbackLocale } from './utilities/locale/index.js';
11
+ import { buildMeta } from './utilities/meta/buildMeta.js';
11
12
  import { convertPayloadWhereToContentAPI } from './utilities/where.js';
12
- async function init() {
13
- if (this.auth.mode === 'apiKey') {
14
- this.payload.logger.info('Using API Key authentication');
15
- } else if (this.auth.mode === 'tokenStore') {
16
- this.payload.logger.info('Using TokenStore authentication (local dev)');
17
- } else {
18
- this.payload.logger.info('Using Dev JWT authentication (testing)');
19
- }
20
- if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
21
- this.payload.logger.info(`---- DROPPING CONTENT API SYSTEM (${this.contentSystemId}) ----`);
22
- try {
23
- await fetch(`${this.url}/dev/clear-db`, {
24
- body: JSON.stringify({
25
- contentSystemId: this.contentSystemId
26
- }),
27
- headers: {
28
- 'Content-Type': 'application/json'
29
- },
30
- method: 'POST'
31
- });
32
- this.payload.logger.info('---- DROPPED CONTENT API SYSTEM ----');
33
- } catch (error) {
34
- this.payload.logger.warn(`Failed to drop content system: ${error.message}`);
35
- }
36
- }
13
+ async function syncCollections() {
37
14
  let existingIds;
38
15
  try {
39
16
  const { data: response, error } = await this.client.GET('/api/v0/content_systems/{contentSystemId}/collections', {
@@ -67,6 +44,19 @@ async function init() {
67
44
  }
68
45
  }
69
46
  }
47
+ async function init() {
48
+ if (this.auth.mode === 'apiKey') {
49
+ this.payload.logger.info('Using API Key authentication');
50
+ } else if (this.auth.mode === 'tokenStore') {
51
+ this.payload.logger.info('Using TokenStore authentication (local dev)');
52
+ } else {
53
+ this.payload.logger.info('Using Dev JWT authentication (testing)');
54
+ }
55
+ if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
56
+ await this.clearDatabase();
57
+ }
58
+ await syncCollections.call(this);
59
+ }
70
60
  async function createCollection(collectionId) {
71
61
  try {
72
62
  const { error } = await this.client.POST('/api/v0/content_systems/{contentSystemId}/collections', {
@@ -90,24 +80,21 @@ async function createCollection(collectionId) {
90
80
  }
91
81
  }
92
82
  }
93
- async function findMany({ collection, joins, limit, locale, page, pagination, sort, where }) {
94
- // Use provided locale or fall back to default locale from config
95
- // 'all' is a special Payload value meaning "return all locales" - don't send to Content API
96
- const localization = this.payload.config.localization;
97
- const effectiveLocale = locale && locale !== 'all' ? locale : localization ? localization.defaultLocale : undefined;
83
+ async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
84
+ const locale = addFallbackLocale(localeArg, this.payload);
98
85
  const { data: response, error } = await this.client.POST('/api/v0/documents:find', {
99
86
  body: {
100
87
  collection,
101
88
  contentSystemId: this.contentSystemId,
102
89
  join: convertPayloadJoinsToContentAPI(this.payload, collection, joins),
103
90
  limit,
104
- locale: effectiveLocale && locale !== 'all' ? effectiveLocale : undefined,
91
+ locale,
105
92
  page: page ?? 1,
106
93
  sort: addFallbackSort(sort, this.payload, collection),
107
94
  where: convertPayloadWhereToContentAPI(where ?? {}),
108
95
  ...buildMeta(this.payload, {
109
96
  collection,
110
- locale: effectiveLocale,
97
+ locale,
111
98
  where
112
99
  })
113
100
  }
@@ -139,12 +126,10 @@ async function find(args) {
139
126
  async function findVersions(args) {
140
127
  const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
141
128
  const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {
142
- parentToDocumentId: true
129
+ parentToDocumentId: true,
130
+ stripVersionPrefix: true
143
131
  });
144
- // Use provided locale or fall back to default locale from config
145
- // 'all' is a special Payload value meaning "return all locales" - don't send to Content API
146
- const localization = this.payload.config.localization;
147
- const effectiveLocale = args.locale && args.locale !== 'all' ? args.locale : localization ? localization.defaultLocale : undefined;
132
+ const locale = addFallbackLocale(args.locale, this.payload);
148
133
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {
149
134
  body: {
150
135
  collection: args.collection,
@@ -152,13 +137,13 @@ async function findVersions(args) {
152
137
  // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'
153
138
  // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
154
139
  limit: args.limit,
155
- locale: effectiveLocale && args.locale !== 'all' ? effectiveLocale : undefined,
140
+ locale,
156
141
  page: args.page ?? 1,
157
142
  sort: sortWithFallback,
158
143
  where: whereClause,
159
144
  ...buildMeta(this.payload, {
160
145
  collection: args.collection,
161
- locale: effectiveLocale,
146
+ locale,
162
147
  where: args.where
163
148
  })
164
149
  }
@@ -175,6 +160,7 @@ async function queryDrafts(args) {
175
160
  const versionsResult = await this.findVersions({
176
161
  collection: args.collection,
177
162
  limit: args.limit,
163
+ locale: args.locale,
178
164
  page: args.page,
179
165
  pagination: args.pagination,
180
166
  sort: args.sort,
@@ -207,10 +193,13 @@ async function createVersion(args) {
207
193
  collection: args.collectionSlug,
208
194
  contentSystemId: this.contentSystemId,
209
195
  versionDoc: {
196
+ createdAt: args.createdAt,
210
197
  latest: !args.autosave,
211
198
  parent: String(args.parent),
199
+ updatedAt: args.updatedAt,
212
200
  version: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {
213
- applyDefaults: true
201
+ applyDefaults: true,
202
+ publishedLocale: args.publishedLocale
214
203
  })
215
204
  }
216
205
  }
@@ -229,17 +218,30 @@ async function updateVersion(args) {
229
218
  equals: args.id
230
219
  }
231
220
  };
221
+ const locale = addFallbackLocale(args.locale, this.payload);
222
+ // versionData contains version metadata plus nested version content
223
+ const { publishedLocale, version, ...versionMeta } = args.versionData;
232
224
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {
233
225
  body: {
234
226
  collection: args.collection,
235
227
  contentSystemId: this.contentSystemId,
236
228
  createOnMissing: false,
229
+ locale,
237
230
  versionDoc: {
238
- version: dataToContentAPI(this.payload, args.collection, args.versionData)
231
+ createdAt: versionMeta.createdAt,
232
+ latest: versionMeta.latest,
233
+ parent: versionMeta.parent != null ? String(versionMeta.parent) : undefined,
234
+ updatedAt: versionMeta.updatedAt,
235
+ version: dataToContentAPI(this.payload, args.collection, version, {
236
+ publishedLocale
237
+ })
239
238
  },
240
- where: convertPayloadWhereToContentAPI(where),
239
+ where: convertPayloadWhereToContentAPI(where, {
240
+ stripVersionPrefix: true
241
+ }),
241
242
  ...buildMeta(this.payload, {
242
243
  collection: args.collection,
244
+ locale,
243
245
  where
244
246
  })
245
247
  }
@@ -260,13 +262,18 @@ async function deleteVersions(args) {
260
262
  if (!args.collection) {
261
263
  throw new Error('deleteVersions requires a collection');
262
264
  }
265
+ const locale = addFallbackLocale(args.locale, this.payload);
263
266
  const { error } = await this.client.POST('/api/v0/document_versions:delete', {
264
267
  body: {
265
268
  collection: args.collection,
266
269
  contentSystemId: this.contentSystemId,
267
- where: convertPayloadWhereToContentAPI(args.where),
270
+ locale,
271
+ where: convertPayloadWhereToContentAPI(args.where, {
272
+ stripVersionPrefix: true
273
+ }),
268
274
  ...buildMeta(this.payload, {
269
275
  collection: args.collection,
276
+ locale,
270
277
  where: args.where
271
278
  })
272
279
  }
@@ -287,7 +294,7 @@ async function findOne(args) {
287
294
  return docs[0] ?? null;
288
295
  }
289
296
  async function updateMany(args) {
290
- const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
297
+ const locale = addFallbackLocale(args.locale, this.payload);
291
298
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
292
299
  body: {
293
300
  collection: args.collection,
@@ -295,11 +302,13 @@ async function updateMany(args) {
295
302
  createOnMissing: false,
296
303
  doc: dataToContentAPI(this.payload, args.collection, args.data),
297
304
  limit: args.limit,
305
+ locale,
298
306
  returning: {},
299
- sort: sortWithFallback,
307
+ sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
300
308
  where: convertPayloadWhereToContentAPI(args.where),
301
309
  ...buildMeta(this.payload, {
302
310
  collection: args.collection,
311
+ locale,
303
312
  where: args.where
304
313
  })
305
314
  }
@@ -316,6 +325,7 @@ async function updateMany(args) {
316
325
  return null;
317
326
  }
318
327
  async function updateOne(args) {
328
+ const locale = addFallbackLocale(args.locale, this.payload);
319
329
  const where = args.where ?? {
320
330
  id: {
321
331
  equals: args.id
@@ -327,10 +337,12 @@ async function updateOne(args) {
327
337
  contentSystemId: this.contentSystemId,
328
338
  createOnMissing: false,
329
339
  doc: dataToContentAPI(this.payload, args.collection, args.data),
340
+ locale,
330
341
  returning: {},
331
342
  where: convertPayloadWhereToContentAPI(where),
332
343
  ...buildMeta(this.payload, {
333
344
  collection: args.collection,
345
+ locale,
334
346
  where
335
347
  })
336
348
  }
@@ -351,13 +363,16 @@ async function updateOne(args) {
351
363
  return unwrapDocument(this.payload, doc, args.collection);
352
364
  }
353
365
  async function deleteMany(args) {
366
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
354
367
  const { error } = await this.client.POST('/api/v0/documents:delete', {
355
368
  body: {
356
369
  collection: args.collection,
357
370
  contentSystemId: this.contentSystemId,
371
+ locale,
358
372
  where: convertPayloadWhereToContentAPI(args.where),
359
373
  ...buildMeta(this.payload, {
360
374
  collection: args.collection,
375
+ locale,
361
376
  where: args.where
362
377
  })
363
378
  }
@@ -367,14 +382,17 @@ async function deleteMany(args) {
367
382
  }
368
383
  }
369
384
  async function deleteOne(args) {
385
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
370
386
  const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {
371
387
  body: {
372
388
  collection: args.collection,
373
389
  contentSystemId: this.contentSystemId,
390
+ locale,
374
391
  returning: {},
375
392
  where: convertPayloadWhereToContentAPI(args.where),
376
393
  ...buildMeta(this.payload, {
377
394
  collection: args.collection,
395
+ locale,
378
396
  where: args.where
379
397
  })
380
398
  }
@@ -392,18 +410,26 @@ async function deleteOne(args) {
392
410
  return unwrapDocument(this.payload, doc, args.collection);
393
411
  }
394
412
  async function create(args) {
395
- const id = args.data.id || uuid();
413
+ const isGlobalCollection = args.collection.startsWith('_global-');
414
+ const customIDType = this.payload.collections[args.collection]?.customIDType;
415
+ const id = (isGlobalCollection || customIDType || this.allowIDOnCreate) && args.data.id != null && (typeof args.data.id === 'string' || typeof args.data.id === 'number') ? String(args.data.id) : uuid();
416
+ const locale = addFallbackLocale(args.locale, this.payload);
396
417
  const { data: response, error } = await this.client.POST('/api/v0/documents:create', {
397
418
  body: {
398
419
  collection: args.collection,
399
420
  contentSystemId: this.contentSystemId,
400
421
  doc: {
401
- id: String(id),
402
422
  ...dataToContentAPI(this.payload, args.collection, args.data, {
403
423
  applyDefaults: true,
404
424
  createdAt: true
405
- })
406
- }
425
+ }),
426
+ id
427
+ },
428
+ locale,
429
+ ...buildMeta(this.payload, {
430
+ collection: args.collection,
431
+ locale
432
+ })
407
433
  }
408
434
  });
409
435
  if (error) {
@@ -414,14 +440,34 @@ async function create(args) {
414
440
  }
415
441
  return unwrapDocument(this.payload, response.result, args.collection);
416
442
  }
443
+ async function clearDatabase() {
444
+ this.payload.logger.info(`---- CLEARING CONTENT API DATABASE ----`);
445
+ try {
446
+ await fetch(`${this.url}/dev/clear-db`, {
447
+ headers: {
448
+ 'Content-Type': 'application/json'
449
+ },
450
+ method: 'POST'
451
+ });
452
+ this.payload.logger.info('---- CONTENT API DATABASE CLEARED ----');
453
+ // Re-sync collections after clearing
454
+ await syncCollections.call(this);
455
+ } catch (error) {
456
+ this.payload.logger.error(`Failed to clear database: ${error.message}`);
457
+ throw error;
458
+ }
459
+ }
417
460
  async function count(args) {
461
+ const locale = addFallbackLocale(args.locale, this.payload);
418
462
  const { data: response, error } = await this.client.POST('/api/v0/documents:count', {
419
463
  body: {
420
464
  collection: args.collection,
421
465
  contentSystemId: this.contentSystemId,
466
+ locale,
422
467
  where: convertPayloadWhereToContentAPI(args.where),
423
468
  ...buildMeta(this.payload, {
424
469
  collection: args.collection,
470
+ locale,
425
471
  where: args.where
426
472
  })
427
473
  }
@@ -437,13 +483,18 @@ async function count(args) {
437
483
  };
438
484
  }
439
485
  async function countVersions(args) {
486
+ const locale = addFallbackLocale(args.locale, this.payload);
440
487
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {
441
488
  body: {
442
489
  collection: args.collection,
443
490
  contentSystemId: this.contentSystemId,
444
- where: convertPayloadWhereToContentAPI(args.where),
491
+ locale,
492
+ where: convertPayloadWhereToContentAPI(args.where, {
493
+ stripVersionPrefix: true
494
+ }),
445
495
  ...buildMeta(this.payload, {
446
496
  collection: args.collection,
497
+ locale,
447
498
  where: args.where
448
499
  })
449
500
  }
@@ -469,6 +520,7 @@ async function upsert(args) {
469
520
  if (!documentId) {
470
521
  documentId = uuid();
471
522
  }
523
+ const locale = addFallbackLocale(args.locale, this.payload);
472
524
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
473
525
  body: {
474
526
  collection: args.collection,
@@ -480,7 +532,13 @@ async function upsert(args) {
480
532
  applyDefaults: true,
481
533
  createdAt: true
482
534
  }),
483
- where: convertPayloadWhereToContentAPI(args.where)
535
+ locale,
536
+ where: convertPayloadWhereToContentAPI(args.where),
537
+ ...buildMeta(this.payload, {
538
+ collection: args.collection,
539
+ locale,
540
+ where: args.where
541
+ })
484
542
  }
485
543
  });
486
544
  if (error) {
@@ -511,6 +569,7 @@ function createGlobal(args) {
511
569
  function findGlobal(args) {
512
570
  return this.findOne({
513
571
  collection: getGlobalSlug(args.slug),
572
+ locale: args.locale,
514
573
  where: args.where ?? {}
515
574
  });
516
575
  }
@@ -532,6 +591,7 @@ function findGlobalVersions(args) {
532
591
  return this.findVersions({
533
592
  collection: getGlobalSlug(args.global),
534
593
  limit: args.limit,
594
+ locale: args.locale,
535
595
  page: args.page,
536
596
  pagination: args.pagination,
537
597
  sort: args.sort,
@@ -546,6 +606,7 @@ function createGlobalVersion(args) {
546
606
  collectionSlug: getGlobalSlug(args.globalSlug),
547
607
  createdAt: args.createdAt,
548
608
  parent: args.globalSlug,
609
+ publishedLocale: args.publishedLocale,
549
610
  updatedAt: args.updatedAt,
550
611
  versionData: args.versionData
551
612
  });
@@ -556,12 +617,14 @@ function updateGlobalVersion(args) {
556
617
  return this.updateVersion({
557
618
  id: args.id,
558
619
  collection: getGlobalSlug(args.global),
620
+ locale: args.locale,
559
621
  versionData: args.versionData
560
622
  });
561
623
  }
562
624
  // args.where is guaranteed by Payload when args.id is undefined
563
625
  return this.updateVersion({
564
626
  collection: getGlobalSlug(args.global),
627
+ locale: args.locale,
565
628
  versionData: args.versionData,
566
629
  where: args.where
567
630
  });
@@ -569,6 +632,7 @@ function updateGlobalVersion(args) {
569
632
  function countGlobalVersions(args) {
570
633
  return this.countVersions({
571
634
  collection: getGlobalSlug(args.global),
635
+ locale: args.locale,
572
636
  where: args.where
573
637
  });
574
638
  }
@@ -589,8 +653,10 @@ export const contentAPIAdapter = (opts)=>({
589
653
  client.use(createErrorMiddleware(middlewareOpts));
590
654
  return createDatabaseAdapter({
591
655
  name: 'content-api',
656
+ allowIDOnCreate: opts.allowIDOnCreate ?? false,
592
657
  auth: opts.auth,
593
658
  beginTransaction: ()=>Promise.resolve(null),
659
+ clearDatabase: clearDatabase,
594
660
  client,
595
661
  commitTransaction: async ()=>{},
596
662
  contentSystemId: opts.contentSystemId,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/db-content-api/index.ts"],"sourcesContent":["import type {\n BaseDatabaseAdapter,\n Count,\n CountArgs,\n CountGlobalVersionArgs,\n CountGlobalVersions,\n CountVersions,\n Create,\n CreateArgs,\n CreateGlobal,\n CreateGlobalArgs,\n CreateGlobalVersion,\n CreateGlobalVersionArgs,\n CreateVersion,\n CreateVersionArgs,\n DatabaseAdapterObj,\n DeleteMany,\n DeleteManyArgs,\n DeleteOne,\n DeleteOneArgs,\n DeleteVersions,\n DeleteVersionsArgs,\n Find,\n FindArgs,\n FindGlobal,\n FindGlobalArgs,\n FindGlobalVersions,\n FindGlobalVersionsArgs,\n FindOne,\n FindOneArgs,\n FindVersions,\n FindVersionsArgs,\n QueryDrafts,\n QueryDraftsArgs,\n UpdateGlobal,\n UpdateGlobalArgs,\n UpdateGlobalVersion,\n UpdateGlobalVersionArgs,\n UpdateMany,\n UpdateManyArgs,\n UpdateOne,\n UpdateOneArgs,\n UpdateVersion,\n UpdateVersionArgs,\n Upsert,\n UpsertArgs,\n} from 'payload'\n\nimport createClient from 'openapi-fetch'\nimport { createDatabaseAdapter } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { paths } from './generated/content-api-types.js'\n\nimport { getGlobalSlug } from './temp-utilities/slug.js'\nimport { addFallbackSort } from './temp-utilities/sorting.js'\nimport { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js'\nimport { type AuthMode, createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js'\nimport { dataToContentAPI } from './utilities/data/index.js'\nimport { convertPayloadJoinsToContentAPI } from './utilities/joins.js'\nimport { buildMeta } from './utilities/meta/index.js'\nimport { convertPayloadWhereToContentAPI } from './utilities/where.js'\n\ntype ContentAPIOptions = {\n auth: AuthMode\n contentSystemId: string\n url: string\n}\n\nexport type ContentAPIAdapter = {\n auth: AuthMode\n client: ReturnType<typeof createClient<paths>>\n contentSystemId: string\n url: string\n} & BaseDatabaseAdapter\n\nasync function init(this: ContentAPIAdapter) {\n if (this.auth.mode === 'apiKey') {\n this.payload.logger.info('Using API Key authentication')\n } else if (this.auth.mode === 'tokenStore') {\n this.payload.logger.info('Using TokenStore authentication (local dev)')\n } else {\n this.payload.logger.info('Using Dev JWT authentication (testing)')\n }\n\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING CONTENT API SYSTEM (${this.contentSystemId}) ----`)\n try {\n await fetch(`${this.url}/dev/clear-db`, {\n body: JSON.stringify({ contentSystemId: this.contentSystemId }),\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n })\n this.payload.logger.info('---- DROPPED CONTENT API SYSTEM ----')\n } catch (error) {\n this.payload.logger.warn(`Failed to drop content system: ${(error as Error).message}`)\n }\n }\n\n let existingIds: Set<string>\n try {\n const { data: response, error } = await this.client.GET(\n '/api/v0/content_systems/{contentSystemId}/collections',\n {\n params: { path: { contentSystemId: this.contentSystemId } },\n },\n )\n\n if (error) {\n throw new Error(JSON.stringify(error))\n }\n if (!response) {\n throw new Error('No response from collections endpoint')\n }\n\n existingIds = new Set(response.data.map((c) => c.id))\n this.payload.logger.info(`Found ${existingIds.size} existing collections`)\n } catch (error) {\n this.payload.logger.warn(\n `Failed to fetch collections, will attempt to create all: ${(error as Error).message}`,\n )\n existingIds = new Set()\n }\n\n for (const collection of this.payload.config.collections) {\n if (!existingIds.has(collection.slug)) {\n await createCollection.call(this, collection.slug)\n }\n }\n\n for (const global of this.payload.config.globals || []) {\n const globalId = `_global-${global.slug}`\n if (!existingIds.has(globalId)) {\n await createCollection.call(this, globalId)\n }\n }\n}\n\nasync function createCollection(this: ContentAPIAdapter, collectionId: string) {\n try {\n const { error } = await this.client.POST(\n '/api/v0/content_systems/{contentSystemId}/collections',\n {\n body: { id: collectionId },\n params: { path: { contentSystemId: this.contentSystemId } },\n },\n )\n\n if (error) {\n throw new Error(JSON.stringify(error))\n }\n this.payload.logger.info(`Created collection: ${collectionId}`)\n } catch (error) {\n const errorMessage = (error as Error).message\n if (!errorMessage.includes('already exists') && !errorMessage.includes('409')) {\n this.payload.logger.warn(`Failed to create collection ${collectionId}: ${errorMessage}`)\n }\n }\n}\n\nasync function findMany(\n this: ContentAPIAdapter,\n {\n collection,\n joins,\n limit,\n locale,\n page,\n pagination,\n sort,\n where,\n // Not yet passed to Content API:\n // - select: supported by Content API, pass-through possible\n // Not supported by Content API:\n // - draftsEnabled, versions, projection\n }: Pick<FindArgs, 'joins' | 'locale' | 'pagination' | 'sort' | 'where'> &\n Required<Pick<FindArgs, 'collection' | 'limit' | 'page'>>,\n) {\n // Use provided locale or fall back to default locale from config\n // 'all' is a special Payload value meaning \"return all locales\" - don't send to Content API\n const localization = this.payload.config.localization\n const effectiveLocale =\n locale && locale !== 'all' ? locale : localization ? localization.defaultLocale : undefined\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:find', {\n body: {\n collection,\n contentSystemId: this.contentSystemId,\n join: convertPayloadJoinsToContentAPI(this.payload, collection, joins),\n limit,\n locale: effectiveLocale && locale !== 'all' ? effectiveLocale : undefined,\n page: page ?? 1,\n sort: addFallbackSort(sort, this.payload, collection),\n where: convertPayloadWhereToContentAPI(where ?? {}),\n ...buildMeta(this.payload, { collection, locale: effectiveLocale, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API findMany error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from findMany')\n }\n\n return unwrapFindResponse(this.payload, response.result, collection)\n}\n\nasync function find(this: ContentAPIAdapter, args: FindArgs) {\n const collectionConfig = this.payload.config.collections.find((c) => c.slug === args.collection)\n return findMany.call(this, {\n collection: args.collection,\n joins: args.joins,\n // TODO: FindArgs.limit should be 'number' not 'number | undefined'\n // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)\n limit: args.limit!,\n locale: args.locale,\n page: args.page ?? 1,\n pagination: args.pagination,\n sort: args.sort || collectionConfig?.defaultSort,\n where: args.where,\n })\n}\n\n// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183\nasync function findVersions(this: ContentAPIAdapter, args: Omit<FindVersionsArgs, 'skip'>) {\n const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection)\n\n const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {\n parentToDocumentId: true,\n })\n\n // Use provided locale or fall back to default locale from config\n // 'all' is a special Payload value meaning \"return all locales\" - don't send to Content API\n const localization = this.payload.config.localization\n const effectiveLocale =\n args.locale && args.locale !== 'all'\n ? args.locale\n : localization\n ? localization.defaultLocale\n : undefined\n\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'\n // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)\n limit: args.limit!,\n locale: effectiveLocale && args.locale !== 'all' ? effectiveLocale : undefined,\n page: args.page ?? 1,\n sort: sortWithFallback,\n where: whereClause,\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale: effectiveLocale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API findVersions error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from findVersions')\n }\n\n return unwrapFindResponse(this.payload, response.result, args.collection)\n}\n\nasync function queryDrafts(this: ContentAPIAdapter, args: QueryDraftsArgs) {\n const versionsResult = await this.findVersions({\n collection: args.collection,\n limit: args.limit,\n page: args.page,\n pagination: args.pagination,\n sort: args.sort,\n where: { ...args.where, latest: { equals: true } },\n })\n\n // queryDrafts should return documents with fields at root level, not nested in 'version'\n // So we need to unwrap the version structure and merge version fields to root\n const docs = versionsResult.docs.map((versionDoc) => {\n const { version, ...versionMeta } = versionDoc\n return {\n ...versionMeta,\n ...version,\n // Keep version metadata like parent, but document fields take precedence\n id: version.id, // Document ID, not version ID\n }\n })\n\n return {\n ...versionsResult,\n docs,\n }\n}\n\nasync function createVersion(this: ContentAPIAdapter, args: CreateVersionArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:create', {\n body: {\n collection: args.collectionSlug,\n contentSystemId: this.contentSystemId,\n versionDoc: {\n latest: !args.autosave,\n parent: String(args.parent),\n version: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {\n applyDefaults: true,\n }),\n },\n },\n })\n\n if (error) {\n throw new Error(`Content API createVersion error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from createVersion')\n }\n return unwrapDocument(this.payload, response.result, args.collectionSlug)\n}\n\nasync function updateVersion(this: ContentAPIAdapter, args: UpdateVersionArgs) {\n const where = args.where ?? { id: { equals: args.id } }\n\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n versionDoc: {\n version: dataToContentAPI(this.payload, args.collection, args.versionData),\n },\n where: convertPayloadWhereToContentAPI(where),\n ...buildMeta(this.payload, { collection: args.collection, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateVersion error: ${JSON.stringify(error)}`)\n }\n if (!response?.result || !('data' in response.result)) {\n throw new Error('No document data in updateVersion response')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function deleteVersions(this: ContentAPIAdapter, args: DeleteVersionsArgs) {\n if (!args.collection) {\n throw new Error('deleteVersions requires a collection')\n }\n\n const { error } = await this.client.POST('/api/v0/document_versions:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteVersions error: ${JSON.stringify(error)}`)\n }\n}\n\nasync function findOne(this: ContentAPIAdapter, args: FindOneArgs) {\n const { docs } = await this.find({\n collection: args.collection,\n joins: args.joins,\n limit: 1,\n locale: args.locale,\n pagination: false,\n where: args.where,\n })\n return docs[0] ?? null\n}\n\nasync function updateMany(this: ContentAPIAdapter, args: UpdateManyArgs) {\n const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n doc: dataToContentAPI(this.payload, args.collection, args.data),\n limit: args.limit,\n returning: {},\n sort: sortWithFallback,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateMany error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from updateMany')\n }\n\n if (response.result && 'data' in response.result) {\n return response.result.data.map((doc) => unwrapDocument(this.payload, doc, args.collection))\n }\n return null\n}\n\nasync function updateOne(this: ContentAPIAdapter, args: UpdateOneArgs) {\n const where = args.where ?? { id: { equals: args.id } }\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n doc: dataToContentAPI(this.payload, args.collection, args.data),\n returning: {},\n where: convertPayloadWhereToContentAPI(where),\n ...buildMeta(this.payload, { collection: args.collection, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateOne error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from updateOne')\n }\n if (!response.result || !('data' in response.result)) {\n throw new Error('Unexpected response format from updateOne')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function deleteMany(this: ContentAPIAdapter, args: DeleteManyArgs) {\n const { error } = await this.client.POST('/api/v0/documents:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteMany error: ${JSON.stringify(error)}`)\n }\n}\n\nasync function deleteOne(this: ContentAPIAdapter, args: DeleteOneArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n returning: {}, // Request deleted document back\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteOne error: ${JSON.stringify(error)}`)\n }\n if (!response?.result || !('data' in response.result)) {\n throw new Error('No document data in deleteOne response')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function create(this: ContentAPIAdapter, args: CreateArgs) {\n const id = (args.data.id as string | undefined) || uuid()\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:create', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n doc: {\n id: String(id),\n ...dataToContentAPI(this.payload, args.collection, args.data, {\n applyDefaults: true,\n createdAt: true,\n }),\n },\n },\n })\n\n if (error) {\n throw new Error(`Content API create error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from create')\n }\n return unwrapDocument(this.payload, response.result, args.collection)\n}\n\nasync function count(this: ContentAPIAdapter, args: CountArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/documents:count', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API count error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from count')\n }\n\n return { totalDocs: response.result.count }\n}\n\nasync function countVersions(this: ContentAPIAdapter, args: CountArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, { collection: args.collection, where: args.where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API countVersions error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from countVersions')\n }\n\n return { totalDocs: response.result.count }\n}\n\nasync function upsert(this: ContentAPIAdapter, args: UpsertArgs) {\n let documentId = args.data.id as string | undefined\n if (!documentId && args.where && 'id' in args.where) {\n const idClause = (args.where as Record<string, unknown>).id as Record<string, unknown>\n if (idClause && 'equals' in idClause) {\n documentId = idClause.equals as string\n }\n }\n if (!documentId) {\n documentId = uuid()\n }\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: { id: documentId },\n doc: dataToContentAPI(this.payload, args.collection, args.data, {\n applyDefaults: true,\n createdAt: true,\n }),\n where: convertPayloadWhereToContentAPI(args.where),\n },\n })\n\n if (error) {\n throw new Error(`Content API upsert error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from upsert')\n }\n if (!response.result || !('data' in response.result)) {\n throw new Error('Unexpected response format from upsert')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n throw new Error('No document data in upsert response')\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nfunction createGlobal(this: ContentAPIAdapter, args: CreateGlobalArgs) {\n return this.create({\n collection: getGlobalSlug(args.slug),\n data: { ...args.data, id: args.slug, globalType: args.slug },\n })\n}\n\nfunction findGlobal(this: ContentAPIAdapter, args: FindGlobalArgs) {\n return this.findOne({ collection: getGlobalSlug(args.slug), where: args.where ?? {} })\n}\n\nasync function updateGlobal(this: ContentAPIAdapter, args: UpdateGlobalArgs) {\n // Use upsert to ensure the global exists\n // Use slug as the consistent document ID for globals\n return this.upsert({\n collection: getGlobalSlug(args.slug),\n data: args.data,\n where: { id: { equals: args.slug } },\n })\n}\n\n// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183\nfunction findGlobalVersions(this: ContentAPIAdapter, args: Omit<FindGlobalVersionsArgs, 'skip'>) {\n return this.findVersions({\n collection: getGlobalSlug(args.global),\n limit: args.limit,\n page: args.page,\n pagination: args.pagination,\n sort: args.sort,\n where: args.where,\n })\n}\n\nfunction createGlobalVersion(this: ContentAPIAdapter, args: CreateGlobalVersionArgs) {\n // For globals, use the globalSlug as the consistent document ID\n // This matches what we do in updateGlobal\n return this.createVersion({\n autosave: args.autosave,\n collectionSlug: getGlobalSlug(args.globalSlug),\n createdAt: args.createdAt,\n parent: args.globalSlug,\n updatedAt: args.updatedAt,\n versionData: args.versionData,\n })\n}\n\nfunction updateGlobalVersion(this: ContentAPIAdapter, args: UpdateGlobalVersionArgs) {\n // UpdateVersion requires either id OR where, not both\n if (args.id !== undefined) {\n return this.updateVersion({\n id: args.id,\n collection: getGlobalSlug(args.global),\n versionData: args.versionData,\n })\n }\n // args.where is guaranteed by Payload when args.id is undefined\n return this.updateVersion({\n collection: getGlobalSlug(args.global),\n versionData: args.versionData,\n where: args.where,\n })\n}\n\nfunction countGlobalVersions(this: ContentAPIAdapter, args: CountGlobalVersionArgs) {\n return this.countVersions({ collection: getGlobalSlug(args.global), where: args.where })\n}\n\nexport const contentAPIAdapter = (opts: ContentAPIOptions): DatabaseAdapterObj => ({\n name: 'content-api',\n defaultIDType: 'text',\n init: ({ payload }) => {\n const client = createClient<paths>({ baseUrl: opts.url })\n\n const middlewareOpts = {\n auth: opts.auth,\n contentSystemId: opts.contentSystemId,\n logger: payload.logger,\n url: opts.url,\n }\n\n client.use(createAuthMiddleware(middlewareOpts))\n client.use(createErrorMiddleware(middlewareOpts))\n\n return createDatabaseAdapter<ContentAPIAdapter>({\n name: 'content-api',\n auth: opts.auth,\n beginTransaction: () => Promise.resolve(null),\n client,\n commitTransaction: async () => {},\n contentSystemId: opts.contentSystemId,\n count: count as Count,\n countGlobalVersions: countGlobalVersions as CountGlobalVersions,\n countVersions: countVersions as CountVersions,\n create: create as Create,\n createGlobal: createGlobal as CreateGlobal,\n createGlobalVersion: createGlobalVersion as CreateGlobalVersion,\n createVersion: createVersion as CreateVersion,\n defaultIDType: 'text',\n deleteMany: deleteMany as DeleteMany,\n deleteOne: deleteOne as DeleteOne,\n deleteVersions: deleteVersions as DeleteVersions,\n find: find as Find,\n findDistinct: () =>\n Promise.reject(new Error('findDistinct is not yet implemented for Content API adapter')),\n findGlobal: findGlobal as FindGlobal,\n findGlobalVersions: findGlobalVersions as FindGlobalVersions,\n findOne: findOne as FindOne,\n findVersions: findVersions as FindVersions,\n init,\n packageName: '@payloadcms/db-content-api',\n payload,\n queryDrafts: queryDrafts as QueryDrafts,\n rollbackTransaction: async () => {},\n updateGlobal: updateGlobal as UpdateGlobal,\n updateGlobalVersion: updateGlobalVersion as UpdateGlobalVersion,\n updateMany: updateMany as UpdateMany,\n updateOne: updateOne as UpdateOne,\n updateVersion: updateVersion as UpdateVersion,\n upsert: upsert as Upsert,\n url: opts.url,\n })\n },\n})\n"],"names":["createClient","createDatabaseAdapter","v4","uuid","getGlobalSlug","addFallbackSort","unwrapDocument","unwrapFindResponse","createAuthMiddleware","createErrorMiddleware","dataToContentAPI","convertPayloadJoinsToContentAPI","buildMeta","convertPayloadWhereToContentAPI","init","auth","mode","payload","logger","info","process","env","PAYLOAD_DROP_DATABASE","contentSystemId","fetch","url","body","JSON","stringify","headers","method","error","warn","message","existingIds","data","response","client","GET","params","path","Error","Set","map","c","id","size","collection","config","collections","has","slug","createCollection","call","global","globals","globalId","collectionId","POST","errorMessage","includes","findMany","joins","limit","locale","page","pagination","sort","where","localization","effectiveLocale","defaultLocale","undefined","join","result","find","args","collectionConfig","defaultSort","findVersions","sortWithFallback","whereClause","parentToDocumentId","queryDrafts","versionsResult","latest","equals","docs","versionDoc","version","versionMeta","createVersion","collectionSlug","autosave","parent","String","versionData","applyDefaults","updateVersion","createOnMissing","doc","deleteVersions","findOne","updateMany","returning","updateOne","deleteMany","deleteOne","create","createdAt","count","totalDocs","countVersions","upsert","documentId","idClause","createGlobal","globalType","findGlobal","updateGlobal","findGlobalVersions","createGlobalVersion","globalSlug","updatedAt","updateGlobalVersion","countGlobalVersions","contentAPIAdapter","opts","name","defaultIDType","baseUrl","middlewareOpts","use","beginTransaction","Promise","resolve","commitTransaction","findDistinct","reject","packageName","rollbackTransaction"],"mappings":"AAgDA,OAAOA,kBAAkB,gBAAe;AACxC,SAASC,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,qCAAoC;AACvF,SAAwBC,oBAAoB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAChG,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,+BAA+B,QAAQ,uBAAsB;AACtE,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,+BAA+B,QAAQ,uBAAsB;AAetE,eAAeC;IACb,IAAI,IAAI,CAACC,IAAI,CAACC,IAAI,KAAK,UAAU;QAC/B,IAAI,CAACC,OAAO,CAAC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sH,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxClG;gBACAmG,mBAAmB,WAAa;gBAChCjH,iBAAiBwG,KAAKxG,eAAe;gBACrCuF,OAAOA;gBACPe,qBAAqBA;gBACrBb,eAAeA;gBACfJ,QAAQA;gBACRQ,cAAcA;gBACdK,qBAAqBA;gBACrB9B,eAAeA;gBACfsC,eAAe;gBACfvB,YAAYA;gBACZC,WAAWA;gBACXN,gBAAgBA;gBAChB1B,MAAMA;gBACN8D,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAIjG,MAAM;gBAC3B6E,YAAYA;gBACZE,oBAAoBA;gBACpBlB,SAASA;gBACTvB,cAAcA;gBACdjE;gBACA6H,aAAa;gBACb1H;gBACAkE,aAAaA;gBACbyD,qBAAqB,WAAa;gBAClCrB,cAAcA;gBACdK,qBAAqBA;gBACrBrB,YAAYA;gBACZE,WAAWA;gBACXP,eAAeA;gBACfe,QAAQA;gBACRxF,KAAKsG,KAAKtG,GAAG;YACf;QACF;IACF,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/db-content-api/index.ts"],"sourcesContent":["import type {\n BaseDatabaseAdapter,\n Count,\n CountArgs,\n CountGlobalVersionArgs,\n CountGlobalVersions,\n CountVersions,\n Create,\n CreateArgs,\n CreateGlobal,\n CreateGlobalArgs,\n CreateGlobalVersion,\n CreateGlobalVersionArgs,\n CreateVersion,\n CreateVersionArgs,\n DatabaseAdapterObj,\n DeleteMany,\n DeleteManyArgs,\n DeleteOne,\n DeleteOneArgs,\n DeleteVersions,\n DeleteVersionsArgs,\n Find,\n FindArgs,\n FindGlobal,\n FindGlobalArgs,\n FindGlobalVersions,\n FindGlobalVersionsArgs,\n FindOne,\n FindOneArgs,\n FindVersions,\n FindVersionsArgs,\n QueryDrafts,\n QueryDraftsArgs,\n UpdateGlobal,\n UpdateGlobalArgs,\n UpdateGlobalVersion,\n UpdateGlobalVersionArgs,\n UpdateMany,\n UpdateManyArgs,\n UpdateOne,\n UpdateOneArgs,\n UpdateVersion,\n UpdateVersionArgs,\n Upsert,\n UpsertArgs,\n} from 'payload'\n\nimport createClient from 'openapi-fetch'\nimport { createDatabaseAdapter } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { paths } from './generated/content-api-types.js'\n\nimport { getGlobalSlug } from './temp-utilities/slug.js'\nimport { addFallbackSort } from './temp-utilities/sorting.js'\nimport { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js'\nimport { type AuthMode, createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js'\nimport { dataToContentAPI } from './utilities/data/index.js'\nimport { convertPayloadJoinsToContentAPI } from './utilities/joins.js'\nimport { addFallbackLocale } from './utilities/locale/index.js'\nimport { buildMeta } from './utilities/meta/buildMeta.js'\nimport { convertPayloadWhereToContentAPI } from './utilities/where.js'\n\ntype ContentAPIOptions = {\n allowIDOnCreate?: boolean\n auth: AuthMode\n contentSystemId: string\n url: string\n}\n\nexport type ContentAPIAdapter = {\n auth: AuthMode\n clearDatabase: () => Promise<void>\n client: ReturnType<typeof createClient<paths>>\n contentSystemId: string\n url: string\n} & BaseDatabaseAdapter\n\nasync function syncCollections(this: ContentAPIAdapter) {\n let existingIds: Set<string>\n try {\n const { data: response, error } = await this.client.GET(\n '/api/v0/content_systems/{contentSystemId}/collections',\n {\n params: { path: { contentSystemId: this.contentSystemId } },\n },\n )\n\n if (error) {\n throw new Error(JSON.stringify(error))\n }\n if (!response) {\n throw new Error('No response from collections endpoint')\n }\n\n existingIds = new Set(response.data.map((c) => c.id))\n this.payload.logger.info(`Found ${existingIds.size} existing collections`)\n } catch (error) {\n this.payload.logger.warn(\n `Failed to fetch collections, will attempt to create all: ${(error as Error).message}`,\n )\n existingIds = new Set()\n }\n\n for (const collection of this.payload.config.collections) {\n if (!existingIds.has(collection.slug)) {\n await createCollection.call(this, collection.slug)\n }\n }\n\n for (const global of this.payload.config.globals || []) {\n const globalId = `_global-${global.slug}`\n if (!existingIds.has(globalId)) {\n await createCollection.call(this, globalId)\n }\n }\n}\n\nasync function init(this: ContentAPIAdapter) {\n if (this.auth.mode === 'apiKey') {\n this.payload.logger.info('Using API Key authentication')\n } else if (this.auth.mode === 'tokenStore') {\n this.payload.logger.info('Using TokenStore authentication (local dev)')\n } else {\n this.payload.logger.info('Using Dev JWT authentication (testing)')\n }\n\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n await this.clearDatabase()\n }\n\n await syncCollections.call(this)\n}\n\nasync function createCollection(this: ContentAPIAdapter, collectionId: string) {\n try {\n const { error } = await this.client.POST(\n '/api/v0/content_systems/{contentSystemId}/collections',\n {\n body: { id: collectionId },\n params: { path: { contentSystemId: this.contentSystemId } },\n },\n )\n\n if (error) {\n throw new Error(JSON.stringify(error))\n }\n this.payload.logger.info(`Created collection: ${collectionId}`)\n } catch (error) {\n const errorMessage = (error as Error).message\n if (!errorMessage.includes('already exists') && !errorMessage.includes('409')) {\n this.payload.logger.warn(`Failed to create collection ${collectionId}: ${errorMessage}`)\n }\n }\n}\n\nasync function findMany(\n this: ContentAPIAdapter,\n {\n collection,\n joins,\n limit,\n locale: localeArg,\n page,\n pagination: _pagination,\n sort,\n where,\n // Not yet passed to Content API:\n // - select: supported by Content API, pass-through possible\n // Not supported by Content API:\n // - draftsEnabled, versions, projection\n }: Pick<FindArgs, 'joins' | 'locale' | 'pagination' | 'sort' | 'where'> &\n Required<Pick<FindArgs, 'collection' | 'limit' | 'page'>>,\n) {\n const locale = addFallbackLocale(localeArg, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:find', {\n body: {\n collection,\n contentSystemId: this.contentSystemId,\n join: convertPayloadJoinsToContentAPI(this.payload, collection, joins),\n limit,\n locale,\n page: page ?? 1,\n sort: addFallbackSort(sort, this.payload, collection),\n where: convertPayloadWhereToContentAPI(where ?? {}),\n ...buildMeta(this.payload, { collection, locale, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API findMany error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from findMany')\n }\n\n return unwrapFindResponse(this.payload, response.result, collection)\n}\n\nasync function find(this: ContentAPIAdapter, args: FindArgs) {\n const collectionConfig = this.payload.config.collections.find((c) => c.slug === args.collection)\n return findMany.call(this, {\n collection: args.collection,\n joins: args.joins,\n // TODO: FindArgs.limit should be 'number' not 'number | undefined'\n // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)\n limit: args.limit!,\n locale: args.locale,\n page: args.page ?? 1,\n pagination: args.pagination,\n sort: args.sort || collectionConfig?.defaultSort,\n where: args.where,\n })\n}\n\n// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183\nasync function findVersions(this: ContentAPIAdapter, args: Omit<FindVersionsArgs, 'skip'>) {\n const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection)\n\n const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {\n parentToDocumentId: true,\n stripVersionPrefix: true,\n })\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'\n // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)\n limit: args.limit!,\n locale,\n page: args.page ?? 1,\n sort: sortWithFallback,\n where: whereClause,\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API findVersions error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from findVersions')\n }\n\n return unwrapFindResponse(this.payload, response.result, args.collection)\n}\n\nasync function queryDrafts(this: ContentAPIAdapter, args: QueryDraftsArgs) {\n const versionsResult = await this.findVersions({\n collection: args.collection,\n limit: args.limit,\n locale: args.locale,\n page: args.page,\n pagination: args.pagination,\n sort: args.sort,\n where: { ...args.where, latest: { equals: true } },\n })\n\n // queryDrafts should return documents with fields at root level, not nested in 'version'\n // So we need to unwrap the version structure and merge version fields to root\n const docs = versionsResult.docs.map((versionDoc) => {\n const { version, ...versionMeta } = versionDoc\n return {\n ...versionMeta,\n ...version,\n // Keep version metadata like parent, but document fields take precedence\n id: version.id, // Document ID, not version ID\n }\n })\n\n return {\n ...versionsResult,\n docs,\n }\n}\n\nasync function createVersion(this: ContentAPIAdapter, args: CreateVersionArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:create', {\n body: {\n collection: args.collectionSlug,\n contentSystemId: this.contentSystemId,\n versionDoc: {\n createdAt: args.createdAt,\n latest: !args.autosave,\n parent: String(args.parent),\n updatedAt: args.updatedAt,\n version: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {\n applyDefaults: true,\n publishedLocale: args.publishedLocale,\n }),\n },\n },\n })\n\n if (error) {\n throw new Error(`Content API createVersion error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from createVersion')\n }\n return unwrapDocument(this.payload, response.result, args.collectionSlug)\n}\n\nasync function updateVersion(this: ContentAPIAdapter, args: UpdateVersionArgs) {\n const where = args.where ?? { id: { equals: args.id } }\n const locale = addFallbackLocale(args.locale, this.payload)\n\n // versionData contains version metadata plus nested version content\n const { publishedLocale, version, ...versionMeta } = args.versionData\n\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n locale,\n versionDoc: {\n createdAt: versionMeta.createdAt,\n latest: versionMeta.latest,\n parent: versionMeta.parent != null ? String(versionMeta.parent) : undefined,\n updatedAt: versionMeta.updatedAt,\n version: dataToContentAPI(this.payload, args.collection, version, { publishedLocale }),\n },\n where: convertPayloadWhereToContentAPI(where, { stripVersionPrefix: true }),\n ...buildMeta(this.payload, { collection: args.collection, locale, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateVersion error: ${JSON.stringify(error)}`)\n }\n if (!response?.result || !('data' in response.result)) {\n throw new Error('No document data in updateVersion response')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function deleteVersions(this: ContentAPIAdapter, args: DeleteVersionsArgs) {\n if (!args.collection) {\n throw new Error('deleteVersions requires a collection')\n }\n\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { error } = await this.client.POST('/api/v0/document_versions:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n locale,\n where: convertPayloadWhereToContentAPI(args.where, { stripVersionPrefix: true }),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteVersions error: ${JSON.stringify(error)}`)\n }\n}\n\nasync function findOne(this: ContentAPIAdapter, args: FindOneArgs) {\n const { docs } = await this.find({\n collection: args.collection,\n joins: args.joins,\n limit: 1,\n locale: args.locale,\n pagination: false,\n where: args.where,\n })\n return docs[0] ?? null\n}\n\nasync function updateMany(this: ContentAPIAdapter, args: UpdateManyArgs) {\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n doc: dataToContentAPI(this.payload, args.collection, args.data),\n limit: args.limit,\n locale,\n returning: {},\n sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateMany error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from updateMany')\n }\n\n if (response.result && 'data' in response.result) {\n return response.result.data.map((doc) => unwrapDocument(this.payload, doc, args.collection))\n }\n return null\n}\n\nasync function updateOne(this: ContentAPIAdapter, args: UpdateOneArgs) {\n const locale = addFallbackLocale(args.locale, this.payload)\n const where = args.where ?? { id: { equals: args.id } }\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n doc: dataToContentAPI(this.payload, args.collection, args.data),\n locale,\n returning: {},\n where: convertPayloadWhereToContentAPI(where),\n ...buildMeta(this.payload, { collection: args.collection, locale, where }),\n },\n })\n\n if (error) {\n throw new Error(`Content API updateOne error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from updateOne')\n }\n if (!response.result || !('data' in response.result)) {\n throw new Error('Unexpected response format from updateOne')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function deleteMany(this: ContentAPIAdapter, args: DeleteManyArgs) {\n const locale = addFallbackLocale(args.req?.locale, this.payload)\n\n const { error } = await this.client.POST('/api/v0/documents:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n locale,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteMany error: ${JSON.stringify(error)}`)\n }\n}\n\nasync function deleteOne(this: ContentAPIAdapter, args: DeleteOneArgs) {\n const locale = addFallbackLocale(args.req?.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n locale,\n returning: {}, // Request deleted document back\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API deleteOne error: ${JSON.stringify(error)}`)\n }\n if (!response?.result || !('data' in response.result)) {\n throw new Error('No document data in deleteOne response')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n return null\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nasync function create(this: ContentAPIAdapter, args: CreateArgs) {\n const isGlobalCollection = args.collection.startsWith('_global-')\n const customIDType = this.payload.collections[args.collection]?.customIDType\n const id =\n (isGlobalCollection || customIDType || this.allowIDOnCreate) &&\n args.data.id != null &&\n (typeof args.data.id === 'string' || typeof args.data.id === 'number')\n ? String(args.data.id)\n : uuid()\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:create', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n doc: {\n ...dataToContentAPI(this.payload, args.collection, args.data, {\n applyDefaults: true,\n createdAt: true,\n }),\n id,\n },\n locale,\n ...buildMeta(this.payload, { collection: args.collection, locale }),\n },\n })\n\n if (error) {\n throw new Error(`Content API create error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from create')\n }\n return unwrapDocument(this.payload, response.result, args.collection)\n}\n\nasync function clearDatabase(this: ContentAPIAdapter) {\n this.payload.logger.info(`---- CLEARING CONTENT API DATABASE ----`)\n try {\n await fetch(`${this.url}/dev/clear-db`, {\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n })\n this.payload.logger.info('---- CONTENT API DATABASE CLEARED ----')\n\n // Re-sync collections after clearing\n await syncCollections.call(this)\n } catch (error) {\n this.payload.logger.error(`Failed to clear database: ${(error as Error).message}`)\n throw error\n }\n}\n\nasync function count(this: ContentAPIAdapter, args: CountArgs) {\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:count', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n locale,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API count error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from count')\n }\n\n return { totalDocs: response.result.count }\n}\n\nasync function countVersions(this: ContentAPIAdapter, args: CountArgs) {\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n locale,\n where: convertPayloadWhereToContentAPI(args.where, { stripVersionPrefix: true }),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API countVersions error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from countVersions')\n }\n\n return { totalDocs: response.result.count }\n}\n\nasync function upsert(this: ContentAPIAdapter, args: UpsertArgs) {\n let documentId = args.data.id as string | undefined\n if (!documentId && args.where && 'id' in args.where) {\n const idClause = (args.where as Record<string, unknown>).id as Record<string, unknown>\n if (idClause && 'equals' in idClause) {\n documentId = idClause.equals as string\n }\n }\n if (!documentId) {\n documentId = uuid()\n }\n\n const locale = addFallbackLocale(args.locale, this.payload)\n\n const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collection: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: { id: documentId },\n doc: dataToContentAPI(this.payload, args.collection, args.data, {\n applyDefaults: true,\n createdAt: true,\n }),\n locale,\n where: convertPayloadWhereToContentAPI(args.where),\n ...buildMeta(this.payload, {\n collection: args.collection,\n locale,\n where: args.where,\n }),\n },\n })\n\n if (error) {\n throw new Error(`Content API upsert error: ${JSON.stringify(error)}`)\n }\n if (!response) {\n throw new Error('No response from upsert')\n }\n if (!response.result || !('data' in response.result)) {\n throw new Error('Unexpected response format from upsert')\n }\n\n const doc = response.result.data[0]\n if (!doc) {\n throw new Error('No document data in upsert response')\n }\n\n return unwrapDocument(this.payload, doc, args.collection)\n}\n\nfunction createGlobal(this: ContentAPIAdapter, args: CreateGlobalArgs) {\n return this.create({\n collection: getGlobalSlug(args.slug),\n data: { ...args.data, id: args.slug, globalType: args.slug },\n })\n}\n\nfunction findGlobal(this: ContentAPIAdapter, args: FindGlobalArgs) {\n return this.findOne({\n collection: getGlobalSlug(args.slug),\n locale: args.locale,\n where: args.where ?? {},\n })\n}\n\nasync function updateGlobal(this: ContentAPIAdapter, args: UpdateGlobalArgs) {\n // Use upsert to ensure the global exists\n // Use slug as the consistent document ID for globals\n return this.upsert({\n collection: getGlobalSlug(args.slug),\n data: args.data,\n where: { id: { equals: args.slug } },\n })\n}\n\n// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183\nfunction findGlobalVersions(this: ContentAPIAdapter, args: Omit<FindGlobalVersionsArgs, 'skip'>) {\n return this.findVersions({\n collection: getGlobalSlug(args.global),\n limit: args.limit,\n locale: args.locale,\n page: args.page,\n pagination: args.pagination,\n sort: args.sort,\n where: args.where,\n })\n}\n\nfunction createGlobalVersion(this: ContentAPIAdapter, args: CreateGlobalVersionArgs) {\n // For globals, use the globalSlug as the consistent document ID\n // This matches what we do in updateGlobal\n return this.createVersion({\n autosave: args.autosave,\n collectionSlug: getGlobalSlug(args.globalSlug),\n createdAt: args.createdAt,\n parent: args.globalSlug,\n publishedLocale: args.publishedLocale,\n updatedAt: args.updatedAt,\n versionData: args.versionData,\n })\n}\n\nfunction updateGlobalVersion(this: ContentAPIAdapter, args: UpdateGlobalVersionArgs) {\n // UpdateVersion requires either id OR where, not both\n if (args.id !== undefined) {\n return this.updateVersion({\n id: args.id,\n collection: getGlobalSlug(args.global),\n locale: args.locale,\n versionData: args.versionData,\n })\n }\n // args.where is guaranteed by Payload when args.id is undefined\n return this.updateVersion({\n collection: getGlobalSlug(args.global),\n locale: args.locale,\n versionData: args.versionData,\n where: args.where,\n })\n}\n\nfunction countGlobalVersions(this: ContentAPIAdapter, args: CountGlobalVersionArgs) {\n return this.countVersions({\n collection: getGlobalSlug(args.global),\n locale: args.locale,\n where: args.where,\n })\n}\n\nexport const contentAPIAdapter = (opts: ContentAPIOptions): DatabaseAdapterObj => ({\n name: 'content-api',\n defaultIDType: 'text',\n init: ({ payload }) => {\n const client = createClient<paths>({ baseUrl: opts.url })\n\n const middlewareOpts = {\n auth: opts.auth,\n contentSystemId: opts.contentSystemId,\n logger: payload.logger,\n url: opts.url,\n }\n\n client.use(createAuthMiddleware(middlewareOpts))\n client.use(createErrorMiddleware(middlewareOpts))\n\n return createDatabaseAdapter<ContentAPIAdapter>({\n name: 'content-api',\n allowIDOnCreate: opts.allowIDOnCreate ?? false,\n auth: opts.auth,\n beginTransaction: () => Promise.resolve(null),\n clearDatabase: clearDatabase as () => Promise<void>,\n client,\n commitTransaction: async () => {},\n contentSystemId: opts.contentSystemId,\n count: count as Count,\n countGlobalVersions: countGlobalVersions as CountGlobalVersions,\n countVersions: countVersions as CountVersions,\n create: create as Create,\n createGlobal: createGlobal as CreateGlobal,\n createGlobalVersion: createGlobalVersion as CreateGlobalVersion,\n createVersion: createVersion as CreateVersion,\n defaultIDType: 'text',\n deleteMany: deleteMany as DeleteMany,\n deleteOne: deleteOne as DeleteOne,\n deleteVersions: deleteVersions as DeleteVersions,\n find: find as Find,\n findDistinct: () =>\n Promise.reject(new Error('findDistinct is not yet implemented for Content API adapter')),\n findGlobal: findGlobal as FindGlobal,\n findGlobalVersions: findGlobalVersions as FindGlobalVersions,\n findOne: findOne as FindOne,\n findVersions: findVersions as FindVersions,\n init,\n packageName: '@payloadcms/db-content-api',\n payload,\n queryDrafts: queryDrafts as QueryDrafts,\n rollbackTransaction: async () => {},\n updateGlobal: updateGlobal as UpdateGlobal,\n updateGlobalVersion: updateGlobalVersion as UpdateGlobalVersion,\n updateMany: updateMany as UpdateMany,\n updateOne: updateOne as UpdateOne,\n updateVersion: updateVersion as UpdateVersion,\n upsert: upsert as Upsert,\n url: opts.url,\n })\n },\n})\n"],"names":["createClient","createDatabaseAdapter","v4","uuid","getGlobalSlug","addFallbackSort","unwrapDocument","unwrapFindResponse","createAuthMiddleware","createErrorMiddleware","dataToContentAPI","convertPayloadJoinsToContentAPI","addFallbackLocale","buildMeta","convertPayloadWhereToContentAPI","syncCollections","existingIds","data","response","error","client","GET","params","path","contentSystemId","Error","JSON","stringify","Set","map","c","id","payload","logger","info","size","warn","message","collection","config","collections","has","slug","createCollection","call","global","globals","globalId","init","auth","mode","process","env","PAYLOAD_DROP_DATABASE","clearDatabase","collectionId","POST","body","errorMessage","includes","findMany","joins","limit","locale","localeArg","page","pagination","_pagination","sort","where","join","result","find","args","collectionConfig","defaultSort","findVersions","sortWithFallback","whereClause","parentToDocumentId","stripVersionPrefix","queryDrafts","versionsResult","latest","equals","docs","versionDoc","version","versionMeta","createVersion","collectionSlug","createdAt","autosave","parent","String","updatedAt","versionData","applyDefaults","publishedLocale","updateVersion","createOnMissing","undefined","doc","deleteVersions","findOne","updateMany","returning","updateOne","deleteMany","req","deleteOne","create","isGlobalCollection","startsWith","customIDType","allowIDOnCreate","fetch","url","headers","method","count","totalDocs","countVersions","upsert","documentId","idClause","createGlobal","globalType","findGlobal","updateGlobal","findGlobalVersions","createGlobalVersion","globalSlug","updateGlobalVersion","countGlobalVersions","contentAPIAdapter","opts","name","defaultIDType","baseUrl","middlewareOpts","use","beginTransaction","Promise","resolve","commitTransaction","findDistinct","reject","packageName","rollbackTransaction"],"mappings":"AAgDA,OAAOA,kBAAkB,gBAAe;AACxC,SAASC,qBAAqB,QAAQ,UAAS;AAC/C,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,qCAAoC;AACvF,SAAwBC,oBAAoB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAChG,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,+BAA+B,QAAQ,uBAAsB;AACtE,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,SAAS,QAAQ,gCAA+B;AACzD,SAASC,+BAA+B,QAAQ,uBAAsB;AAiBtE,eAAeC;IACb,IAAIC;IACJ,IAAI;QACF,MAAM,EAAEC,MAAMC,QAAQ,EAAEC,KAAK,EAAE,GAAG,MAAM,IAAI,CAACC,MAAM,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