@payloadcms/figma 0.0.1-alpha.42 → 0.0.1-alpha.44

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 (66) hide show
  1. package/dist/constants.d.ts +1 -1
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +19 -4
  4. package/dist/constants.js.map +1 -1
  5. package/dist/db-content-api/generated/content-api-types.d.ts +6 -174
  6. package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -1
  7. package/dist/db-content-api/generated/content-api-types.js.map +1 -1
  8. package/dist/db-content-api/index.d.ts +2 -0
  9. package/dist/db-content-api/index.d.ts.map +1 -1
  10. package/dist/db-content-api/index.js +135 -44
  11. package/dist/db-content-api/index.js.map +1 -1
  12. package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +1 -1
  13. package/dist/db-content-api/utilities/data/castFieldValue.js +4 -1
  14. package/dist/db-content-api/utilities/data/castFieldValue.js.map +1 -1
  15. package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
  16. package/dist/db-content-api/utilities/data/index.js +16 -2
  17. package/dist/db-content-api/utilities/data/index.js.map +1 -1
  18. package/dist/db-content-api/utilities/locale/index.d.ts +10 -0
  19. package/dist/db-content-api/utilities/locale/index.d.ts.map +1 -0
  20. package/dist/db-content-api/utilities/locale/index.js +21 -0
  21. package/dist/db-content-api/utilities/locale/index.js.map +1 -0
  22. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +11 -0
  23. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts.map +1 -0
  24. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +55 -0
  25. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js.map +1 -0
  26. package/dist/db-content-api/utilities/meta/buildMeta.d.ts +22 -0
  27. package/dist/db-content-api/utilities/meta/buildMeta.d.ts.map +1 -0
  28. package/dist/db-content-api/utilities/meta/buildMeta.js +30 -0
  29. package/dist/db-content-api/utilities/meta/buildMeta.js.map +1 -0
  30. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +7 -0
  31. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts.map +1 -0
  32. package/dist/db-content-api/utilities/{buildPathTypes.js → meta/buildPathTypes.js} +3 -9
  33. package/dist/db-content-api/utilities/meta/buildPathTypes.js.map +1 -0
  34. package/dist/db-content-api/utilities/meta/index.d.ts +5 -0
  35. package/dist/db-content-api/utilities/meta/index.d.ts.map +1 -0
  36. package/dist/db-content-api/utilities/meta/index.js +5 -0
  37. package/dist/db-content-api/utilities/meta/index.js.map +1 -0
  38. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +1 -1
  39. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +3 -3
  40. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +1 -1
  41. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +1 -1
  42. package/dist/storage-content-api/client-uploads/generateSignedURL.js +8 -1
  43. package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -1
  44. package/dist/storage-content-api/utilities/getSafeFilename.d.ts +12 -0
  45. package/dist/storage-content-api/utilities/getSafeFilename.d.ts.map +1 -0
  46. package/dist/storage-content-api/utilities/getSafeFilename.js +61 -0
  47. package/dist/storage-content-api/utilities/getSafeFilename.js.map +1 -0
  48. package/dist/storage-content-api/utilities/index.d.ts +2 -0
  49. package/dist/storage-content-api/utilities/index.d.ts.map +1 -0
  50. package/dist/storage-content-api/utilities/index.js +3 -0
  51. package/dist/storage-content-api/utilities/index.js.map +1 -0
  52. package/dist/templates/.env.example +11 -0
  53. package/dist/utils/env-management.d.ts +9 -1
  54. package/dist/utils/env-management.d.ts.map +1 -1
  55. package/dist/utils/env-management.js +39 -17
  56. package/dist/utils/env-management.js.map +1 -1
  57. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  58. package/dist/utils/payload-config-ast.js +7 -0
  59. package/dist/utils/payload-config-ast.js.map +1 -1
  60. package/dist/utils/project.d.ts.map +1 -1
  61. package/dist/utils/project.js +3 -0
  62. package/dist/utils/project.js.map +1 -1
  63. package/package.json +2 -2
  64. package/dist/db-content-api/utilities/buildPathTypes.d.ts +0 -12
  65. package/dist/db-content-api/utilities/buildPathTypes.d.ts.map +0 -1
  66. package/dist/db-content-api/utilities/buildPathTypes.js.map +0 -1
