@payloadcms/figma 0.0.1-alpha.30 → 0.0.1-alpha.32
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.
- package/dist/db-content-api/index.d.ts.map +1 -1
- package/dist/db-content-api/index.js +29 -8
- package/dist/db-content-api/index.js.map +1 -1
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +1 -1
- package/dist/db-content-api/temp-utilities/unwrapDocument.js +11 -3
- package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +1 -1
- package/dist/db-content-api/utilities/data/applyDefaults.d.ts +7 -0
- package/dist/db-content-api/utilities/data/applyDefaults.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/applyDefaults.js +59 -0
- package/dist/db-content-api/utilities/data/applyDefaults.js.map +1 -0
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts +11 -0
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/castFieldValue.js +66 -0
- package/dist/db-content-api/utilities/data/castFieldValue.js.map +1 -0
- package/dist/db-content-api/utilities/{data.d.ts → data/index.d.ts} +7 -3
- package/dist/db-content-api/utilities/data/index.d.ts.map +1 -0
- package/dist/db-content-api/utilities/{data.js → data/index.js} +54 -6
- package/dist/db-content-api/utilities/data/index.js.map +1 -0
- package/dist/db-content-api/utilities/data/stripFields.d.ts +48 -0
- package/dist/db-content-api/utilities/data/stripFields.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/stripFields.js +195 -0
- package/dist/db-content-api/utilities/data/stripFields.js.map +1 -0
- package/dist/db-content-api/utilities/where.d.ts.map +1 -1
- package/dist/db-content-api/utilities/where.js +46 -2
- package/dist/db-content-api/utilities/where.js.map +1 -1
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +14 -0
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +9 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +1 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +42 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +1 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +13 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +1 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.js +31 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -0
- package/dist/storage-content-api/handleUpload.d.ts.map +1 -1
- package/dist/storage-content-api/handleUpload.js +13 -3
- package/dist/storage-content-api/handleUpload.js.map +1 -1
- package/dist/storage-content-api/staticHandler.d.ts.map +1 -1
- package/dist/storage-content-api/staticHandler.js +22 -2
- package/dist/storage-content-api/staticHandler.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +16 -0
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/package.json +5 -2
- package/dist/db-content-api/utilities/data.d.ts.map +0 -1
- package/dist/db-content-api/utilities/data.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db-content-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAcnB,kBAAkB,EA+BnB,MAAM,SAAS,CAAA;AAEhB,OAAO,YAAY,MAAM,eAAe,CAAA;AAIxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAA;AAM7D,OAAO,EAAE,KAAK,QAAQ,EAA+C,MAAM,qBAAqB,CAAA;AAKhG,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db-content-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAcnB,kBAAkB,EA+BnB,MAAM,SAAS,CAAA;AAEhB,OAAO,YAAY,MAAM,eAAe,CAAA;AAIxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAA;AAM7D,OAAO,EAAE,KAAK,QAAQ,EAA+C,MAAM,qBAAqB,CAAA;AAKhG,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,mBAAmB,CAAA;AAuiBvB,eAAO,MAAM,iBAAiB,SAAU,iBAAiB,KAAG,kBAuD1D,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { getGlobalSlug } from './temp-utilities/slug.js';
|
|
|
6
6
|
import { addFallbackSort, convertPayloadSortToContentAPI } from './temp-utilities/sorting.js';
|
|
7
7
|
import { unwrapDocument } from './temp-utilities/unwrapDocument.js';
|
|
8
8
|
import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
|
|
9
|
-
import { dataToContentAPI } from './utilities/data.js';
|
|
9
|
+
import { dataToContentAPI } from './utilities/data/index.js';
|
|
10
10
|
import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
|
|
11
11
|
import { convertPayloadWhereToContentAPI } from './utilities/where.js';
|
|
12
12
|
async function init() {
|
|
@@ -155,7 +155,7 @@ async function findVersions(args) {
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
async function queryDrafts(args) {
|
|
158
|
-
|
|
158
|
+
const versionsResult = await this.findVersions({
|
|
159
159
|
collection: args.collection,
|
|
160
160
|
limit: args.limit,
|
|
161
161
|
page: args.page,
|
|
@@ -168,13 +168,30 @@ async function queryDrafts(args) {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
+
// queryDrafts should return documents with fields at root level, not nested in 'version'
|
|
172
|
+
// So we need to unwrap the version structure and merge version fields to root
|
|
173
|
+
const docs = versionsResult.docs.map((versionDoc)=>{
|
|
174
|
+
const { version, ...versionMeta } = versionDoc;
|
|
175
|
+
return {
|
|
176
|
+
...versionMeta,
|
|
177
|
+
...version,
|
|
178
|
+
// Keep version metadata like parent, but document fields take precedence
|
|
179
|
+
id: version.id
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
...versionsResult,
|
|
184
|
+
docs
|
|
185
|
+
};
|
|
171
186
|
}
|
|
172
187
|
async function createVersion(args) {
|
|
173
188
|
const { data: response, error } = await this.client.POST('/api/v0/document_versions:create', {
|
|
174
189
|
body: {
|
|
175
190
|
collectionId: args.collectionSlug,
|
|
176
191
|
contentSystemId: this.contentSystemId,
|
|
177
|
-
data: dataToContentAPI(this.payload, args.collectionSlug, args.versionData
|
|
192
|
+
data: dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {
|
|
193
|
+
applyDefaults: true
|
|
194
|
+
}),
|
|
178
195
|
documentId: String(args.parent),
|
|
179
196
|
latest: !args.autosave
|
|
180
197
|
}
|
|
@@ -212,7 +229,7 @@ async function updateVersion(args) {
|
|
|
212
229
|
}
|
|
213
230
|
const doc = response.result.data[0];
|
|
214
231
|
if (!doc) {
|
|
215
|
-
|
|
232
|
+
return null;
|
|
216
233
|
}
|
|
217
234
|
return unwrapDocument(this.payload, doc, args.collection);
|
|
218
235
|
}
|
|
@@ -289,7 +306,7 @@ async function updateOne(args) {
|
|
|
289
306
|
}
|
|
290
307
|
const doc = response.result.data[0];
|
|
291
308
|
if (!doc) {
|
|
292
|
-
|
|
309
|
+
return null;
|
|
293
310
|
}
|
|
294
311
|
return unwrapDocument(this.payload, doc, args.collection);
|
|
295
312
|
}
|
|
@@ -322,7 +339,7 @@ async function deleteOne(args) {
|
|
|
322
339
|
}
|
|
323
340
|
const doc = response.result.data[0];
|
|
324
341
|
if (!doc) {
|
|
325
|
-
|
|
342
|
+
return null;
|
|
326
343
|
}
|
|
327
344
|
return unwrapDocument(this.payload, doc, args.collection);
|
|
328
345
|
}
|
|
@@ -333,7 +350,9 @@ async function create(args) {
|
|
|
333
350
|
id: String(id),
|
|
334
351
|
collectionId: args.collection,
|
|
335
352
|
contentSystemId: this.contentSystemId,
|
|
336
|
-
data: dataToContentAPI(this.payload, args.collection, args.data
|
|
353
|
+
data: dataToContentAPI(this.payload, args.collection, args.data, {
|
|
354
|
+
applyDefaults: true
|
|
355
|
+
})
|
|
337
356
|
}
|
|
338
357
|
});
|
|
339
358
|
if (error) {
|
|
@@ -401,7 +420,9 @@ async function upsert(args) {
|
|
|
401
420
|
createOnMissing: {
|
|
402
421
|
id: documentId
|
|
403
422
|
},
|
|
404
|
-
data: dataToContentAPI(this.payload, args.collection, args.data
|
|
423
|
+
data: dataToContentAPI(this.payload, args.collection, args.data, {
|
|
424
|
+
applyDefaults: true
|
|
425
|
+
}),
|
|
405
426
|
where: convertPayloadWhereToContentAPI(args.where)
|
|
406
427
|
}
|
|
407
428
|
});
|
|
@@ -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, convertPayloadSortToContentAPI } 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.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 collectionConfig = this.payload.config.collections.find((c) => c.slug === collection)\n const sortWithFallback = addFallbackSort(sort, collectionConfig)\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: collectionConfig\n ? convertPayloadJoinsToContentAPI(this.payload, collectionConfig, joins)\n : undefined,\n limit,\n page: page ?? 1,\n sort: convertPayloadSortToContentAPI(sortWithFallback),\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 limit: args.limit ?? 0,\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 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 limit: args.limit ?? 0,\n page: args.page ?? 1,\n sort: convertPayloadSortToContentAPI(args.sort),\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 return 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\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 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 throw new Error('No document version matched the where clause')\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 { 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),\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 throw new Error('No document matched the where clause for update')\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 throw new Error('No document matched the where clause for deletion')\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),\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),\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","convertPayloadSortToContentAPI","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","collectionConfig","find","sortWithFallback","join","undefined","docs","result","doc","args","defaultSort","findVersions","whereClause","parentToDocumentId","queryDrafts","latest","equals","createVersion","collectionSlug","versionData","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","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,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,eAAe,EAAEC,8BAA8B,QAAQ,8BAA6B;AAC7F,SAASC,cAAc,QAAQ,qCAAoC;AACnE,SAAwBC,oBAAoB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAChG,SAASC,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,+BAA+B,QAAQ,uBAAsB;AACtE,SAASC,+BAA+B,QAAQ,uBAAsB;AAetE,eAAeC;IACb,IAAI,IAAI,CAACC,IAAI,CAACC,IAAI,KAAK,UAAU;QAC/B,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO,IAAI,IAAI,CAACJ,IAAI,CAACC,IAAI,KAAK,cAAc;QAC1C,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACF,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B;IAEA,IAAIC,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;QAChD,IAAI,CAACL,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAE,IAAI,CAACI,eAAe,CAAC,MAAM,CAAC;QAC1F,IAAI;YACF,MAAMC,MAAM,GAAG,IAAI,CAACC,GAAG,CAAC,aAAa,CAAC,EAAE;gBACtCC,MAAMC,KA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AChCrF,OAAOsF,GAAG,CAACjH,sBAAsBgH;YAEjC,OAAOzH,sBAAyC;gBAC9CsH,MAAM;gBACNxG,MAAMuG,KAAKvG,IAAI;gBACf6G,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxCzF;gBACA0F,mBAAmB,WAAa;gBAChCxG,iBAAiB+F,KAAK/F,eAAe;gBACrC8E,OAAOA;gBACPe,qBAAqBA;gBACrBb,eAAeA;gBACfH,QAAQA;gBACRM,cAAcA;gBACdK,qBAAqBA;gBACrB3B,eAAeA;gBACfoC,eAAe;gBACftB,YAAYA;gBACZC,WAAWA;gBACXN,gBAAgBA;gBAChBxB,MAAMA;gBACN2D,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAIxF,MAAM;gBAC3BmE,YAAYA;gBACZE,oBAAoBA;gBACpBhB,SAASA;gBACThB,cAAcA;gBACdhE;gBACAoH,aAAa;gBACbjH;gBACAgE,aAAaA;gBACbkD,qBAAqB,WAAa;gBAClCtB,cAAcA;gBACdM,qBAAqBA;gBACrBpB,YAAYA;gBACZE,WAAWA;gBACXN,eAAeA;gBACfa,QAAQA;gBACR/E,KAAK6F,KAAK7F,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 { getPaginationData } from './temp-utilities/pagination.js'\nimport { getGlobalSlug } from './temp-utilities/slug.js'\nimport { addFallbackSort, convertPayloadSortToContentAPI } 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 collectionConfig = this.payload.config.collections.find((c) => c.slug === collection)\n const sortWithFallback = addFallbackSort(sort, collectionConfig)\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: collectionConfig\n ? convertPayloadJoinsToContentAPI(this.payload, collectionConfig, joins)\n : undefined,\n limit,\n page: page ?? 1,\n sort: convertPayloadSortToContentAPI(sortWithFallback),\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 limit: args.limit ?? 0,\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 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 limit: args.limit ?? 0,\n page: args.page ?? 1,\n sort: convertPayloadSortToContentAPI(args.sort),\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 { 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),\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","convertPayloadSortToContentAPI","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","collectionConfig","find","sortWithFallback","join","undefined","docs","result","doc","args","defaultSort","findVersions","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","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,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,eAAe,EAAEC,8BAA8B,QAAQ,8BAA6B;AAC7F,SAASC,cAAc,QAAQ,qCAAoC;AACnE,SAAwBC,oBAAoB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAChG,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,+BAA+B,QAAQ,uBAAsB;AACtE,SAASC,+BAA+B,QAAQ,uBAAsB;AAetE,eAAeC;IACb,IAAI,IAAI,CAACC,IAAI,CAACC,IAAI,KAAK,UAAU;QAC/B,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO,IAAI,IAAI,CAACJ,IAAI,CAACC,IAAI,KAAK,cAAc;QAC1C,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACF,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B;IAEA,IAAIC,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;QAChD,IAAI,CAACL,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAE,IAAI,CAACI,eAAe,CAAC,MAAM,CAAC;QAC1F,IAAI;YACF,MAAMC,MAAM,GAAG,IAAI,CAACC,GAAG,CAAC,aAAa,CAAC,EAAE;gBACtCC,MAAMC,KAAKC,SAAS,CAAC;oBAAEL,iBAAiB,IAAI,CAACA,eAAe;gBAAC;gBAC7DM,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9CC,QAAQ;YACV;YACA,IAAI,CAACb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AAG;YAAC;YAEvD,MAAMsG,iBAAiB;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,OAAO9H,sBAAyC;gBAC9C2H,MAAM;gBACN7G,MAAM4G,KAAK5G,IAAI;gBACfkH,kBAAkB,IAAMC,QAAQC,OAAO,CAAC;gBACxC9F;gBACA+F,mBAAmB,WAAa;gBAChC7G,iBAAiBoG,KAAKpG,eAAe;gBACrCmF,OAAOA;gBACPe,qBAAqBA;gBACrBb,eAAeA;gBACfH,QAAQA;gBACRM,cAAcA;gBACdK,qBAAqBA;gBACrB5B,eAAeA;gBACfqC,eAAe;gBACftB,YAAYA;gBACZC,WAAWA;gBACXN,gBAAgBA;gBAChB7B,MAAMA;gBACNgE,cAAc,IACZH,QAAQI,MAAM,CAAC,IAAI7F,MAAM;gBAC3BwE,YAAYA;gBACZE,oBAAoBA;gBACpBhB,SAASA;gBACTrB,cAAcA;gBACdhE;gBACAyH,aAAa;gBACbtH;gBACAgE,aAAaA;gBACbuD,qBAAqB,WAAa;gBAClCtB,cAAcA;gBACdM,qBAAqBA;gBACrBpB,YAAYA;gBACZE,WAAWA;gBACXN,eAAeA;gBACfa,QAAQA;gBACRpF,KAAKkG,KAAKlG,GAAG;YACf;QACF;IACF,CAAA,EAAE"}
|
|
@@ -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;
|
|
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,9 +1,11 @@
|
|
|
1
|
-
import { dataFromContentAPI } from '../utilities/data.js';
|
|
1
|
+
import { dataFromContentAPI } from '../utilities/data/index.js';
|
|
2
2
|
// Helper to unwrap Content API document format to Payload format
|
|
3
|
-
// Content API returns:
|
|
3
|
+
// Content API returns:
|
|
4
|
+
// - For documents: { id, data: { ...fields }, createdAt, updatedAt }
|
|
5
|
+
// - For versions: { id, documentId, latest, data: { ...fields }, createdAt, updatedAt }
|
|
4
6
|
// Payload expects:
|
|
5
7
|
// - For documents: { id, ...fields, createdAt, updatedAt }
|
|
6
|
-
// - For versions: { id, version: { ...fields }, createdAt, updatedAt
|
|
8
|
+
// - For versions: { id, parent, latest, version: { ...fields }, createdAt, updatedAt }
|
|
7
9
|
export function unwrapDocument(payload, doc, collectionSlug) {
|
|
8
10
|
if (!doc) {
|
|
9
11
|
return doc;
|
|
@@ -17,6 +19,7 @@ export function unwrapDocument(payload, doc, collectionSlug) {
|
|
|
17
19
|
id: versionDoc.id,
|
|
18
20
|
createdAt: versionDoc.createdAt,
|
|
19
21
|
latest: versionDoc.latest,
|
|
22
|
+
parent: versionDoc.documentId,
|
|
20
23
|
updatedAt: versionDoc.updatedAt,
|
|
21
24
|
version: versionDoc.data
|
|
22
25
|
};
|
|
@@ -24,6 +27,11 @@ export function unwrapDocument(payload, doc, collectionSlug) {
|
|
|
24
27
|
if (collectionSlug) {
|
|
25
28
|
// Only transform the nested 'version' field
|
|
26
29
|
baseDoc.version = dataFromContentAPI(payload, collectionSlug, baseDoc.version);
|
|
30
|
+
// Also convert version ID if collection uses numeric custom ID
|
|
31
|
+
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
32
|
+
if (customIDType === 'number') {
|
|
33
|
+
baseDoc.id = Number(baseDoc.id);
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
return baseDoc;
|
|
29
37
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db-content-api/temp-utilities/unwrapDocument.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { components } from '../generated/content-api-types.js'\n\nimport { dataFromContentAPI } from '../utilities/data.js'\n\n// Helper to unwrap Content API document format to Payload format\n// Content API returns: { id, data: { ...fields }, createdAt, updatedAt }\n// Payload expects:\n// - For documents: { id, ...fields, createdAt, updatedAt }\n
|
|
1
|
+
{"version":3,"sources":["../../../src/db-content-api/temp-utilities/unwrapDocument.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { components } from '../generated/content-api-types.js'\n\nimport { dataFromContentAPI } from '../utilities/data/index.js'\n\n// Helper to unwrap Content API document format to Payload format\n// Content API returns:\n// - For documents: { id, data: { ...fields }, createdAt, updatedAt }\n// - For versions: { id, documentId, latest, data: { ...fields }, createdAt, updatedAt }\n// Payload expects:\n// - For documents: { id, ...fields, createdAt, updatedAt }\n// - For versions: { id, parent, latest, version: { ...fields }, createdAt, updatedAt }\nexport function unwrapDocument(\n payload: Payload,\n doc: components['schemas']['Document'] | components['schemas']['DocumentVersion'],\n collectionSlug?: string,\n): Record<string, unknown> {\n if (!doc) {\n return doc as unknown as Record<string, unknown>\n }\n\n // Check if this is a DocumentVersion (has documentId and latest fields)\n const isVersion = 'documentId' in doc && 'latest' in doc\n\n if (isVersion) {\n // For versions, Payload expects nested structure with 'version' field\n const versionDoc = doc\n const baseDoc = {\n id: versionDoc.id,\n createdAt: versionDoc.createdAt,\n latest: versionDoc.latest,\n parent: versionDoc.documentId, // Content API uses 'documentId', Payload expects 'parent'\n updatedAt: versionDoc.updatedAt,\n version: versionDoc.data, // Nest data inside 'version'\n } as Record<string, unknown>\n\n // Transform data from Content API format to Payload format\n if (collectionSlug) {\n // Only transform the nested 'version' field\n baseDoc.version = dataFromContentAPI(payload, collectionSlug, baseDoc.version) as Record<\n string,\n unknown\n >\n\n // Also convert version ID if collection uses numeric custom ID\n const customIDType = payload.collections?.[collectionSlug]?.customIDType\n if (customIDType === 'number') {\n baseDoc.id = Number(baseDoc.id)\n }\n }\n\n return baseDoc\n } else {\n // For regular documents, spread data at root level\n const baseDoc = {\n ...doc.data, // Spread the actual document fields\n id: doc.id,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n // Transform data from Content API format to Payload format\n if (collectionSlug) {\n return dataFromContentAPI(payload, collectionSlug, baseDoc) as Record<string, unknown>\n }\n\n return baseDoc as Record<string, unknown>\n }\n}\n"],"names":["dataFromContentAPI","unwrapDocument","payload","doc","collectionSlug","isVersion","versionDoc","baseDoc","id","createdAt","latest","parent","documentId","updatedAt","version","data","customIDType","collections","Number"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,6BAA4B;AAE/D,iEAAiE;AACjE,uBAAuB;AACvB,uEAAuE;AACvE,0FAA0F;AAC1F,mBAAmB;AACnB,6DAA6D;AAC7D,yFAAyF;AACzF,OAAO,SAASC,eACdC,OAAgB,EAChBC,GAAiF,EACjFC,cAAuB;IAEvB,IAAI,CAACD,KAAK;QACR,OAAOA;IACT;IAEA,wEAAwE;IACxE,MAAME,YAAY,gBAAgBF,OAAO,YAAYA;IAErD,IAAIE,WAAW;QACb,sEAAsE;QACtE,MAAMC,aAAaH;QACnB,MAAMI,UAAU;YACdC,IAAIF,WAAWE,EAAE;YACjBC,WAAWH,WAAWG,SAAS;YAC/BC,QAAQJ,WAAWI,MAAM;YACzBC,QAAQL,WAAWM,UAAU;YAC7BC,WAAWP,WAAWO,SAAS;YAC/BC,SAASR,WAAWS,IAAI;QAC1B;QAEA,2DAA2D;QAC3D,IAAIX,gBAAgB;YAClB,4CAA4C;YAC5CG,QAAQO,OAAO,GAAGd,mBAAmBE,SAASE,gBAAgBG,QAAQO,OAAO;YAK7E,+DAA+D;YAC/D,MAAME,eAAed,QAAQe,WAAW,EAAE,CAACb,eAAe,EAAEY;YAC5D,IAAIA,iBAAiB,UAAU;gBAC7BT,QAAQC,EAAE,GAAGU,OAAOX,QAAQC,EAAE;YAChC;QACF;QAEA,OAAOD;IACT,OAAO;QACL,mDAAmD;QACnD,MAAMA,UAAU;YACd,GAAGJ,IAAIY,IAAI;YACXP,IAAIL,IAAIK,EAAE;YACVC,WAAWN,IAAIM,SAAS;YACxBI,WAAWV,IAAIU,SAAS;QAC1B;QAEA,2DAA2D;QAC3D,IAAIT,gBAAgB;YAClB,OAAOJ,mBAAmBE,SAASE,gBAAgBG;QACrD;QAEA,OAAOA;IACT;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively apply static default values to data
|
|
4
|
+
* This handles defaults for nested structures (arrays, groups) which traverseFields doesn't handle
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyDefaults(data: Record<string, unknown>, fields: Field[]): void;
|
|
7
|
+
//# sourceMappingURL=applyDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyDefaults.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/applyDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CA8DlF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively apply static default values to data
|
|
3
|
+
* This handles defaults for nested structures (arrays, groups) which traverseFields doesn't handle
|
|
4
|
+
*/ export function applyDefaults(data, fields) {
|
|
5
|
+
for (const field of fields){
|
|
6
|
+
// Only process fields that affect data (have a name)
|
|
7
|
+
if (!('name' in field) || !field.name) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const value = data[field.name];
|
|
11
|
+
// Check if field has a default value (only for FieldAffectingData types)
|
|
12
|
+
const defaultValue = 'defaultValue' in field ? field.defaultValue : undefined;
|
|
13
|
+
const hasDefault = defaultValue !== undefined;
|
|
14
|
+
const isFunction = typeof defaultValue === 'function';
|
|
15
|
+
// Skip function defaults - they need req/user context
|
|
16
|
+
if (hasDefault && isFunction) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
// Apply default if value is undefined
|
|
20
|
+
if (hasDefault && value === undefined) {
|
|
21
|
+
let appliedDefault = typeof defaultValue === 'object' ? JSON.parse(JSON.stringify(defaultValue)) : defaultValue;
|
|
22
|
+
// Special handling for point fields: convert array [lng, lat] to GeoJSON format
|
|
23
|
+
if (field.type === 'point' && Array.isArray(appliedDefault) && appliedDefault.length === 2) {
|
|
24
|
+
appliedDefault = {
|
|
25
|
+
type: 'Point',
|
|
26
|
+
coordinates: appliedDefault
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
data[field.name] = appliedDefault;
|
|
30
|
+
}
|
|
31
|
+
// Recursively process nested structures
|
|
32
|
+
const currentValue = data[field.name];
|
|
33
|
+
if (field.type === 'array' && Array.isArray(currentValue) && 'fields' in field) {
|
|
34
|
+
// Apply defaults to each array element
|
|
35
|
+
for (const element of currentValue){
|
|
36
|
+
if (element && typeof element === 'object') {
|
|
37
|
+
applyDefaults(element, field.fields);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else if (field.type === 'group' && currentValue && typeof currentValue === 'object') {
|
|
41
|
+
// Apply defaults to group fields
|
|
42
|
+
if ('fields' in field) {
|
|
43
|
+
applyDefaults(currentValue, field.fields);
|
|
44
|
+
}
|
|
45
|
+
} else if (field.type === 'blocks' && Array.isArray(currentValue) && 'blocks' in field) {
|
|
46
|
+
// Apply defaults to each block
|
|
47
|
+
for (const element of currentValue){
|
|
48
|
+
if (element && typeof element === 'object' && 'blockType' in element) {
|
|
49
|
+
const block = field.blocks.find((b)=>b.slug === element.blockType);
|
|
50
|
+
if (block?.fields) {
|
|
51
|
+
applyDefaults(element, block.fields);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=applyDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/applyDefaults.ts"],"sourcesContent":["import type { Field } from 'payload'\n\n/**\n * Recursively apply static default values to data\n * This handles defaults for nested structures (arrays, groups) which traverseFields doesn't handle\n */\nexport function applyDefaults(data: Record<string, unknown>, fields: Field[]): void {\n for (const field of fields) {\n // Only process fields that affect data (have a name)\n if (!('name' in field) || !field.name) {\n continue\n }\n\n const value = data[field.name]\n\n // Check if field has a default value (only for FieldAffectingData types)\n const defaultValue = 'defaultValue' in field ? field.defaultValue : undefined\n const hasDefault = defaultValue !== undefined\n const isFunction = typeof defaultValue === 'function'\n\n // Skip function defaults - they need req/user context\n if (hasDefault && isFunction) {\n continue\n }\n\n // Apply default if value is undefined\n if (hasDefault && value === undefined) {\n let appliedDefault =\n typeof defaultValue === 'object' ? JSON.parse(JSON.stringify(defaultValue)) : defaultValue\n\n // Special handling for point fields: convert array [lng, lat] to GeoJSON format\n if (field.type === 'point' && Array.isArray(appliedDefault) && appliedDefault.length === 2) {\n appliedDefault = {\n type: 'Point',\n coordinates: appliedDefault,\n }\n }\n\n data[field.name] = appliedDefault\n }\n\n // Recursively process nested structures\n const currentValue = data[field.name]\n\n if (field.type === 'array' && Array.isArray(currentValue) && 'fields' in field) {\n // Apply defaults to each array element\n for (const element of currentValue) {\n if (element && typeof element === 'object') {\n applyDefaults(element as Record<string, unknown>, field.fields)\n }\n }\n } else if (field.type === 'group' && currentValue && typeof currentValue === 'object') {\n // Apply defaults to group fields\n if ('fields' in field) {\n applyDefaults(currentValue as Record<string, unknown>, field.fields)\n }\n } else if (field.type === 'blocks' && Array.isArray(currentValue) && 'blocks' in field) {\n // Apply defaults to each block\n for (const element of currentValue) {\n if (element && typeof element === 'object' && 'blockType' in element) {\n const block = field.blocks.find((b) => b.slug === element.blockType)\n if (block?.fields) {\n applyDefaults(element as Record<string, unknown>, block.fields)\n }\n }\n }\n }\n }\n}\n"],"names":["applyDefaults","data","fields","field","name","value","defaultValue","undefined","hasDefault","isFunction","appliedDefault","JSON","parse","stringify","type","Array","isArray","length","coordinates","currentValue","element","block","blocks","find","b","slug","blockType"],"mappings":"AAEA;;;CAGC,GACD,OAAO,SAASA,cAAcC,IAA6B,EAAEC,MAAe;IAC1E,KAAK,MAAMC,SAASD,OAAQ;QAC1B,qDAAqD;QACrD,IAAI,CAAE,CAAA,UAAUC,KAAI,KAAM,CAACA,MAAMC,IAAI,EAAE;YACrC;QACF;QAEA,MAAMC,QAAQJ,IAAI,CAACE,MAAMC,IAAI,CAAC;QAE9B,yEAAyE;QACzE,MAAME,eAAe,kBAAkBH,QAAQA,MAAMG,YAAY,GAAGC;QACpE,MAAMC,aAAaF,iBAAiBC;QACpC,MAAME,aAAa,OAAOH,iBAAiB;QAE3C,sDAAsD;QACtD,IAAIE,cAAcC,YAAY;YAC5B;QACF;QAEA,sCAAsC;QACtC,IAAID,cAAcH,UAAUE,WAAW;YACrC,IAAIG,iBACF,OAAOJ,iBAAiB,WAAWK,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACP,iBAAiBA;YAEhF,gFAAgF;YAChF,IAAIH,MAAMW,IAAI,KAAK,WAAWC,MAAMC,OAAO,CAACN,mBAAmBA,eAAeO,MAAM,KAAK,GAAG;gBAC1FP,iBAAiB;oBACfI,MAAM;oBACNI,aAAaR;gBACf;YACF;YAEAT,IAAI,CAACE,MAAMC,IAAI,CAAC,GAAGM;QACrB;QAEA,wCAAwC;QACxC,MAAMS,eAAelB,IAAI,CAACE,MAAMC,IAAI,CAAC;QAErC,IAAID,MAAMW,IAAI,KAAK,WAAWC,MAAMC,OAAO,CAACG,iBAAiB,YAAYhB,OAAO;YAC9E,uCAAuC;YACvC,KAAK,MAAMiB,WAAWD,aAAc;gBAClC,IAAIC,WAAW,OAAOA,YAAY,UAAU;oBAC1CpB,cAAcoB,SAAoCjB,MAAMD,MAAM;gBAChE;YACF;QACF,OAAO,IAAIC,MAAMW,IAAI,KAAK,WAAWK,gBAAgB,OAAOA,iBAAiB,UAAU;YACrF,iCAAiC;YACjC,IAAI,YAAYhB,OAAO;gBACrBH,cAAcmB,cAAyChB,MAAMD,MAAM;YACrE;QACF,OAAO,IAAIC,MAAMW,IAAI,KAAK,YAAYC,MAAMC,OAAO,CAACG,iBAAiB,YAAYhB,OAAO;YACtF,+BAA+B;YAC/B,KAAK,MAAMiB,WAAWD,aAAc;gBAClC,IAAIC,WAAW,OAAOA,YAAY,YAAY,eAAeA,SAAS;oBACpE,MAAMC,QAAQlB,MAAMmB,MAAM,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKL,QAAQM,SAAS;oBACnE,IAAIL,OAAOnB,QAAQ;wBACjBF,cAAcoB,SAAoCC,MAAMnB,MAAM;oBAChE;gBACF;YACF;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Field, TabAsField } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Cast field values to the appropriate type for Content API storage.
|
|
4
|
+
*
|
|
5
|
+
* This function implements type coercion similar to Mongoose (used by MongoDB adapter)
|
|
6
|
+
* to ensure data consistency. When users ignore TypeScript types and pass incorrect types,
|
|
7
|
+
* we automatically convert them to the expected type.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function castFieldValue(field: Field | TabAsField, value: unknown): unknown;
|
|
11
|
+
//# sourceMappingURL=castFieldValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"castFieldValue.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/castFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmEjF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast field values to the appropriate type for Content API storage.
|
|
3
|
+
*
|
|
4
|
+
* This function implements type coercion similar to Mongoose (used by MongoDB adapter)
|
|
5
|
+
* to ensure data consistency. When users ignore TypeScript types and pass incorrect types,
|
|
6
|
+
* we automatically convert them to the expected type.
|
|
7
|
+
*
|
|
8
|
+
*/ export function castFieldValue(field, value) {
|
|
9
|
+
if (value === null || value === undefined) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
if (field.type === 'number') {
|
|
13
|
+
// Handle hasMany: true - array of numbers
|
|
14
|
+
if ('hasMany' in field && field.hasMany && Array.isArray(value)) {
|
|
15
|
+
return value.map((item)=>{
|
|
16
|
+
if (typeof item === 'number') {
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
if (typeof item === 'string' || typeof item === 'boolean') {
|
|
20
|
+
return Number(item);
|
|
21
|
+
}
|
|
22
|
+
return item // Pass through other types (will likely fail validation)
|
|
23
|
+
;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Handle single number
|
|
27
|
+
if (typeof value !== 'number') {
|
|
28
|
+
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
29
|
+
return Number(value);
|
|
30
|
+
}
|
|
31
|
+
// For objects/arrays (when not hasMany), return as-is (will likely fail validation later)
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (field.type === 'checkbox' && typeof value !== 'boolean') {
|
|
36
|
+
if (typeof value === 'string') {
|
|
37
|
+
if (value.toLowerCase() === 'true' || value === '1') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (value.toLowerCase() === 'false' || value === '0' || value === '') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Boolean(value);
|
|
45
|
+
}
|
|
46
|
+
// Matches Mongoose behavior: stores dates as ISO strings
|
|
47
|
+
if (field.type === 'date' && typeof value !== 'string') {
|
|
48
|
+
if (value instanceof Date) {
|
|
49
|
+
return value.toISOString();
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === 'number') {
|
|
52
|
+
return new Date(value).toISOString();
|
|
53
|
+
}
|
|
54
|
+
// For other types, return as-is (will likely fail validation)
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
// Text-like fields: convert non-strings to JSON strings
|
|
58
|
+
// This handles text, textarea, email, and code fields
|
|
59
|
+
if ((field.type === 'text' || field.type === 'textarea' || field.type === 'email' || field.type === 'code') && typeof value !== 'string') {
|
|
60
|
+
return JSON.stringify(value);
|
|
61
|
+
}
|
|
62
|
+
// No casting needed for other types or already correct types
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=castFieldValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/castFieldValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\n/**\n * Cast field values to the appropriate type for Content API storage.\n *\n * This function implements type coercion similar to Mongoose (used by MongoDB adapter)\n * to ensure data consistency. When users ignore TypeScript types and pass incorrect types,\n * we automatically convert them to the expected type.\n *\n */\nexport function castFieldValue(field: Field | TabAsField, value: unknown): unknown {\n if (value === null || value === undefined) {\n return value\n }\n\n if (field.type === 'number') {\n // Handle hasMany: true - array of numbers\n if ('hasMany' in field && field.hasMany && Array.isArray(value)) {\n return value.map((item) => {\n if (typeof item === 'number') {\n return item\n }\n if (typeof item === 'string' || typeof item === 'boolean') {\n return Number(item)\n }\n return item // Pass through other types (will likely fail validation)\n })\n }\n\n // Handle single number\n if (typeof value !== 'number') {\n if (typeof value === 'string' || typeof value === 'boolean') {\n return Number(value)\n }\n // For objects/arrays (when not hasMany), return as-is (will likely fail validation later)\n return value\n }\n }\n\n if (field.type === 'checkbox' && typeof value !== 'boolean') {\n if (typeof value === 'string') {\n if (value.toLowerCase() === 'true' || value === '1') {\n return true\n }\n if (value.toLowerCase() === 'false' || value === '0' || value === '') {\n return false\n }\n }\n return Boolean(value)\n }\n\n // Matches Mongoose behavior: stores dates as ISO strings\n if (field.type === 'date' && typeof value !== 'string') {\n if (value instanceof Date) {\n return value.toISOString()\n }\n if (typeof value === 'number') {\n return new Date(value).toISOString()\n }\n // For other types, return as-is (will likely fail validation)\n return value\n }\n\n // Text-like fields: convert non-strings to JSON strings\n // This handles text, textarea, email, and code fields\n if (\n (field.type === 'text' ||\n field.type === 'textarea' ||\n field.type === 'email' ||\n field.type === 'code') &&\n typeof value !== 'string'\n ) {\n return JSON.stringify(value)\n }\n\n // No casting needed for other types or already correct types\n return value\n}\n"],"names":["castFieldValue","field","value","undefined","type","hasMany","Array","isArray","map","item","Number","toLowerCase","Boolean","Date","toISOString","JSON","stringify"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,SAASA,eAAeC,KAAyB,EAAEC,KAAc;IACtE,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOD;IACT;IAEA,IAAID,MAAMG,IAAI,KAAK,UAAU;QAC3B,0CAA0C;QAC1C,IAAI,aAAaH,SAASA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|
import type { Payload } from 'payload';
|
|
2
|
-
import type { components } from '
|
|
2
|
+
import type { components } from '../../generated/content-api-types.js';
|
|
3
3
|
type DataWithOperations = components['schemas']['DataWithOperations'];
|
|
4
4
|
/**
|
|
5
5
|
* Transform data before sending to Content API (WRITE operations)
|
|
6
6
|
*
|
|
7
7
|
* Conversions applied:
|
|
8
|
+
* - Default values: Apply static defaults for undefined fields (when applyDefaults=true)
|
|
9
|
+
* - Type casting: Convert values to match field types (e.g., number -> string for text fields)
|
|
8
10
|
* - RichText fields: Objects -> JSON strings
|
|
9
11
|
*
|
|
10
12
|
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
11
13
|
*/
|
|
12
|
-
export declare function dataToContentAPI(payload: Payload, collectionSlug: string, data: unknown
|
|
14
|
+
export declare function dataToContentAPI(payload: Payload, collectionSlug: string, data: unknown, options?: {
|
|
15
|
+
applyDefaults?: boolean;
|
|
16
|
+
}): DataWithOperations;
|
|
13
17
|
/**
|
|
14
18
|
* Transform data received from Content API (READ operations)
|
|
15
19
|
*
|
|
@@ -21,4 +25,4 @@ export declare function dataToContentAPI(payload: Payload, collectionSlug: strin
|
|
|
21
25
|
*/
|
|
22
26
|
export declare function dataFromContentAPI(payload: Payload, collectionSlug: string, data: unknown): unknown;
|
|
23
27
|
export {};
|
|
24
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,OAAO,EAA0B,MAAM,SAAS,CAAA;AAI9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAMtE,KAAK,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAA;AAErE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,GACpC,kBAAkB,CAoEpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,GACZ,OAAO,CA6ET"}
|