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

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 (100) hide show
  1. package/dist/auth/oauth-flow.d.ts.map +1 -1
  2. package/dist/auth/oauth-flow.js +6 -3
  3. package/dist/auth/oauth-flow.js.map +1 -1
  4. package/dist/auth/refresh.d.ts +2 -1
  5. package/dist/auth/refresh.d.ts.map +1 -1
  6. package/dist/auth/refresh.js +11 -3
  7. package/dist/auth/refresh.js.map +1 -1
  8. package/dist/auth/token-store.d.ts +6 -4
  9. package/dist/auth/token-store.d.ts.map +1 -1
  10. package/dist/auth/token-store.js +17 -14
  11. package/dist/auth/token-store.js.map +1 -1
  12. package/dist/auth/types.d.ts +7 -4
  13. package/dist/auth/types.d.ts.map +1 -1
  14. package/dist/auth/types.js.map +1 -1
  15. package/dist/cli.js +8 -6
  16. package/dist/cli.js.map +1 -1
  17. package/dist/commands/deploy.d.ts.map +1 -1
  18. package/dist/commands/deploy.js +2 -1
  19. package/dist/commands/deploy.js.map +1 -1
  20. package/dist/commands/init.d.ts.map +1 -1
  21. package/dist/commands/init.js +12 -1
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/list-tokens.d.ts +3 -3
  24. package/dist/commands/list-tokens.d.ts.map +1 -1
  25. package/dist/commands/list-tokens.js +20 -8
  26. package/dist/commands/list-tokens.js.map +1 -1
  27. package/dist/commands/login.d.ts.map +1 -1
  28. package/dist/commands/login.js +12 -4
  29. package/dist/commands/login.js.map +1 -1
  30. package/dist/commands/logout.d.ts +5 -4
  31. package/dist/commands/logout.d.ts.map +1 -1
  32. package/dist/commands/logout.js +55 -12
  33. package/dist/commands/logout.js.map +1 -1
  34. package/dist/db-content-api/generated/content-api-types.d.ts +163 -103
  35. package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -1
  36. package/dist/db-content-api/generated/content-api-types.js.map +1 -1
  37. package/dist/db-content-api/index.d.ts.map +1 -1
  38. package/dist/db-content-api/index.js +73 -65
  39. package/dist/db-content-api/index.js.map +1 -1
  40. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +31 -1
  41. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +1 -1
  42. package/dist/db-content-api/temp-utilities/unwrapDocument.js +24 -24
  43. package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +1 -1
  44. package/dist/db-content-api/utilities/buildPathTypes.d.ts +12 -0
  45. package/dist/db-content-api/utilities/buildPathTypes.d.ts.map +1 -0
  46. package/dist/db-content-api/utilities/buildPathTypes.js +157 -0
  47. package/dist/db-content-api/utilities/buildPathTypes.js.map +1 -0
  48. package/dist/db-content-api/utilities/data/index.d.ts +2 -0
  49. package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
  50. package/dist/db-content-api/utilities/data/index.js +8 -0
  51. package/dist/db-content-api/utilities/data/index.js.map +1 -1
  52. package/dist/db-content-api/utilities/where.d.ts.map +1 -1
  53. package/dist/db-content-api/utilities/where.js +17 -3
  54. package/dist/db-content-api/utilities/where.js.map +1 -1
  55. package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -1
  56. package/dist/oauth/components/LogoutButton/index.js +5 -3
  57. package/dist/oauth/components/LogoutButton/index.js.map +1 -1
  58. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  59. package/dist/oauth/endpoints/getLoginEndpoint.js +17 -7
  60. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  61. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -1
  62. package/dist/oauth/endpoints/getLogoutEndpoint.js +7 -4
  63. package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -1
  64. package/dist/plugin/build-config.js +3 -3
  65. package/dist/plugin/build-config.js.map +1 -1
  66. package/dist/storage-content-api/api-types.d.ts +8 -1
  67. package/dist/storage-content-api/api-types.d.ts.map +1 -1
  68. package/dist/storage-content-api/api-types.js.map +1 -1
  69. package/dist/storage-content-api/client-uploads/generateSignedURL.js +1 -0
  70. package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -1
  71. package/dist/storage-content-api/generateURL.d.ts.map +1 -1
  72. package/dist/storage-content-api/generateURL.js +3 -2
  73. package/dist/storage-content-api/generateURL.js.map +1 -1
  74. package/dist/storage-content-api/handleDelete.d.ts.map +1 -1
  75. package/dist/storage-content-api/handleDelete.js +4 -2
  76. package/dist/storage-content-api/handleDelete.js.map +1 -1
  77. package/dist/storage-content-api/handleUpload.d.ts +1 -1
  78. package/dist/storage-content-api/handleUpload.d.ts.map +1 -1
  79. package/dist/storage-content-api/handleUpload.js +11 -3
  80. package/dist/storage-content-api/handleUpload.js.map +1 -1
  81. package/dist/storage-content-api/staticHandler.js +1 -0
  82. package/dist/storage-content-api/staticHandler.js.map +1 -1
  83. package/dist/utils/format-env-suffix.d.ts +12 -0
  84. package/dist/utils/format-env-suffix.d.ts.map +1 -0
  85. package/dist/utils/format-env-suffix.js +13 -0
  86. package/dist/utils/format-env-suffix.js.map +1 -0
  87. package/dist/utils/lambda-config.js +26 -12
  88. package/dist/utils/lambda-config.js.map +1 -1
  89. package/dist/utils/messages.d.ts.map +1 -1
  90. package/dist/utils/messages.js +1 -2
  91. package/dist/utils/messages.js.map +1 -1
  92. package/package.json +1 -1
  93. package/dist/db-content-api/temp-utilities/pagination.d.ts +0 -13
  94. package/dist/db-content-api/temp-utilities/pagination.d.ts.map +0 -1
  95. package/dist/db-content-api/temp-utilities/pagination.js +0 -45
  96. package/dist/db-content-api/temp-utilities/pagination.js.map +0 -1
  97. package/dist/oauth/utilities/getAdminPath.d.ts +0 -8
  98. package/dist/oauth/utilities/getAdminPath.d.ts.map +0 -1
  99. package/dist/oauth/utilities/getAdminPath.js +0 -9
  100. package/dist/oauth/utilities/getAdminPath.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  import createClient from 'openapi-fetch';
