@payloadcms/figma 0.0.1-alpha.43 → 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.
@@ -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 { addFallbackLocale } from './utilities/locale/index.js';
10
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,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
  }
@@ -141,10 +128,7 @@ async function findVersions(args) {
141
128
  const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {
142
129
  parentToDocumentId: true
143
130
  });
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;
131
+ const locale = addFallbackLocale(args.locale, this.payload);
148
132
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {
149
133
  body: {
150
134
  collection: args.collection,
@@ -152,13 +136,13 @@ async function findVersions(args) {
152
136
  // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'
153
137
  // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
154
138
  limit: args.limit,
155
- locale: effectiveLocale && args.locale !== 'all' ? effectiveLocale : undefined,
139
+ locale,
156
140
  page: args.page ?? 1,
157
141
  sort: sortWithFallback,
158
142
  where: whereClause,
159
143
  ...buildMeta(this.payload, {
160
144
  collection: args.collection,
161
- locale: effectiveLocale,
145
+ locale,
162
146
  where: args.where
163
147
  })
164
148
  }
@@ -175,6 +159,7 @@ async function queryDrafts(args) {
175
159
  const versionsResult = await this.findVersions({
176
160
  collection: args.collection,
177
161
  limit: args.limit,
162
+ locale: args.locale,
178
163
  page: args.page,
179
164
  pagination: args.pagination,
180
165
  sort: args.sort,
@@ -229,17 +214,20 @@ async function updateVersion(args) {
229
214
  equals: args.id
230
215
  }
231
216
  };
217
+ const locale = addFallbackLocale(args.locale, this.payload);
232
218
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {
233
219
  body: {
234
220
  collection: args.collection,
235
221
  contentSystemId: this.contentSystemId,
236
222
  createOnMissing: false,
223
+ locale,
237
224
  versionDoc: {
238
225
  version: dataToContentAPI(this.payload, args.collection, args.versionData)
239
226
  },
240
227
  where: convertPayloadWhereToContentAPI(where),
241
228
  ...buildMeta(this.payload, {
242
229
  collection: args.collection,
230
+ locale,
243
231
  where
244
232
  })
245
233
  }
@@ -260,13 +248,16 @@ async function deleteVersions(args) {
260
248
  if (!args.collection) {
261
249
  throw new Error('deleteVersions requires a collection');
262
250
  }
251
+ const locale = addFallbackLocale(args.locale, this.payload);
263
252
  const { error } = await this.client.POST('/api/v0/document_versions:delete', {
264
253
  body: {
265
254
  collection: args.collection,
266
255
  contentSystemId: this.contentSystemId,
256
+ locale,
267
257
  where: convertPayloadWhereToContentAPI(args.where),
268
258
  ...buildMeta(this.payload, {
269
259
  collection: args.collection,
260
+ locale,
270
261
  where: args.where
271
262
  })
272
263
  }
@@ -287,7 +278,7 @@ async function findOne(args) {
287
278
  return docs[0] ?? null;
288
279
  }
289
280
  async function updateMany(args) {
290
- const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
281
+ const locale = addFallbackLocale(args.locale, this.payload);
291
282
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
292
283
  body: {
293
284
  collection: args.collection,
@@ -295,11 +286,13 @@ async function updateMany(args) {
295
286
  createOnMissing: false,
296
287
  doc: dataToContentAPI(this.payload, args.collection, args.data),
297
288
  limit: args.limit,
289
+ locale,
298
290
  returning: {},
299
- sort: sortWithFallback,
291
+ sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
300
292
  where: convertPayloadWhereToContentAPI(args.where),
301
293
  ...buildMeta(this.payload, {
302
294
  collection: args.collection,
295
+ locale,
303
296
  where: args.where
304
297
  })
305
298
  }
@@ -316,6 +309,7 @@ async function updateMany(args) {
316
309
  return null;
317
310
  }
318
311
  async function updateOne(args) {
312
+ const locale = addFallbackLocale(args.locale, this.payload);
319
313
  const where = args.where ?? {
320
314
  id: {
321
315
  equals: args.id
@@ -327,10 +321,12 @@ async function updateOne(args) {
327
321
  contentSystemId: this.contentSystemId,
328
322
  createOnMissing: false,
329
323
  doc: dataToContentAPI(this.payload, args.collection, args.data),
324
+ locale,
330
325
  returning: {},
331
326
  where: convertPayloadWhereToContentAPI(where),
332
327
  ...buildMeta(this.payload, {
333
328
  collection: args.collection,
329
+ locale,
334
330
  where
335
331
  })
336
332
  }
@@ -351,13 +347,16 @@ async function updateOne(args) {
351
347
  return unwrapDocument(this.payload, doc, args.collection);
352
348
  }
353
349
  async function deleteMany(args) {
350
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
354
351
  const { error } = await this.client.POST('/api/v0/documents:delete', {
355
352
  body: {
356
353
  collection: args.collection,
357
354
  contentSystemId: this.contentSystemId,
355
+ locale,
358
356
  where: convertPayloadWhereToContentAPI(args.where),
359
357
  ...buildMeta(this.payload, {
360
358
  collection: args.collection,
359
+ locale,
361
360
  where: args.where
362
361
  })
363
362
  }
@@ -367,14 +366,17 @@ async function deleteMany(args) {
367
366
  }
368
367
  }
369
368
  async function deleteOne(args) {
369
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
370
370
  const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {
371
371
  body: {
372
372
  collection: args.collection,
373
373
  contentSystemId: this.contentSystemId,
374
+ locale,
374
375
  returning: {},
375
376
  where: convertPayloadWhereToContentAPI(args.where),
376
377
  ...buildMeta(this.payload, {
377
378
  collection: args.collection,
379
+ locale,
378
380
  where: args.where
379
381
  })
380
382
  }
@@ -392,18 +394,26 @@ async function deleteOne(args) {
392
394
  return unwrapDocument(this.payload, doc, args.collection);
393
395
  }
394
396
  async function create(args) {
395
- 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);
396
401
  const { data: response, error } = await this.client.POST('/api/v0/documents:create', {
397
402
  body: {
398
403
  collection: args.collection,
399
404
  contentSystemId: this.contentSystemId,
400
405
  doc: {
401
- id: String(id),
402
406
  ...dataToContentAPI(this.payload, args.collection, args.data, {
403
407
  applyDefaults: true,
404
408
  createdAt: true
405
- })
406
- }
409
+ }),
410
+ id
411
+ },
412
+ locale,
413
+ ...buildMeta(this.payload, {
414
+ collection: args.collection,
415
+ locale
416
+ })
407
417
  }
408
418
  });
409
419
  if (error) {
@@ -414,14 +424,34 @@ async function create(args) {
414
424
  }
415
425
  return unwrapDocument(this.payload, response.result, args.collection);
416
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
+ }
417
444
  async function count(args) {
445
+ const locale = addFallbackLocale(args.locale, this.payload);
418
446
  const { data: response, error } = await this.client.POST('/api/v0/documents:count', {
419
447
  body: {
420
448
  collection: args.collection,
421
449
  contentSystemId: this.contentSystemId,
450
+ locale,
422
451
  where: convertPayloadWhereToContentAPI(args.where),
423
452
  ...buildMeta(this.payload, {
424
453
  collection: args.collection,
454
+ locale,
425
455
  where: args.where
426
456
  })
427
457
  }
@@ -437,13 +467,16 @@ async function count(args) {
437
467
  };
438
468
  }
439
469
  async function countVersions(args) {
470
+ const locale = addFallbackLocale(args.locale, this.payload);
440
471
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {
441
472
  body: {
442
473
  collection: args.collection,
443
474
  contentSystemId: this.contentSystemId,
475
+ locale,
444
476
  where: convertPayloadWhereToContentAPI(args.where),
445
477
  ...buildMeta(this.payload, {
446
478
  collection: args.collection,
479
+ locale,
447
480
  where: args.where
448
481
  })
449
482
  }
@@ -469,6 +502,7 @@ async function upsert(args) {
469
502
  if (!documentId) {
470
503
  documentId = uuid();
471
504
  }
505
+ const locale = addFallbackLocale(args.locale, this.payload);
472
506
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
473
507
  body: {
474
508
  collection: args.collection,
@@ -480,7 +514,13 @@ async function upsert(args) {
480
514
  applyDefaults: true,
481
515
  createdAt: true
482
516
  }),
483
- 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
+ })
484
524
  }
485
525
  });
486
526
  if (error) {
@@ -511,6 +551,7 @@ function createGlobal(args) {
511
551
  function findGlobal(args) {
512
552
  return this.findOne({
513
553
  collection: getGlobalSlug(args.slug),
554
+ locale: args.locale,
514
555
  where: args.where ?? {}
515
556
  });
516
557
  }
@@ -532,6 +573,7 @@ function findGlobalVersions(args) {
532
573
  return this.findVersions({
533
574
  collection: getGlobalSlug(args.global),
534
575
  limit: args.limit,
576
+ locale: args.locale,
535
577
  page: args.page,
536
578
  pagination: args.pagination,
537
579
  sort: args.sort,
@@ -556,12 +598,14 @@ function updateGlobalVersion(args) {
556
598
  return this.updateVersion({
557
599
  id: args.id,
558
600
  collection: getGlobalSlug(args.global),
601
+ locale: args.locale,
559
602
  versionData: args.versionData
560
603
  });
561
604
  }
562
605
  // args.where is guaranteed by Payload when args.id is undefined
563
606
  return this.updateVersion({
564
607
  collection: getGlobalSlug(args.global),
608
+ locale: args.locale,
565
609
  versionData: args.versionData,
566
610
  where: args.where
567
611
  });
@@ -569,6 +613,7 @@ function updateGlobalVersion(args) {
569
613
  function countGlobalVersions(args) {
570
614
  return this.countVersions({
571
615
  collection: getGlobalSlug(args.global),
616
+ locale: args.locale,
572
617
  where: args.where
573
618
  });
574
619
  }
@@ -589,8 +634,10 @@ export const contentAPIAdapter = (opts)=>({
589
634
  client.use(createErrorMiddleware(middlewareOpts));
590
635
  return createDatabaseAdapter({
591
636
  name: 'content-api',
637
+ allowIDOnCreate: opts.allowIDOnCreate ?? false,
592
638
  auth: opts.auth,
593
639
  beginTransaction: ()=>Promise.resolve(null),
640
+ clearDatabase: clearDatabase,
594
641
  client,
595
642
  commitTransaction: async ()=>{},
596
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 { 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,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;gBAAC;gBAC7DM,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9CC,QAAQ;YACV;YACA,IAAI,CAACb,OAAO,CAACC,MA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,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;AA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,GAAG;YAAC;YAEvD,MAAMyB,iBAAiB;gBACrBzF,MAAMqF,KAAKrF,IAAI;gBACfzB,iBAAiB8G,KAAK9G,eAAe;gBACrCS,QAAQD,QAAQC,MAAM;gBACtBgF,KAAKqB,KAAKrB,GAAG;YACf;YAEA7F,OAAOuH,GAAG,CAACnI,qBAAqBkI;YAChCtH,OAAOuH,GAAG,CAAClI,sBAAsBiI;YAEjC,OAAOzI,sBAAyC;gBAC9CsI,MAAM;gBACNzB,iBAAiBwB,KAAKxB,eAAe,IAAI;gBACzC7D,MAAMqF,KAAKrF,IAAI;gBACf2F,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxCxF,eAAeA;gBACflC;gBACA2H,mBAAmB,WAAa;gBAChCvH,iBAAiB8G,KAAK9G,eAAe;gBACrC4F,OAAOA;gBACPgB,qBAAqBA;gBACrBd,eAAeA;gBACfZ,QAAQA;gBACRgB,cAAcA;gBACdK,qBAAqBA;gBACrBvC,eAAeA;gBACfgD,eAAe;gBACfjC,YAAYA;gBACZE,WAAWA;gBACXP,gBAAgBA;gBAChB1B,MAAMA;gBACNwE,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAIxH,MAAM;gBAC3BmG,YAAYA;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"}
@@ -161,6 +161,7 @@ import { stripFields } from './stripFields.js';
161
161
  traverseFields({
162
162
  callback,
163
163
  fields: collectionConfig.fields,
164
+ fillEmpty: false,
164
165
  ref: transformed
165
166
  });
166
167
  // Convert string ID to number if collection uses numeric custom ID