@@ -5,35 +5,12 @@ import { getGlobalSlug } from './temp-utilities/slug.js';
5
5
  import { addFallbackSort } from './temp-utilities/sorting.js';
6
6
  import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
7
7
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
8
- import { buildPathTypes } from './utilities/buildPathTypes.js';
9
8
  import { dataToContentAPI } from './utilities/data/index.js';
10
9
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
10
+ import { addFallbackLocale } from './utilities/locale/index.js';
11
+ import { buildMeta } from './utilities/meta/index.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,17 +80,23 @@ async function createCollection(collectionId) {
90
80
  }
91
81
  }
92
82
  }
93
- async function findMany({ collection, joins, limit, page, pagination, sort, where }) {
83
+ async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
84
+ const locale = addFallbackLocale(localeArg, this.payload);
94
85
  const { data: response, error } = await this.client.POST('/api/v0/documents:find', {
95
86
  body: {
96
87
  collection,
97
88
  contentSystemId: this.contentSystemId,
98
89
  join: convertPayloadJoinsToContentAPI(this.payload, collection, joins),
99
90
  limit,
91
+ locale,
100
92
  page: page ?? 1,
101
93
  sort: addFallbackSort(sort, this.payload, collection),
102
94
  where: convertPayloadWhereToContentAPI(where ?? {}),
103
- ...buildPathTypes(this.payload, collection, where)
95
+ ...buildMeta(this.payload, {
96
+ collection,
97
+ locale,
98
+ where
99
+ })
104
100
  }
105
101
  });
106
102
  if (error) {
@@ -119,6 +115,7 @@ async function find(args) {
119
115
  // TODO: FindArgs.limit should be 'number' not 'number | undefined'
120
116
  // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
121
117
  limit: args.limit,
118
+ locale: args.locale,
122
119
  page: args.page ?? 1,
123
120
  pagination: args.pagination,
124
121
  sort: args.sort || collectionConfig?.defaultSort,
@@ -131,6 +128,7 @@ async function findVersions(args) {
131
128
  const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {
132
129
  parentToDocumentId: true
133
130
  });
131
+ const locale = addFallbackLocale(args.locale, this.payload);
134
132
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {
135
133
  body: {
136
134
  collection: args.collection,
@@ -138,10 +136,15 @@ async function findVersions(args) {
138
136
  // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'
139
137
  // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
140
138
  limit: args.limit,
139
+ locale,
141
140
  page: args.page ?? 1,
142
141
  sort: sortWithFallback,
143
142
  where: whereClause,
144
- ...buildPathTypes(this.payload, args.collection, args.where)
143
+ ...buildMeta(this.payload, {
144
+ collection: args.collection,
145
+ locale,
146
+ where: args.where
147
+ })
145
148
  }
146
149
  });
147
150
  if (error) {
@@ -156,6 +159,7 @@ async function queryDrafts(args) {
156
159
  const versionsResult = await this.findVersions({
157
160
  collection: args.collection,
158
161
  limit: args.limit,
162
+ locale: args.locale,
159
163
  page: args.page,
160
164
  pagination: args.pagination,
161
165
  sort: args.sort,
@@ -210,16 +214,22 @@ async function updateVersion(args) {
210
214
  equals: args.id
211
215
  }
212
216
  };
217
+ const locale = addFallbackLocale(args.locale, this.payload);
213
218
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {
214
219
  body: {
215
220
  collection: args.collection,
216
221
  contentSystemId: this.contentSystemId,
217
222
  createOnMissing: false,
223
+ locale,
218
224
  versionDoc: {
219
225
  version: dataToContentAPI(this.payload, args.collection, args.versionData)
220
226
  },
221
227
  where: convertPayloadWhereToContentAPI(where),
222
- ...buildPathTypes(this.payload, args.collection, where)
228
+ ...buildMeta(this.payload, {
229
+ collection: args.collection,
230
+ locale,
231
+ where
232
+ })
223
233
  }
224
234
  });
225
235
  if (error) {
@@ -238,12 +248,18 @@ async function deleteVersions(args) {
238
248
  if (!args.collection) {
239
249
  throw new Error('deleteVersions requires a collection');
240
250
  }
251
+ const locale = addFallbackLocale(args.locale, this.payload);
241
252
  const { error } = await this.client.POST('/api/v0/document_versions:delete', {
242
253
  body: {
243
254
  collection: args.collection,
244
255
  contentSystemId: this.contentSystemId,
256
+ locale,
245
257
  where: convertPayloadWhereToContentAPI(args.where),
246
- ...buildPathTypes(this.payload, args.collection, args.where)
258
+ ...buildMeta(this.payload, {
259
+ collection: args.collection,
260
+ locale,
261
+ where: args.where
262
+ })
247
263
  }
248
264
  });
249
265
  if (error) {
@@ -255,13 +271,14 @@ async function findOne(args) {
255
271
  collection: args.collection,
256
272
  joins: args.joins,
257
273
  limit: 1,
274
+ locale: args.locale,
258
275
  pagination: false,
259
276
  where: args.where
260
277
  });
261
278
  return docs[0] ?? null;
262
279
  }
263
280
  async function updateMany(args) {
264
- const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
281
+ const locale = addFallbackLocale(args.locale, this.payload);
265
282
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
266
283
  body: {
267
284
  collection: args.collection,
@@ -269,10 +286,15 @@ async function updateMany(args) {
269
286
  createOnMissing: false,
270
287
  doc: dataToContentAPI(this.payload, args.collection, args.data),
271
288
  limit: args.limit,
289
+ locale,
272
290
  returning: {},
273
- sort: sortWithFallback,
291
+ sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
274
292
  where: convertPayloadWhereToContentAPI(args.where),
275
- ...buildPathTypes(this.payload, args.collection, args.where)
293
+ ...buildMeta(this.payload, {
294
+ collection: args.collection,
295
+ locale,
296
+ where: args.where
297
+ })
276
298
  }
277
299
  });
278
300
  if (error) {
@@ -287,6 +309,7 @@ async function updateMany(args) {
287
309
  return null;
288
310
  }
289
311
  async function updateOne(args) {
312
+ const locale = addFallbackLocale(args.locale, this.payload);
290
313
  const where = args.where ?? {
291
314
  id: {
292
315
  equals: args.id
@@ -298,9 +321,14 @@ async function updateOne(args) {
298
321
  contentSystemId: this.contentSystemId,
299
322
  createOnMissing: false,
300
323
  doc: dataToContentAPI(this.payload, args.collection, args.data),
324
+ locale,
301
325
  returning: {},
302
326
  where: convertPayloadWhereToContentAPI(where),
303
- ...buildPathTypes(this.payload, args.collection, where)
327
+ ...buildMeta(this.payload, {
328
+ collection: args.collection,
329
+ locale,
330
+ where
331
+ })
304
332
  }
305
333
  });
306
334
  if (error) {
@@ -319,12 +347,18 @@ async function updateOne(args) {
319
347
  return unwrapDocument(this.payload, doc, args.collection);
320
348
  }
321
349
  async function deleteMany(args) {
350
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
322
351
  const { error } = await this.client.POST('/api/v0/documents:delete', {
323
352
  body: {
324
353
  collection: args.collection,
325
354
  contentSystemId: this.contentSystemId,
355
+ locale,
326
356
  where: convertPayloadWhereToContentAPI(args.where),
327
- ...buildPathTypes(this.payload, args.collection, args.where)
357
+ ...buildMeta(this.payload, {
358
+ collection: args.collection,
359
+ locale,
360
+ where: args.where
361
+ })
328
362
  }
329
363
  });
330
364
  if (error) {
@@ -332,13 +366,19 @@ async function deleteMany(args) {
332
366
  }
333
367
  }
334
368
  async function deleteOne(args) {
369
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
335
370
  const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {
336
371
  body: {
337
372
  collection: args.collection,
338
373
  contentSystemId: this.contentSystemId,
374
+ locale,
339
375
  returning: {},
340
376
  where: convertPayloadWhereToContentAPI(args.where),
341
- ...buildPathTypes(this.payload, args.collection, args.where)
377
+ ...buildMeta(this.payload, {
378
+ collection: args.collection,
379
+ locale,
380
+ where: args.where
381
+ })
342
382
  }
343
383
  });
344
384
  if (error) {
@@ -354,18 +394,26 @@ async function deleteOne(args) {
354
394
  return unwrapDocument(this.payload, doc, args.collection);
355
395
  }
356
396
  async function create(args) {
357
- const id = args.data.id || uuid();
397
+ const isGlobalCollection = args.collection.startsWith('_global-');
398
+ const customIDType = this.payload.collections[args.collection]?.customIDType;
399
+ 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();
400
+ const locale = addFallbackLocale(args.locale, this.payload);
358
401
  const { data: response, error } = await this.client.POST('/api/v0/documents:create', {
359
402
  body: {
360
403
  collection: args.collection,
361
404
  contentSystemId: this.contentSystemId,
362
405
  doc: {
363
- id: String(id),
364
406
  ...dataToContentAPI(this.payload, args.collection, args.data, {
365
407
  applyDefaults: true,
366
408
  createdAt: true
367
- })
368
- }
409
+ }),
410
+ id
411
+ },
412
+ locale,
413
+ ...buildMeta(this.payload, {
414
+ collection: args.collection,
415
+ locale
416
+ })
369
417
  }
370
418
  });
371
419
  if (error) {
@@ -376,13 +424,36 @@ async function create(args) {
376
424
  }
377
425
  return unwrapDocument(this.payload, response.result, args.collection);
378
426
  }
427
+ async function clearDatabase() {
428
+ this.payload.logger.info(`---- CLEARING CONTENT API DATABASE ----`);
429
+ try {
430
+ await fetch(`${this.url}/dev/clear-db`, {
431
+ headers: {
432
+ 'Content-Type': 'application/json'
433
+ },
434
+ method: 'POST'
435
+ });
436
+ this.payload.logger.info('---- CONTENT API DATABASE CLEARED ----');
437
+ // Re-sync collections after clearing
438
+ await syncCollections.call(this);
439
+ } catch (error) {
440
+ this.payload.logger.error(`Failed to clear database: ${error.message}`);
441
+ throw error;
442
+ }
443
+ }
379
444
  async function count(args) {
445
+ const locale = addFallbackLocale(args.locale, this.payload);
380
446
  const { data: response, error } = await this.client.POST('/api/v0/documents:count', {
381
447
  body: {
382
448
  collection: args.collection,
383
449
  contentSystemId: this.contentSystemId,
450
+ locale,
384
451
  where: convertPayloadWhereToContentAPI(args.where),
385
- ...buildPathTypes(this.payload, args.collection, args.where)
452
+ ...buildMeta(this.payload, {
453
+ collection: args.collection,
454
+ locale,
455
+ where: args.where
456
+ })
386
457
  }
387
458
  });
388
459
  if (error) {
@@ -396,12 +467,18 @@ async function count(args) {
396
467
  };
397
468
  }
398
469
  async function countVersions(args) {
470
+ const locale = addFallbackLocale(args.locale, this.payload);
399
471
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {
400
472
  body: {
401
473
  collection: args.collection,
402
474
  contentSystemId: this.contentSystemId,
475
+ locale,
403
476
  where: convertPayloadWhereToContentAPI(args.where),
404
- ...buildPathTypes(this.payload, args.collection, args.where)
477
+ ...buildMeta(this.payload, {
478
+ collection: args.collection,
479
+ locale,
480
+ where: args.where
481
+ })
405
482
  }
406
483
  });
407
484
  if (error) {
@@ -425,6 +502,7 @@ async function upsert(args) {
425
502
  if (!documentId) {
426
503
  documentId = uuid();
427
504
  }
505
+ const locale = addFallbackLocale(args.locale, this.payload);
428
506
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
429
507
  body: {
430
508
  collection: args.collection,
@@ -436,7 +514,13 @@ async function upsert(args) {
436
514
  applyDefaults: true,
437
515
  createdAt: true
438
516
  }),
439
- where: convertPayloadWhereToContentAPI(args.where)
517
+ locale,
518
+ where: convertPayloadWhereToContentAPI(args.where),
519
+ ...buildMeta(this.payload, {
520
+ collection: args.collection,
521
+ locale,
522
+ where: args.where
523
+ })
440
524
  }
441
525
  });
442
526
  if (error) {
@@ -467,6 +551,7 @@ function createGlobal(args) {
467
551
  function findGlobal(args) {
468
552
  return this.findOne({
469
553
  collection: getGlobalSlug(args.slug),
554
+ locale: args.locale,
470
555
  where: args.where ?? {}
471
556
  });
472
557
  }
@@ -488,6 +573,7 @@ function findGlobalVersions(args) {
488
573
  return this.findVersions({
489
574
  collection: getGlobalSlug(args.global),
490
575
  limit: args.limit,
576
+ locale: args.locale,
491
577
  page: args.page,
492
578
  pagination: args.pagination,
493
579
  sort: args.sort,
@@ -512,12 +598,14 @@ function updateGlobalVersion(args) {
512
598
  return this.updateVersion({
513
599
  id: args.id,
514
600
  collection: getGlobalSlug(args.global),
601
+ locale: args.locale,
515
602
  versionData: args.versionData
516
603
  });
517
604
  }
518
605
  // args.where is guaranteed by Payload when args.id is undefined
519
606
  return this.updateVersion({
520
607
  collection: getGlobalSlug(args.global),
608
+ locale: args.locale,
521
609
  versionData: args.versionData,
522
610
  where: args.where
523
611
  });
@@ -525,6 +613,7 @@ function updateGlobalVersion(args) {
525
613
  function countGlobalVersions(args) {
526
614
  return this.countVersions({
527
615
  collection: getGlobalSlug(args.global),
616
+ locale: args.locale,
528
617
  where: args.where
529
618
  });
530
619
  }
@@ -545,8 +634,10 @@ export const contentAPIAdapter = (opts)=>({
545
634
  client.use(createErrorMiddleware(middlewareOpts));
546
635
  return createDatabaseAdapter({
547
636
  name: 'content-api',
637
+ allowIDOnCreate: opts.allowIDOnCreate ?? false,
548
638
  auth: opts.auth,
549
639
  beginTransaction: ()=>Promise.resolve(null),
640
+ clearDatabase: clearDatabase,
550
641
  client,
551
642
  commitTransaction: async ()=>{},
552
643
  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 { buildPathTypes } from './utilities/buildPathTypes.js'\nimport { dataToContentAPI } from './utilities/data/index.js'\nimport { convertPayloadJoinsToContentAPI } from './utilities/joins.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 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, locale, versions, projection\n }: Pick<FindArgs, 'joins' | 'pagination' | 'sort' | 'where'> &\n Required<Pick<FindArgs, 'collection' | 'limit' | 'page'>>,\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 page: page ?? 1,\n sort: addFallbackSort(sort, this.payload, collection),\n where: convertPayloadWhereToContentAPI(where ?? {}),\n ...buildPathTypes(this.payload, collection, 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 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 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 page: args.page ?? 1,\n sort: sortWithFallback,\n where: whereClause,\n ...buildPathTypes(this.payload, args.collection, args.where),\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 ...buildPathTypes(this.payload, 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 ...buildPathTypes(this.payload, args.collection, 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 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 ...buildPathTypes(this.payload, args.collection, 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 ...buildPathTypes(this.payload, 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 ...buildPathTypes(this.payload, args.collection, 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 ...buildPathTypes(this.payload, args.collection, 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 ...buildPathTypes(this.payload, args.collection, 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 ...buildPathTypes(this.payload, args.collection, 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","buildPathTypes","dataToContentAPI","convertPayloadJoinsToContentAPI","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","page","pagination","sort","where","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","undefined","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,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,+BAA+B,QAAQ,uBAAsB;AACtE,SAASC,+BAA+B,QAAQ,uBAAsB;AAetE,eAAeC;IACb,IAAI,IAAI,CAACC,IAAI,CAACC,IAAI,KAAK,UAAU;QAC/B,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO,IAAI,IAAI,CAACJ,IAAI,CAACC,IAAI,KAAK,cAAc;QAC1C,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACF,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B;IAEA,IAAIC,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;QAChD,IAAI,CAACL,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAE,IAAI,CAACI,eAAe,CAAC,MAAM,CAAC;QAC1F,IAAI;YACF,MAAMC,MAAM,GAAG,IAAI,CAACC,GAAG,CAAC,aAAa,CAAC,EAAE;gBACtCC,MAAMC,KAAKC,SAAS,CAAC;oBAAEL,iBAAiB,IAAI,CAACA,eAAe;g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A;gBACfJ,QAAQA;gBACRQ,cAAcA;gBACdK,qBAAqBA;gBACrB9B,eAAeA;gBACfuC,eAAe;gBACfxB,YAAYA;gBACZC,WAAWA;gBACXN,gBAAgBA;gBAChB1B,MAAMA;gBACN+D,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAI7F,MAAM;gBAC3BwE,YAAYA;gBACZE,oBAAoBA;gBACpBlB,SAASA;gBACTvB,cAAcA;gBACd5D;gBACAyH,aAAa;gBACbtH;gBACA6D,aAAaA;gBACb0D,qBAAqB,WAAa;gBAClCtB,cAAcA;gBACdK,qBAAqBA;gBACrBrB,YAAYA;gBACZE,WAAWA;gBACXP,eAAeA;gBACfe,QAAQA;gBACRnF,KAAKkG,KAAKlG,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/index.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 })\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 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 const locale = addFallbackLocale(args.locale, this.payload)\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 version: dataToContentAPI(this.payload, args.collection, args.versionData),\n },\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 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),\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),\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 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","queryDrafts","versionsResult","latest","equals","docs","versionDoc","version","versionMeta","createVersion","collectionSlug","autosave","parent","String","versionData","applyDefaults","updateVersion","createOnMissing","doc","deleteVersions","findOne","updateMany","returning","updateOne","deleteMany","req","deleteOne","create","isGlobalCollection","startsWith","customIDType","allowIDOnCreate","createdAt","fetch","url","headers","method","count","totalDocs","countVersions","upsert","documentId","idClause","createGlobal","globalType","findGlobal","updateGlobal","findGlobalVersions","createGlobalVersion","globalSlug","updatedAt","updateGlobalVersion","undefined","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,4BAA2B;AACrD,SAASC,+BAA+B,QAAQ,uBAAsB;AAiBtE,eAAeC;IACb,IAAIC;IACJ,IAAI;QACF,MAAM,EAAEC,MAAMC,QAAQ,EAAEC,KAAK,EAAE,GAAG,MAAM,IAAI,CAACC,MAAM,CAACC,GAAG,CACrD,yDACA;YACEC,QAAQ;gBAAEC,MAAM;oBAAEC,iBAAiB,IAAI,CAACA,eAAe;gBAAC;YAAE;QAC5D;QAGF,IAAIL,OAAO;YACT,MAAM,IAAIM,MAAMC,KAAKC,SAAS,CAACR;QACjC;QACA,IAAI,CAACD,UAAU;YACb,MAAM,IAAIO,MAAM;QAClB;QAEAT,cAAc,IAAIY,IAAIV,SAASD,IAAI,CAACY,GAAG,CAAC,CAACC,IAAMA,EAAEC,EAAE;QACnD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,MAAM,EAAElB,YAAYmB,IAAI,CAAC,qBAAqB,CAAC;IAC3E,EAAE,OAAOhB,OAAO;QACd,IAAI,CAACa,OAAO,CAACC,MAAM,CAAC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YA;gBACZE,oBAAoBA;gBACpB3B,SAASA;gBACTvB,cAAcA;gBACd5B;gBACAkG,aAAa;gBACblH;gBACAgD,aAAaA;gBACbmE,qBAAqB,WAAa;gBAClCtB,cAAcA;gBACdK,qBAAqBA;gBACrB9B,YAAYA;gBACZE,WAAWA;gBACXP,eAAeA;gBACfwB,QAAQA;gBACRN,KAAKqB,KAAKrB,GAAG;YACf;QACF;IACF,CAAA,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"castFieldValue.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/castFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmEjF"}
1
+ {"version":3,"file":"castFieldValue.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/castFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAwEjF"}
@@ -56,7 +56,10 @@
56
56
  }
57
57
  // Text-like fields: convert non-strings to JSON strings
58
58
  // This handles text, textarea, email, and code fields
59
- if ((field.type === 'text' || field.type === 'textarea' || field.type === 'email' || field.type === 'code') && typeof value !== 'string') {
59
+ // EXCEPTIONS:
60
+ // - Localized fields are stored as objects like {"en": "value", "es": "valor"}
61
+ // - hasMany fields are stored as arrays like ["value1", "value2"]
62
+ if ((field.type === 'text' || field.type === 'textarea' || field.type === 'email' || field.type === 'code') && typeof value !== 'string' && !('localized' in field && field.localized) && !('hasMany' in field && field.hasMany && Array.isArray(value))) {
60
63
  return JSON.stringify(value);
61
64
  }
62
65
  // No casting needed for other types or already correct types