2
2
  import { createDatabaseAdapter } from 'payload';
3
3
  import { v4 as uuid } from 'uuid';
4
- import { getPaginationData } from './temp-utilities/pagination.js';
5
4
  import { getGlobalSlug } from './temp-utilities/slug.js';
6
5
  import { addFallbackSort } from './temp-utilities/sorting.js';
7
- import { unwrapDocument } from './temp-utilities/unwrapDocument.js';
6
+ import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
8
7
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
8
+ import { buildPathTypes } from './utilities/buildPathTypes.js';
9
9
  import { dataToContentAPI } from './utilities/data/index.js';
10
10
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
11
11
  import { convertPayloadWhereToContentAPI } from './utilities/where.js';
@@ -93,13 +93,14 @@ async function createCollection(collectionId) {
93
93
  async function findMany({ collection, joins, limit, page, pagination, sort, where }) {
94
94
  const { data: response, error } = await this.client.POST('/api/v0/documents:find', {
95
95
  body: {
96
- collectionId: collection,
96
+ collection,
97
97
  contentSystemId: this.contentSystemId,
98
98
  join: convertPayloadJoinsToContentAPI(this.payload, collection, joins),
99
99
  limit,
100
100
  page: page ?? 1,
101
101
  sort: addFallbackSort(sort, this.payload, collection),
102
- where: convertPayloadWhereToContentAPI(where ?? {})
102
+ where: convertPayloadWhereToContentAPI(where ?? {}),
103
+ ...buildPathTypes(this.payload, collection, where)
103
104
  }
104
105
  });
105
106
  if (error) {
@@ -108,10 +109,7 @@ async function findMany({ collection, joins, limit, page, pagination, sort, wher
108
109
  if (!response) {
109
110
  throw new Error('No response from findMany');
110
111
  }
111
- return {
112
- docs: response.result.data.map((doc)=>unwrapDocument(this.payload, doc, collection)),
113
- ...getPaginationData(response.result.pagination, pagination)
114
- };
112
+ return unwrapFindResponse(this.payload, response.result, collection);
115
113
  }
116
114
  async function find(args) {
117
115
  const collectionConfig = this.payload.config.collections.find((c)=>c.slug === args.collection);
@@ -135,14 +133,15 @@ async function findVersions(args) {
135
133
  });
136
134
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:find', {
137
135
  body: {
138
- collectionId: args.collection,
136
+ collection: args.collection,
139
137
  contentSystemId: this.contentSystemId,
140
138
  // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'
141
139
  // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
142
140
  limit: args.limit,
143
141
  page: args.page ?? 1,
144
142
  sort: sortWithFallback,
145
- where: whereClause
143
+ where: whereClause,
144
+ ...buildPathTypes(this.payload, args.collection, args.where)
146
145
  }
147
146
  });
148
147
  if (error) {
@@ -151,11 +150,7 @@ async function findVersions(args) {
151
150
  if (!response) {
152
151
  throw new Error('No response from findVersions');
153
152
  }
154
- const docs = response.result.data.map((doc)=>unwrapDocument(this.payload, doc, args.collection));
155
- return {
156
- docs,
157
- ...getPaginationData(response.result.pagination, args.pagination)
158
- };
153
+ return unwrapFindResponse(this.payload, response.result, args.collection);
159
154
  }
160
155
  async function queryDrafts(args) {
161
156
  const versionsResult = await this.findVersions({
@@ -190,13 +185,15 @@ async function queryDrafts(args) {
190
185
  async function createVersion(args) {
191
186
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:create', {
192
187
  body: {
193
- collectionId: args.collectionSlug,
188
+ collection: args.collectionSlug,
194
189
  contentSystemId: this.contentSystemId,
195
- data: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {
196
- applyDefaults: true
197
- }),
198
- documentId: String(args.parent),
199
- latest: !args.autosave
190
+ versionDoc: {
191
+ latest: !args.autosave,
192
+ parent: String(args.parent),
193
+ version: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {
194
+ applyDefaults: true
195
+ })
196
+ }
200
197
  }
201
198
  });
202
199
  if (error) {
@@ -205,23 +202,24 @@ async function createVersion(args) {
205
202
  if (!response) {
206
203
  throw new Error('No response from createVersion');
207
204
  }
208
- if (!('data' in response.result)) {
209
- throw new Error('Unexpected response format from createVersion');
210
- }
211
- return unwrapDocument(this.payload, response.result.data, args.collectionSlug);
205
+ return unwrapDocument(this.payload, response.result, args.collectionSlug);
212
206
  }
213
207
  async function updateVersion(args) {
208
+ const where = args.where ?? {
209
+ id: {
210
+ equals: args.id
211
+ }
212
+ };
214
213
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {
215
214
  body: {
216
- collectionId: args.collection,
215
+ collection: args.collection,
217
216
  contentSystemId: this.contentSystemId,
218
217
  createOnMissing: false,
219
- data: dataToContentAPI(this.payload, args.collection, args.versionData),
220
- where: convertPayloadWhereToContentAPI(args.where ?? {
221
- id: {
222
- equals: args.id
223
- }
224
- })
218
+ versionDoc: {
219
+ version: dataToContentAPI(this.payload, args.collection, args.versionData)
220
+ },
221
+ where: convertPayloadWhereToContentAPI(where),
222
+ ...buildPathTypes(this.payload, args.collection, where)
225
223
  }
226
224
  });
227
225
  if (error) {
@@ -242,9 +240,10 @@ async function deleteVersions(args) {
242
240
  }
243
241
  const { error } = await this.client.POST('/api/v0/document_versions:delete', {
244
242
  body: {
245
- collectionId: args.collection,
243
+ collection: args.collection,
246
244
  contentSystemId: this.contentSystemId,
247
- where: convertPayloadWhereToContentAPI(args.where)
245
+ where: convertPayloadWhereToContentAPI(args.where),
246
+ ...buildPathTypes(this.payload, args.collection, args.where)
248
247
  }
249
248
  });
250
249
  if (error) {
@@ -265,14 +264,15 @@ async function updateMany(args) {
265
264
  const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
266
265
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
267
266
  body: {
268
- collectionId: args.collection,
267
+ collection: args.collection,
269
268
  contentSystemId: this.contentSystemId,
270
269
  createOnMissing: false,
271
- data: dataToContentAPI(this.payload, args.collection, args.data),
270
+ doc: dataToContentAPI(this.payload, args.collection, args.data),
272
271
  limit: args.limit,
273
272
  returning: {},
274
273
  sort: sortWithFallback,
275
- where: convertPayloadWhereToContentAPI(args.where)
274
+ where: convertPayloadWhereToContentAPI(args.where),
275
+ ...buildPathTypes(this.payload, args.collection, args.where)
276
276
  }
277
277
  });
278
278
  if (error) {
@@ -287,18 +287,20 @@ async function updateMany(args) {
287
287
  return null;
288
288
  }
289
289
  async function updateOne(args) {
290
+ const where = args.where ?? {
291
+ id: {
292
+ equals: args.id
293
+ }
294
+ };
290
295
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
291
296
  body: {
292
- collectionId: args.collection,
297
+ collection: args.collection,
293
298
  contentSystemId: this.contentSystemId,
294
299
  createOnMissing: false,
295
- data: dataToContentAPI(this.payload, args.collection, args.data),
300
+ doc: dataToContentAPI(this.payload, args.collection, args.data),
296
301
  returning: {},
297
- where: convertPayloadWhereToContentAPI(args.where ?? {
298
- id: {
299
- equals: args.id
300
- }
301
- })
302
+ where: convertPayloadWhereToContentAPI(where),
303
+ ...buildPathTypes(this.payload, args.collection, where)
302
304
  }
303
305
  });
304
306
  if (error) {
@@ -319,9 +321,10 @@ async function updateOne(args) {
319
321
  async function deleteMany(args) {
320
322
  const { error } = await this.client.POST('/api/v0/documents:delete', {
321
323
  body: {
322
- collectionId: args.collection,
324
+ collection: args.collection,
323
325
  contentSystemId: this.contentSystemId,
324
- where: convertPayloadWhereToContentAPI(args.where)
326
+ where: convertPayloadWhereToContentAPI(args.where),
327
+ ...buildPathTypes(this.payload, args.collection, args.where)
325
328
  }
326
329
  });
327
330
  if (error) {
@@ -331,10 +334,11 @@ async function deleteMany(args) {
331
334
  async function deleteOne(args) {
332
335
  const { data: response, error } = await this.client.POST('/api/v0/documents:delete', {
333
336
  body: {
334
- collectionId: args.collection,
337
+ collection: args.collection,
335
338
  contentSystemId: this.contentSystemId,
336
339
  returning: {},
337
- where: convertPayloadWhereToContentAPI(args.where)
340
+ where: convertPayloadWhereToContentAPI(args.where),
341
+ ...buildPathTypes(this.payload, args.collection, args.where)
338
342
  }
339
343
  });
340
344
  if (error) {
@@ -353,12 +357,15 @@ async function create(args) {
353
357
  const id = args.data.id || uuid();
354
358
  const { data: response, error } = await this.client.POST('/api/v0/documents:create', {
355
359
  body: {
356
- id: String(id),
357
- collectionId: args.collection,
360
+ collection: args.collection,
358
361
  contentSystemId: this.contentSystemId,
359
- data: dataToContentAPI(this.payload, args.collection, args.data, {
360
- applyDefaults: true
361
- })
362
+ doc: {
363
+ id: String(id),
364
+ ...dataToContentAPI(this.payload, args.collection, args.data, {
365
+ applyDefaults: true,
366
+ createdAt: true
367
+ })
368
+ }
362
369
  }
363
370
  });
364
371
  if (error) {
@@ -367,17 +374,15 @@ async function create(args) {
367
374
  if (!response) {
368
375
  throw new Error('No response from create');
369
376
  }
370
- if (!('data' in response.result)) {
371
- throw new Error('Unexpected response format from create');
372
- }
373
- return unwrapDocument(this.payload, response.result.data, args.collection);
377
+ return unwrapDocument(this.payload, response.result, args.collection);
374
378
  }
375
379
  async function count(args) {
376
380
  const { data: response, error } = await this.client.POST('/api/v0/documents:count', {
377
381
  body: {
378
- collectionId: args.collection,
382
+ collection: args.collection,
379
383
  contentSystemId: this.contentSystemId,
380
- where: convertPayloadWhereToContentAPI(args.where)
384
+ where: convertPayloadWhereToContentAPI(args.where),
385
+ ...buildPathTypes(this.payload, args.collection, args.where)
381
386
  }
382
387
  });
383
388
  if (error) {
@@ -393,9 +398,10 @@ async function count(args) {
393
398
  async function countVersions(args) {
394
399
  const { data: response, error } = await this.client.POST('/api/v0/document_versions:count', {
395
400
  body: {
396
- collectionId: args.collection,
401
+ collection: args.collection,
397
402
  contentSystemId: this.contentSystemId,
398
- where: convertPayloadWhereToContentAPI(args.where)
403
+ where: convertPayloadWhereToContentAPI(args.where),
404
+ ...buildPathTypes(this.payload, args.collection, args.where)
399
405
  }
400
406
  });
401
407
  if (error) {
@@ -421,13 +427,14 @@ async function upsert(args) {
421
427
  }
422
428
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
423
429
  body: {
424
- collectionId: args.collection,
430
+ collection: args.collection,
425
431
  contentSystemId: this.contentSystemId,
426
432
  createOnMissing: {
427
433
  id: documentId
428
434
  },
429
- data: dataToContentAPI(this.payload, args.collection, args.data, {
430
- applyDefaults: true
435
+ doc: dataToContentAPI(this.payload, args.collection, args.data, {
436
+ applyDefaults: true,
437
+ createdAt: true
431
438
  }),
432
439
  where: convertPayloadWhereToContentAPI(args.where)
433
440
  }
@@ -452,6 +459,7 @@ function createGlobal(args) {
452
459
  collection: getGlobalSlug(args.slug),
453
460
  data: {
454
461
  ...args.data,
462
+ id: args.slug,
455
463
  globalType: args.slug
456
464
  }
457
465
  });
@@ -538,7 +546,7 @@ export const contentAPIAdapter = (opts)=>({
538
546
  return createDatabaseAdapter({
539
547
  name: 'content-api',
540
548
  auth: opts.auth,
541
- beginTransaction: ()=>Promise.resolve('no-op-transaction'),
549
+ beginTransaction: ()=>Promise.resolve(null),
542
550
  client,
543
551
  commitTransaction: async ()=>{},
544
552
  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 { getPaginationData } from './temp-utilities/pagination.js'\nimport { getGlobalSlug } from './temp-utilities/slug.js'\nimport { addFallbackSort } from './temp-utilities/sorting.js'\nimport { unwrapDocument } 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 { 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 collectionId: 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 },\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 {\n docs: response.result.data.map((doc) => unwrapDocument(this.payload, doc, collection)),\n ...getPaginationData(response.result.pagination, pagination),\n }\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 collectionId: 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 },\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 const docs = response.result.data.map((doc) => unwrapDocument(this.payload, doc, args.collection))\n\n return {\n docs,\n ...getPaginationData(response.result.pagination, args.pagination),\n }\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 as any\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 collectionId: args.collectionSlug,\n contentSystemId: this.contentSystemId,\n data: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {\n applyDefaults: true,\n }),\n documentId: String(args.parent),\n latest: !args.autosave,\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 if (!('data' in response.result)) {\n throw new Error('Unexpected response format from createVersion')\n }\n\n return unwrapDocument(this.payload, response.result.data, args.collectionSlug)\n}\n\nasync function updateVersion(this: ContentAPIAdapter, args: UpdateVersionArgs) {\n const { data: response, error } = await this.client.POST('/api/v0/document_versions:update', {\n body: {\n collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n data: dataToContentAPI(this.payload, args.collection, args.versionData),\n where: convertPayloadWhereToContentAPI(args.where ?? { id: { equals: args.id } }),\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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(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 const { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n data: dataToContentAPI(this.payload, args.collection, args.data),\n limit: args.limit,\n returning: {},\n sort: sortWithFallback,\n where: convertPayloadWhereToContentAPI(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 { data: response, error } = await this.client.POST('/api/v0/documents:update', {\n body: {\n collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: false,\n data: dataToContentAPI(this.payload, args.collection, args.data),\n returning: {},\n where: convertPayloadWhereToContentAPI(args.where ?? { id: { equals: args.id } }),\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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n returning: {}, // Request deleted document back\n where: convertPayloadWhereToContentAPI(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 id: String(id),\n collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n data: dataToContentAPI(this.payload, args.collection, args.data, { applyDefaults: true }),\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 if (!('data' in response.result)) {\n throw new Error('Unexpected response format from create')\n }\n\n return unwrapDocument(this.payload, response.result.data, 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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n where: convertPayloadWhereToContentAPI(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 collectionId: args.collection,\n contentSystemId: this.contentSystemId,\n createOnMissing: { id: documentId },\n data: dataToContentAPI(this.payload, args.collection, args.data, { applyDefaults: true }),\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, 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('no-op-transaction'),\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","getPaginationData","getGlobalSlug","addFallbackSort","unwrapDocument","createAuthMiddleware","createErrorMiddleware","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","docs","result","doc","find","args","collectionConfig","defaultSort","findVersions","sortWithFallback","whereClause","parentToDocumentId","queryDrafts","versionsResult","latest","equals","versionDoc","version","versionMeta","createVersion","collectionSlug","versionData","applyDefaults","documentId","String","parent","autosave","updateVersion","createOnMissing","deleteVersions","findOne","updateMany","returning","updateOne","deleteMany","deleteOne","create","count","totalDocs","countVersions","upsert","idClause","createGlobal","globalType","findGlobal","updateGlobal","findGlobalVersions","createGlobalVersion","globalSlug","createdAt","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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BAAiB;gBACrBhH,MAAM4G,KAAK5G,IAAI;gBACfQ,iBAAiBoG,KAAKpG,eAAe;gBACrCL,QAAQD,QAAQC,MAAM;gBACtBO,KAAKkG,KAAKlG,GAAG;YACf;YAEAY,OAAO2F,GAAG,CAACvH,qBAAqBsH;YAChC1F,OAAO2F,GAAG,CAACtH,sBAAsBqH;YAEjC,OAAO7H,sBAAyC;gBAC9C0H,MAAM;gBACN7G,MAAM4G,KAAK5G,IAAI;gBACfkH,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxC9F;gBACA+F,mBAAmB,WAAa;gBAChC7G,iBAAiBoG,KAAKpG,eAAe;gBACrCkF,OAAOA;gBACPgB,qBAAqBA;gBACrBd,eAAeA;gBACfH,QAAQA;gBACRM,cAAcA;gBACdK,qBAAqBA;gBACrB5B,eAAeA;gBACfsC,eAAe;gBACfvB,YAAYA;gBACZC,WAAWA;gBACXN,gBAAgBA;gBAChBzB,MAAMA;gBACN6D,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAI7F,MAAM;gBAC3BuE,YAAYA;gBACZE,oBAAoBA;gBACpBhB,SAASA;gBACTtB,cAAcA;gBACd9D;gBACAyH,aAAa;gBACbtH;gBACA+D,aAAaA;gBACbwD,qBAAqB,WAAa;gBAClCvB,cAAcA;gBACdM,qBAAqBA;gBACrBpB,YAAYA;gBACZE,WAAWA;gBACXN,eAAeA;gBACfa,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 { 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,C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Q,iBAAiBoG,KAAKpG,eAAe;gBACrCL,QAAQD,QAAQC,MAAM;gBACtBO,KAAKkG,KAAKlG,GAAG;YACf;YAEAY,OAAO2F,GAAG,CAACxH,qBAAqBuH;YAChC1F,OAAO2F,GAAG,CAACvH,sBAAsBsH;YAEjC,OAAO9H,sBAAyC;gBAC9C2H,MAAM;gBACN7G,MAAM4G,KAAK5G,IAAI;gBACfkH,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxC9F;gBACA+F,mBAAmB,WAAa;gBAChC7G,iBAAiBoG,KAAKpG,eAAe;gBACrCkF,OAAOA;gBACPgB,qBAAqBA;gBACrBd,eAAeA;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,4 +1,34 @@
1
1
  import type { Payload } from 'payload';
2
2
  import type { components } from '../generated/content-api-types.js';
3
- export declare function unwrapDocument(payload: Payload, doc: components['schemas']['Document'] | components['schemas']['DocumentVersion'], collectionSlug?: string): Record<string, unknown>;
3
+ type DocumentResponse = {
4
+ id: string;
5
+ } & components['schemas']['Document'];
6
+ type DocumentVersionResponse = {
7
+ id: string;
8
+ } & components['schemas']['DocumentVersion'];
9
+ export declare function unwrapDocument(payload: Payload, doc: DocumentResponse | DocumentVersionResponse, collectionSlug?: string): Record<string, unknown>;
10
+ export declare const unwrapFindResponse: (payload: Payload, response: components["schemas"]["FindDocumentsResponse"]["result"] | components["schemas"]["FindDocumentVersionsResponse"]["result"], collection: string) => {
11
+ totalDocs: number;
12
+ limit: number;
13
+ page: number;
14
+ totalPages: number;
15
+ pagingCounter: number;
16
+ hasPrevPage: boolean;
17
+ hasNextPage: boolean;
18
+ prevPage: number | null;
19
+ nextPage: number | null;
20
+ docs: Record<string, unknown>[];
21
+ } | {
22
+ totalDocs: number;
23
+ limit: number;
24
+ page: number;
25
+ totalPages: number;
26
+ pagingCounter: number;
27
+ hasPrevPage: boolean;
28
+ hasNextPage: boolean;
29
+ prevPage: number | null;
30
+ nextPage: number | null;
31
+ docs: Record<string, unknown>[];
32
+ };
33
+ export {};
4
34
  //# sourceMappingURL=unwrapDocument.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unwrapDocument.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/temp-utilities/unwrapDocument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAWnE,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,EACjF,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoDzB"}
1
+ {"version":3,"file":"unwrapDocument.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/temp-utilities/unwrapDocument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAInE,KAAK,gBAAgB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CAAA;AAC1E,KAAK,uBAAuB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAA;AASxF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,gBAAgB,GAAG,uBAAuB,EAC/C,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyCzB;AAED,eAAO,MAAM,kBAAkB,YACpB,OAAO,YAEZ,UAAU,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,GACxD,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,cACvD,MAAM;;;;;;;;;;;;;;;;;;;;;;CASnB,CAAA"}
@@ -1,8 +1,8 @@
1
1
  import { dataFromContentAPI } from '../utilities/data/index.js';
2
2
  // Helper to unwrap Content API document format to Payload format
3
3
  // Content API returns:
4
- // - For documents: { id, data: { ...fields }, createdAt, updatedAt }
5
- // - For versions: { id, documentId, latest, data: { ...fields }, createdAt, updatedAt }
4
+ // - For documents: { id, contentSystemId, collection, doc: { ...fields, createdAt, updatedAt } }
5
+ // - For versions: { id, contentSystemId, collection, versionDoc: { id, createdAt, updatedAt, latest, parent, version: {...fields} } }
6
6
  // Payload expects:
7
7
  // - For documents: { id, ...fields, createdAt, updatedAt }
8
8
  // - For versions: { id, parent, latest, version: { ...fields }, createdAt, updatedAt }
@@ -10,18 +10,13 @@ export function unwrapDocument(payload, doc, collectionSlug) {
10
10
  if (!doc) {
11
11
  return doc;
12
12
  }
13
- // Check if this is a DocumentVersion (has documentId and latest fields)
14
- const isVersion = 'documentId' in doc && 'latest' in doc;
13
+ // Check if this is a DocumentVersion (has versionDoc field)
14
+ const isVersion = 'versionDoc' in doc;
15
15
  if (isVersion) {
16
16
  // For versions, Payload expects nested structure with 'version' field
17
- const versionDoc = doc;
17
+ const { versionDoc } = doc;
18
18
  const baseDoc = {
19
- id: versionDoc.id,
20
- createdAt: versionDoc.createdAt,
21
- latest: versionDoc.latest,
22
- parent: versionDoc.documentId,
23
- updatedAt: versionDoc.updatedAt,
24
- version: versionDoc.data
19
+ ...versionDoc
25
20
  };
26
21
  // Transform data from Content API format to Payload format
27
22
  if (collectionSlug) {
@@ -34,20 +29,25 @@ export function unwrapDocument(payload, doc, collectionSlug) {
34
29
  }
35
30
  }
36
31
  return baseDoc;
37
- } else {
38
- // For regular documents, spread data at root level
39
- const baseDoc = {
40
- ...doc.data,
41
- id: doc.id,
42
- createdAt: doc.createdAt,
43
- updatedAt: doc.updatedAt
44
- };
45
- // Transform data from Content API format to Payload format
46
- if (collectionSlug) {
47
- return dataFromContentAPI(payload, collectionSlug, baseDoc);
48
- }
49
- return baseDoc;
50
32
  }
33
+ // For regular documents, spread doc data at root level
34
+ const { id, doc: docData } = doc;
35
+ const baseDoc = {
36
+ ...docData,
37
+ id
38
+ };
39
+ // Transform data from Content API format to Payload format
40
+ if (collectionSlug) {
41
+ return dataFromContentAPI(payload, collectionSlug, baseDoc);
42
+ }
43
+ return baseDoc;
51
44
  }
45
+ export const unwrapFindResponse = (payload, response, collection)=>{
46
+ const { data, ...paginationFields } = response;
47
+ return {
48
+ docs: data.map((doc)=>unwrapDocument(payload, doc, collection)),
49
+ ...paginationFields
50
+ };
51
+ };
52
52
 
53
53
  //# sourceMappingURL=unwrapDocument.js.map