@payloadcms/figma 0.0.1-alpha.34 → 0.0.1-alpha.36
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/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +6 -5
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +14 -9
- package/dist/auth/refresh.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +19 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/build-lambda-zip.d.ts +5 -0
- package/dist/commands/build-lambda-zip.d.ts.map +1 -0
- package/dist/commands/build-lambda-zip.js +19 -0
- package/dist/commands/build-lambda-zip.js.map +1 -0
- package/dist/commands/deploy.js +3 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +3 -1
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +8 -5
- package/dist/commands/login.js.map +1 -1
- package/dist/config/oauth.d.ts +3 -17
- package/dist/config/oauth.d.ts.map +1 -1
- package/dist/config/oauth.js +18 -34
- package/dist/config/oauth.js.map +1 -1
- package/dist/constants.d.ts +23 -12
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +31 -12
- package/dist/constants.js.map +1 -1
- package/dist/db-content-api/README.md +0 -10
- package/dist/db-content-api/generated/content-api-types.d.ts +171 -25
- package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -1
- package/dist/db-content-api/generated/content-api-types.js.map +1 -1
- package/dist/db-content-api/index.d.ts.map +1 -1
- package/dist/db-content-api/index.js +7 -8
- package/dist/db-content-api/index.js.map +1 -1
- package/dist/db-content-api/temp-utilities/sorting.d.ts +2 -6
- package/dist/db-content-api/temp-utilities/sorting.d.ts.map +1 -1
- package/dist/db-content-api/temp-utilities/sorting.js +2 -41
- package/dist/db-content-api/temp-utilities/sorting.js.map +1 -1
- package/dist/db-content-api/utilities/data/index.d.ts +2 -0
- package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
- package/dist/db-content-api/utilities/data/index.js +7 -0
- package/dist/db-content-api/utilities/data/index.js.map +1 -1
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +12 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +54 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js.map +1 -0
- package/dist/db-content-api/utilities/joins.d.ts +4 -4
- package/dist/db-content-api/utilities/joins.d.ts.map +1 -1
- package/dist/db-content-api/utilities/joins.js +12 -6
- package/dist/db-content-api/utilities/joins.js.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +0 -3
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
- package/dist/oauth/index.d.ts.map +1 -1
- package/dist/oauth/index.js +0 -1
- package/dist/oauth/index.js.map +1 -1
- package/dist/oauth/strategy/index.d.ts +0 -2
- package/dist/oauth/strategy/index.d.ts.map +1 -1
- package/dist/oauth/strategy/index.js +33 -14
- package/dist/oauth/strategy/index.js.map +1 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +12 -5
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/asset-collection.d.ts +3 -6
- package/dist/utils/asset-collection.d.ts.map +1 -1
- package/dist/utils/asset-collection.js +10 -34
- package/dist/utils/asset-collection.js.map +1 -1
- package/dist/utils/build-lambda-zip.d.ts +14 -0
- package/dist/utils/build-lambda-zip.d.ts.map +1 -0
- package/dist/utils/build-lambda-zip.js +81 -0
- package/dist/utils/build-lambda-zip.js.map +1 -0
- package/dist/utils/config.js +1 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/env-management.js +2 -2
- package/dist/utils/env-management.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +7 -3
- package/dist/utils/formatter.js.map +1 -1
- package/dist/utils/lambda-config.d.ts +3 -1
- package/dist/utils/lambda-config.d.ts.map +1 -1
- package/dist/utils/lambda-config.js +13 -22
- package/dist/utils/lambda-config.js.map +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +2 -0
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +7 -4
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts +7 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +29 -15
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +4 -3
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/typescript-validator.d.ts.map +1 -1
- package/dist/utils/typescript-validator.js +7 -4
- package/dist/utils/typescript-validator.js.map +1 -1
- package/package.json +6 -2
|
@@ -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/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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AAC,EAAEG,OAAO,EAAE;YAChB,MAAMoB,SAASrC,aAAoB;gBAAE8H,SAASH,KAAKlG,GAAG;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
|
+
{"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 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 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 limit: args.limit ?? 0,\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 { 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","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,UAAS;AAC/C,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,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,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ACjFC,MAAM;QACNC,eAAe;QACf/G,MAAM,CAAC,EAAEG,OAAO,EAAE;YAChB,MAAMoB,SAASpC,aAAoB;gBAAE6H,SAASH,KAAKlG,GAAG;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,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,7 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function addFallbackSort(sort: string | string[] | undefined,
|
|
3
|
-
export declare function convertPayloadSortToContentAPI(sort: string | string[] | undefined): Array<{
|
|
4
|
-
direction: 'asc' | 'desc';
|
|
5
|
-
path: string;
|
|
6
|
-
}> | undefined;
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
export declare function addFallbackSort(sort: string | string[] | undefined, payload: Payload, collectionSlug: string): string | string[] | undefined;
|
|
7
3
|
//# sourceMappingURL=sorting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/temp-utilities/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/temp-utilities/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKtC,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACnC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CA8B/B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Add fallback sort to ensure consistent ordering when sorting by non-unique fields
|
|
2
2
|
// Matches MongoDB adapter behavior
|
|
3
3
|
// TO-DECIDE: Should this live here or in content-api?
|
|
4
|
-
export function addFallbackSort(sort,
|
|
4
|
+
export function addFallbackSort(sort, payload, collectionSlug) {
|
|
5
|
+
const collectionConfig = payload.config.collections.find((c)=>c.slug === collectionSlug);
|
|
5
6
|
if (!sort || !collectionConfig) {
|
|
6
7
|
return sort;
|
|
7
8
|
}
|
|
@@ -27,45 +28,5 @@ export function addFallbackSort(sort, collectionConfig) {
|
|
|
27
28
|
fallbackSort
|
|
28
29
|
];
|
|
29
30
|
}
|
|
30
|
-
// ⚠️ TEMPORARY WORKAROUND - Remove once Content API is fixed
|
|
31
|
-
//
|
|
32
|
-
// TODO: Content API should accept Payload's native Sort format instead of requiring conversion.
|
|
33
|
-
// This converter exists because Content API expects a different format.
|
|
34
|
-
//
|
|
35
|
-
// Payload's format: "-createdAt" or ["createdAt", "-updatedAt"]
|
|
36
|
-
// Content API expects: [{ path: "createdAt", direction: "dsc" }]
|
|
37
|
-
//
|
|
38
|
-
// Once Content API accepts Payload's format:
|
|
39
|
-
// 1. Remove this function entirely
|
|
40
|
-
// 2. Remove all calls to convertPayloadSortToContentAPI()
|
|
41
|
-
// 3. Pass `sort` directly to Content API endpoints
|
|
42
|
-
export function convertPayloadSortToContentAPI(sort) {
|
|
43
|
-
if (!sort) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
const sortArray = Array.isArray(sort) ? sort : [
|
|
47
|
-
sort
|
|
48
|
-
];
|
|
49
|
-
return sortArray.map((field)=>{
|
|
50
|
-
let path = field;
|
|
51
|
-
let direction = 'asc';
|
|
52
|
-
// Check if field starts with '-' for descending
|
|
53
|
-
if (field.startsWith('-')) {
|
|
54
|
-
path = field.substring(1); // Remove the '-'
|
|
55
|
-
direction = 'desc';
|
|
56
|
-
}
|
|
57
|
-
// ⚠️ WORKAROUND: Strip "version." prefix from field names
|
|
58
|
-
// Payload sends "-version.createdAt" for version sort fields
|
|
59
|
-
// but Content API expects just "createdAt"
|
|
60
|
-
// TODO: Content API should handle version field paths correctly
|
|
61
|
-
if (path.startsWith('version.')) {
|
|
62
|
-
path = path.substring(8); // Remove "version." prefix
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
direction,
|
|
66
|
-
path
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
31
|
|
|
71
32
|
//# sourceMappingURL=sorting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db-content-api/temp-utilities/sorting.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/db-content-api/temp-utilities/sorting.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n// Add fallback sort to ensure consistent ordering when sorting by non-unique fields\n// Matches MongoDB adapter behavior\n// TO-DECIDE: Should this live here or in content-api?\nexport function addFallbackSort(\n sort: string | string[] | undefined,\n payload: Payload,\n collectionSlug: string,\n): string | string[] | undefined {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n\n if (!sort || !collectionConfig) {\n return sort\n }\n\n const sortArray = Array.isArray(sort) ? sort : [sort]\n\n // Determine fallback sort field\n let fallbackSort = '-id'\n if (collectionConfig.timestamps !== false) {\n fallbackSort = '-createdAt'\n }\n\n // Check if fallback sort is already included\n const hasFallback = sortArray.some(\n (item) => item === fallbackSort || item === fallbackSort.replace('-', ''),\n )\n\n if (hasFallback) {\n return sort\n }\n\n // Check if all sort fields are unique (then no fallback needed)\n // For simplicity, we'll always add fallback - checking uniqueness requires field traversal\n // which would be expensive. This matches the conservative approach.\n\n // Add fallback sort - always return array to preserve multiple sort fields\n return [...sortArray, fallbackSort]\n}\n"],"names":["addFallbackSort","sort","payload","collectionSlug","collectionConfig","config","collections","find","c","slug","sortArray","Array","isArray","fallbackSort","timestamps","hasFallback","some","item","replace"],"mappings":"AAEA,oFAAoF;AACpF,mCAAmC;AACnC,sDAAsD;AACtD,OAAO,SAASA,gBACdC,IAAmC,EACnCC,OAAgB,EAChBC,cAAsB;IAEtB,MAAMC,mBAAmBF,QAAQG,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKN;IAE3E,IAAI,CAACF,QAAQ,CAACG,kBAAkB;QAC9B,OAAOH;IACT;IAEA,MAAMS,YAAYC,MAAMC,OAAO,CAACX,QAAQA,OAAO;QAACA;KAAK;IAErD,gCAAgC;IAChC,IAAIY,eAAe;IACnB,IAAIT,iBAAiBU,UAAU,KAAK,OAAO;QACzCD,eAAe;IACjB;IAEA,6CAA6C;IAC7C,MAAME,cAAcL,UAAUM,IAAI,CAChC,CAACC,OAASA,SAASJ,gBAAgBI,SAASJ,aAAaK,OAAO,CAAC,KAAK;IAGxE,IAAIH,aAAa;QACf,OAAOd;IACT;IAEA,gEAAgE;IAChE,2FAA2F;IAC3F,oEAAoE;IAEpE,2EAA2E;IAC3E,OAAO;WAAIS;QAAWG;KAAa;AACrC"}
|
|
@@ -8,6 +8,7 @@ type DataWithOperations = components['schemas']['DataWithOperations'];
|
|
|
8
8
|
* - Default values: Apply static defaults for undefined fields (when applyDefaults=true)
|
|
9
9
|
* - Type casting: Convert values to match field types (e.g., number -> string for text fields)
|
|
10
10
|
* - RichText fields: Objects -> JSON strings
|
|
11
|
+
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
11
12
|
*
|
|
12
13
|
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
13
14
|
*/
|
|
@@ -19,6 +20,7 @@ export declare function dataToContentAPI(payload: Payload, collectionSlug: strin
|
|
|
19
20
|
*
|
|
20
21
|
* Conversions applied:
|
|
21
22
|
* - RichText fields: JSON strings -> Objects
|
|
23
|
+
* - Virtual fields: Remove fields with `virtual: true` (should not be in DB but Content API backend may add them)
|
|
22
24
|
*
|
|
23
25
|
* Note: Date fields come as ISO strings from Content API and stay as strings
|
|
24
26
|
* (matching MongoDB and other adapters' behavior)
|
|
@@ -1 +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;
|
|
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;AAOtE,KAAK,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAA;AAErE;;;;;;;;;;GAUG;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,CAsEpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,GACZ,OAAO,CAgFT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { flattenAllFields, traverseFields } from 'payload';
|
|
2
2
|
import { applyDefaults } from './applyDefaults.js';
|
|
3
3
|
import { castFieldValue } from './castFieldValue.js';
|
|
4
|
+
import { removeVirtualFields } from './removeVirtualFields.js';
|
|
4
5
|
import { stripFields } from './stripFields.js';
|
|
5
6
|
/**
|
|
6
7
|
* Transform data before sending to Content API (WRITE operations)
|
|
@@ -9,6 +10,7 @@ import { stripFields } from './stripFields.js';
|
|
|
9
10
|
* - Default values: Apply static defaults for undefined fields (when applyDefaults=true)
|
|
10
11
|
* - Type casting: Convert values to match field types (e.g., number -> string for text fields)
|
|
11
12
|
* - RichText fields: Objects -> JSON strings
|
|
13
|
+
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
12
14
|
*
|
|
13
15
|
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
14
16
|
*/ export function dataToContentAPI(payload, collectionSlug, data, options) {
|
|
@@ -55,6 +57,7 @@ import { stripFields } from './stripFields.js';
|
|
|
55
57
|
traverseFields({
|
|
56
58
|
callback,
|
|
57
59
|
fields: collectionConfig.fields,
|
|
60
|
+
fillEmpty: false,
|
|
58
61
|
ref: transformed
|
|
59
62
|
});
|
|
60
63
|
stripFields({
|
|
@@ -69,6 +72,7 @@ import { stripFields } from './stripFields.js';
|
|
|
69
72
|
'globalType'
|
|
70
73
|
]
|
|
71
74
|
});
|
|
75
|
+
removeVirtualFields(transformed, collectionConfig.fields);
|
|
72
76
|
// Convert numeric ID to string for Content API
|
|
73
77
|
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
74
78
|
if (customIDType === 'number') {
|
|
@@ -81,6 +85,7 @@ import { stripFields } from './stripFields.js';
|
|
|
81
85
|
*
|
|
82
86
|
* Conversions applied:
|
|
83
87
|
* - RichText fields: JSON strings -> Objects
|
|
88
|
+
* - Virtual fields: Remove fields with `virtual: true` (should not be in DB but Content API backend may add them)
|
|
84
89
|
*
|
|
85
90
|
* Note: Date fields come as ISO strings from Content API and stay as strings
|
|
86
91
|
* (matching MongoDB and other adapters' behavior)
|
|
@@ -145,6 +150,8 @@ import { stripFields } from './stripFields.js';
|
|
|
145
150
|
'globalType'
|
|
146
151
|
]
|
|
147
152
|
});
|
|
153
|
+
// Remove virtual fields - must happen AFTER stripFields
|
|
154
|
+
removeVirtualFields(transformed, collectionConfig.fields);
|
|
148
155
|
// Handle auth-specific fields that aren't in the field schema
|
|
149
156
|
// When these fields are null in DB, Content API omits them from response (undefined)
|
|
150
157
|
// But Payload expects them to be null, not undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/index.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig, Payload, TraverseFieldsCallback } from 'payload'\n\nimport { flattenAllFields, traverseFields } from 'payload'\n\nimport type { components } from '../../generated/content-api-types.js'\n\nimport { applyDefaults } from './applyDefaults.js'\nimport { castFieldValue } from './castFieldValue.js'\nimport { stripFields } from './stripFields.js'\n\ntype DataWithOperations = components['schemas']['DataWithOperations']\n\n/**\n * Transform data before sending to Content API (WRITE operations)\n *\n * Conversions applied:\n * - Default values: Apply static defaults for undefined fields (when applyDefaults=true)\n * - Type casting: Convert values to match field types (e.g., number -> string for text fields)\n * - RichText fields: Objects -> JSON strings\n *\n * Note: Date fields are automatically converted to ISO strings by JSON.stringify()\n */\nexport function dataToContentAPI(\n payload: Payload,\n collectionSlug: string,\n data: unknown,\n options?: { applyDefaults?: boolean },\n): DataWithOperations {\n if (!data || typeof data !== 'object') {\n return data as DataWithOperations\n }\n\n // Deep clone to avoid mutating original data\n const transformed = JSON.parse(JSON.stringify(data))\n\n // Get collection config\n const isGlobal = collectionSlug.startsWith('_global-')\n const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug\n const collectionConfig: CollectionConfig | GlobalConfig | undefined = isGlobal\n ? payload.config.globals?.find((g) => g.slug === actualSlug)\n : payload.config.collections.find((c) => c.slug === actualSlug)\n\n if (!collectionConfig?.fields) {\n return transformed as DataWithOperations\n }\n\n // Apply static defaults recursively to handle nested structures (arrays, groups)\n // This must happen before traverseFields to ensure defaults are in place\n if (options?.applyDefaults) {\n applyDefaults(transformed, collectionConfig.fields)\n }\n\n // Use Payload's traverseFields to iterate over all fields for transformations\n const callback: TraverseFieldsCallback = ({ field, ref }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n if (!ref || typeof ref !== 'object') {\n return\n }\n\n const current = ref as Record<string, unknown>\n let value = current[field.name]\n\n // Transform existing values\n if (value !== null && value !== undefined) {\n // Step 1: Apply type casting (e.g., number -> string for text fields)\n value = castFieldValue(field, value)\n current[field.name] = value\n\n // Step 2: Apply Content API specific transformations\n // RichText: object -> JSON string\n if (field.type === 'richText' && typeof value !== 'string') {\n current[field.name] = JSON.stringify(value)\n }\n // Date fields are already handled by JSON.stringify() which converts Date -> ISO string\n }\n }\n\n traverseFields({ callback, fields: collectionConfig.fields, ref: transformed })\n\n stripFields({\n config: payload.config,\n data: transformed,\n fields: flattenAllFields({ cache: true, fields: collectionConfig.fields }),\n reservedKeys: ['id', 'globalType'],\n })\n\n // Convert numeric ID to string for Content API\n const customIDType = payload.collections?.[collectionSlug]?.customIDType\n if (customIDType === 'number') {\n transformed.id = String(transformed.id)\n }\n\n return transformed as DataWithOperations\n}\n\n/**\n * Transform data received from Content API (READ operations)\n *\n * Conversions applied:\n * - RichText fields: JSON strings -> Objects\n *\n * Note: Date fields come as ISO strings from Content API and stay as strings\n * (matching MongoDB and other adapters' behavior)\n */\nexport function dataFromContentAPI(\n payload: Payload,\n collectionSlug: string,\n data: unknown,\n): unknown {\n if (!data || typeof data !== 'object') {\n return data\n }\n\n // Deep clone to avoid mutating original data\n const transformed = JSON.parse(JSON.stringify(data))\n\n // Get collection config\n const isGlobal = collectionSlug.startsWith('_global-')\n const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug\n const collectionConfig: CollectionConfig | GlobalConfig | undefined = isGlobal\n ? payload.config.globals?.find((g) => g.slug === actualSlug)\n : payload.config.collections.find((c) => c.slug === actualSlug)\n\n if (!collectionConfig?.fields) {\n return transformed\n }\n\n // Use Payload's traverseFields to iterate over all fields\n const callback: TraverseFieldsCallback = ({ field, parentPath, ref }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n if (!ref || typeof ref !== 'object') {\n return\n }\n\n const current = ref as Record<string, unknown>\n const value = current[field.name]\n\n if (value !== null && value !== undefined) {\n // RichText: JSON string -> object\n if (field.type === 'richText' && typeof value === 'string') {\n try {\n current[field.name] = JSON.parse(value)\n } catch (error) {\n const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name\n payload.logger.warn({\n err: error instanceof Error ? error : new Error(String(error)),\n msg: `Failed to parse richtext field '${fieldPath}' in collection '${collectionSlug}'`,\n })\n }\n }\n // Date fields: Already ISO strings from Content API, no conversion needed\n }\n }\n\n traverseFields({ callback, fields: collectionConfig.fields, ref: transformed })\n\n // Convert string ID to number if collection uses numeric custom ID\n const customIDType = payload.collections?.[collectionSlug]?.customIDType\n if (customIDType === 'number') {\n transformed.id = Number(transformed.id)\n }\n\n stripFields({\n config: payload.config,\n data: transformed,\n fields: flattenAllFields({ cache: true, fields: collectionConfig.fields }),\n reservedKeys: ['id', 'globalType'],\n })\n\n // Handle auth-specific fields that aren't in the field schema\n // When these fields are null in DB, Content API omits them from response (undefined)\n // But Payload expects them to be null, not undefined\n // Only add them if the collection has auth enabled\n if ('auth' in collectionConfig && collectionConfig.auth) {\n const authFields = ['resetPasswordExpiration', 'lockUntil']\n for (const fieldName of authFields) {\n if (!(fieldName in transformed)) {\n transformed[fieldName] = null\n }\n }\n }\n\n return transformed\n}\n"],"names":["flattenAllFields","traverseFields","applyDefaults","castFieldValue","stripFields","dataToContentAPI","payload","collectionSlug","data","options","transformed","JSON","parse","stringify","isGlobal","startsWith","actualSlug","substring","collectionConfig","config","globals","find","g","slug","collections","c","fields","callback","field","ref","name","current","value","undefined","type","cache","reservedKeys","customIDType","id","String","dataFromContentAPI","parentPath","error","fieldPath","logger","warn","err","Error","msg","Number","auth","authFields","fieldName"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAI1D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,WAAW,QAAQ,mBAAkB;AAI9C;;;;;;;;;CASC,GACD,OAAO,SAASC,iBACdC,OAAgB,EAChBC,cAAsB,EACtBC,IAAa,EACbC,OAAqC;IAErC,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU;QACrC,OAAOA;IACT;IAEA,6CAA6C;IAC7C,MAAME,cAAcC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAE9C,wBAAwB;IACxB,MAAMM,WAAWP,eAAeQ,UAAU,CAAC;IAC3C,MAAMC,aAAaF,WAAWP,eAAeU,SAAS,CAAC,KAAKV;IAC5D,MAAMW,mBAAgEJ,WAClER,QAAQa,MAAM,CAACC,OAAO,EAAEC,KAAK,CAACC,IAAMA,EAAEC,IAAI,KAAKP,cAC/CV,QAAQa,MAAM,CAACK,WAAW,CAACH,IAAI,CAAC,CAACI,IAAMA,EAAEF,IAAI,KAAKP;IAEtD,IAAI,CAACE,kBAAkBQ,QAAQ;QAC7B,OAAOhB;IACT;IAEA,iFAAiF;IACjF,yEAAyE;IAC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CAAC,CAAC;oBACxF;gBACF;YACF;QACA,0EAA0E;QAC5E;IACF;IAEAN,eAAe;QAAE0B;QAAUD,QAAQR,iBAAiBQ,MAAM;QAAEG,KAAKnB;IAAY;IAE7E,mEAAmE;IACnE,MAAM2B,eAAe/B,QAAQkB,WAAW,EAAE,CAACjB,eAAe,EAAE8B;IAC5D,IAAIA,iBAAiB,UAAU;QAC7B3B,YAAY4B,EAAE,GAAGW,OAAOvC,YAAY4B,EAAE;IACxC;IAEAlC,YAAY;QACVe,QAAQb,QAAQa,MAAM;QACtBX,MAAME;QACNgB,QAAQ1B,iBAAiB;YAAEmC,OAAO;YAAMT,QAAQR,iBAAiBQ,MAAM;QAAC;QACxEU,cAAc;YAAC;YAAM;SAAa;IACpC;IAEA,8DAA8D;IAC9D,qFAAqF;IACrF,qDAAqD;IACrD,mDAAmD;IACnD,IAAI,UAAUlB,oBAAoBA,iBAAiBgC,IAAI,EAAE;QACvD,MAAMC,aAAa;YAAC;YAA2B;SAAY;QAC3D,KAAK,MAAMC,aAAaD,WAAY;YAClC,IAAI,CAAEC,CAAAA,aAAa1C,WAAU,GAAI;gBAC/BA,WAAW,CAAC0C,UAAU,GAAG;YAC3B;QACF;IACF;IAEA,OAAO1C;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/index.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig, Payload, TraverseFieldsCallback } from 'payload'\n\nimport { flattenAllFields, traverseFields } from 'payload'\n\nimport type { components } from '../../generated/content-api-types.js'\n\nimport { applyDefaults } from './applyDefaults.js'\nimport { castFieldValue } from './castFieldValue.js'\nimport { removeVirtualFields } from './removeVirtualFields.js'\nimport { stripFields } from './stripFields.js'\n\ntype DataWithOperations = components['schemas']['DataWithOperations']\n\n/**\n * Transform data before sending to Content API (WRITE operations)\n *\n * Conversions applied:\n * - Default values: Apply static defaults for undefined fields (when applyDefaults=true)\n * - Type casting: Convert values to match field types (e.g., number -> string for text fields)\n * - RichText fields: Objects -> JSON strings\n * - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)\n *\n * Note: Date fields are automatically converted to ISO strings by JSON.stringify()\n */\nexport function dataToContentAPI(\n payload: Payload,\n collectionSlug: string,\n data: unknown,\n options?: { applyDefaults?: boolean },\n): DataWithOperations {\n if (!data || typeof data !== 'object') {\n return data as DataWithOperations\n }\n\n // Deep clone to avoid mutating original data\n const transformed = JSON.parse(JSON.stringify(data))\n\n // Get collection config\n const isGlobal = collectionSlug.startsWith('_global-')\n const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug\n const collectionConfig: CollectionConfig | GlobalConfig | undefined = isGlobal\n ? payload.config.globals?.find((g) => g.slug === actualSlug)\n : payload.config.collections.find((c) => c.slug === actualSlug)\n\n if (!collectionConfig?.fields) {\n return transformed as DataWithOperations\n }\n\n // Apply static defaults recursively to handle nested structures (arrays, groups)\n // This must happen before traverseFields to ensure defaults are in place\n if (options?.applyDefaults) {\n applyDefaults(transformed, collectionConfig.fields)\n }\n\n // Use Payload's traverseFields to iterate over all fields for transformations\n const callback: TraverseFieldsCallback = ({ field, ref }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n if (!ref || typeof ref !== 'object') {\n return\n }\n\n const current = ref as Record<string, unknown>\n let value = current[field.name]\n\n // Transform existing values\n if (value !== null && value !== undefined) {\n // Step 1: Apply type casting (e.g., number -> string for text fields)\n value = castFieldValue(field, value)\n current[field.name] = value\n\n // Step 2: Apply Content API specific transformations\n // RichText: object -> JSON string\n if (field.type === 'richText' && typeof value !== 'string') {\n current[field.name] = JSON.stringify(value)\n }\n // Date fields are already handled by JSON.stringify() which converts Date -> ISO string\n }\n }\n\n traverseFields({ callback, fields: collectionConfig.fields, fillEmpty: false, ref: transformed })\n\n stripFields({\n config: payload.config,\n data: transformed,\n fields: flattenAllFields({ cache: true, fields: collectionConfig.fields }),\n reservedKeys: ['id', 'globalType'],\n })\n\n removeVirtualFields(transformed, collectionConfig.fields)\n\n // Convert numeric ID to string for Content API\n const customIDType = payload.collections?.[collectionSlug]?.customIDType\n if (customIDType === 'number') {\n transformed.id = String(transformed.id)\n }\n\n return transformed as DataWithOperations\n}\n\n/**\n * Transform data received from Content API (READ operations)\n *\n * Conversions applied:\n * - RichText fields: JSON strings -> Objects\n * - Virtual fields: Remove fields with `virtual: true` (should not be in DB but Content API backend may add them)\n *\n * Note: Date fields come as ISO strings from Content API and stay as strings\n * (matching MongoDB and other adapters' behavior)\n */\nexport function dataFromContentAPI(\n payload: Payload,\n collectionSlug: string,\n data: unknown,\n): unknown {\n if (!data || typeof data !== 'object') {\n return data\n }\n\n // Deep clone to avoid mutating original data\n const transformed = JSON.parse(JSON.stringify(data))\n\n // Get collection config\n const isGlobal = collectionSlug.startsWith('_global-')\n const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug\n const collectionConfig: CollectionConfig | GlobalConfig | undefined = isGlobal\n ? payload.config.globals?.find((g) => g.slug === actualSlug)\n : payload.config.collections.find((c) => c.slug === actualSlug)\n\n if (!collectionConfig?.fields) {\n return transformed\n }\n\n // Use Payload's traverseFields to iterate over all fields\n const callback: TraverseFieldsCallback = ({ field, parentPath, ref }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n if (!ref || typeof ref !== 'object') {\n return\n }\n\n const current = ref as Record<string, unknown>\n const value = current[field.name]\n\n if (value !== null && value !== undefined) {\n // RichText: JSON string -> object\n if (field.type === 'richText' && typeof value === 'string') {\n try {\n current[field.name] = JSON.parse(value)\n } catch (error) {\n const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name\n payload.logger.warn({\n err: error instanceof Error ? error : new Error(String(error)),\n msg: `Failed to parse richtext field '${fieldPath}' in collection '${collectionSlug}'`,\n })\n }\n }\n // Date fields: Already ISO strings from Content API, no conversion needed\n }\n }\n\n traverseFields({ callback, fields: collectionConfig.fields, ref: transformed })\n\n // Convert string ID to number if collection uses numeric custom ID\n const customIDType = payload.collections?.[collectionSlug]?.customIDType\n if (customIDType === 'number') {\n transformed.id = Number(transformed.id)\n }\n\n stripFields({\n config: payload.config,\n data: transformed,\n fields: flattenAllFields({ cache: true, fields: collectionConfig.fields }),\n reservedKeys: ['id', 'globalType'],\n })\n\n // Remove virtual fields - must happen AFTER stripFields\n removeVirtualFields(transformed, collectionConfig.fields)\n\n // Handle auth-specific fields that aren't in the field schema\n // When these fields are null in DB, Content API omits them from response (undefined)\n // But Payload expects them to be null, not undefined\n // Only add them if the collection has auth enabled\n if ('auth' in collectionConfig && collectionConfig.auth) {\n const authFields = ['resetPasswordExpiration', 'lockUntil']\n for (const fieldName of authFields) {\n if (!(fieldName in transformed)) {\n transformed[fieldName] = null\n }\n }\n }\n\n return transformed\n}\n"],"names":["flattenAllFields","traverseFields","applyDefaults","castFieldValue","removeVirtualFields","stripFields","dataToContentAPI","payload","collectionSlug","data","options","transformed","JSON","parse","stringify","isGlobal","startsWith","actualSlug","substring","collectionConfig","config","globals","find","g","slug","collections","c","fields","callback","field","ref","name","current","value","undefined","type","fillEmpty","cache","reservedKeys","customIDType","id","String","dataFromContentAPI","parentPath","error","fieldPath","logger","warn","err","Error","msg","Number","auth","authFields","fieldName"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAI1D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAI9C;;;;;;;;;;CAUC,GACD,OAAO,SAASC,iBACdC,OAAgB,EAChBC,cAAsB,EACtBC,IAAa,EACbC,OAAqC;IAErC,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU;QACrC,OAAOA;IACT;IAEA,6CAA6C;IAC7C,MAAME,cAAcC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAE9C,wBAAwB;IACxB,MAAMM,WAAWP,eAAeQ,UAAU,CAAC;IAC3C,MAAMC,aAAaF,WAAWP,eAAeU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payload';
|
|
2
|
+
/**
|
|
3
|
+
* Removes virtual fields (fields with virtual: true) from data recursively.
|
|
4
|
+
* Virtual fields should never be persisted in the database.
|
|
5
|
+
*
|
|
6
|
+
* @todo It might be a good idea to combine `stripFields` with `stripFields`
|
|
7
|
+
* in a new utility that receives a callback with conditions. I didn't do
|
|
8
|
+
* it now because `stripFields` was copied from db-mongo and I'd like to
|
|
9
|
+
* find a way to unify everything.
|
|
10
|
+
*/
|
|
11
|
+
export declare function removeVirtualFields(data: Record<string, unknown>, fieldConfigs: CollectionConfig['fields']): void;
|
|
12
|
+
//# sourceMappingURL=removeVirtualFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeVirtualFields.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/removeVirtualFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,YAAY,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GACvC,IAAI,CAgDN"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes virtual fields (fields with virtual: true) from data recursively.
|
|
3
|
+
* Virtual fields should never be persisted in the database.
|
|
4
|
+
*
|
|
5
|
+
* @todo It might be a good idea to combine `stripFields` with `stripFields`
|
|
6
|
+
* in a new utility that receives a callback with conditions. I didn't do
|
|
7
|
+
* it now because `stripFields` was copied from db-mongo and I'd like to
|
|
8
|
+
* find a way to unify everything.
|
|
9
|
+
*/ export function removeVirtualFields(data, fieldConfigs) {
|
|
10
|
+
for (const field of fieldConfigs){
|
|
11
|
+
// Handle UI fields (row, collapsible, tabs) - they don't have names
|
|
12
|
+
// but contain other fields that might be virtual
|
|
13
|
+
if (field.type === 'row' || field.type === 'collapsible') {
|
|
14
|
+
if ('fields' in field) {
|
|
15
|
+
removeVirtualFields(data, field.fields);
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (field.type === 'tabs' && 'tabs' in field) {
|
|
20
|
+
for (const tab of field.tabs){
|
|
21
|
+
if ('fields' in tab) {
|
|
22
|
+
removeVirtualFields(data, tab.fields);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
// Skip fields without names
|
|
28
|
+
if (!('name' in field) || !field.name) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// Remove field if it has virtual: true
|
|
32
|
+
if ('virtual' in field && field.virtual === true) {
|
|
33
|
+
delete data[field.name];
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Recursively handle nested structures (groups, arrays with items, etc.)
|
|
37
|
+
if ('fields' in field && field.name in data) {
|
|
38
|
+
const value = data[field.name];
|
|
39
|
+
if (field.type === 'array' && Array.isArray(value)) {
|
|
40
|
+
// Process each array item
|
|
41
|
+
for (const item of value){
|
|
42
|
+
if (item && typeof item === 'object') {
|
|
43
|
+
removeVirtualFields(item, field.fields);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else if (field.type === 'group' && value && typeof value === 'object') {
|
|
47
|
+
// Process group
|
|
48
|
+
removeVirtualFields(value, field.fields);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=removeVirtualFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/removeVirtualFields.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\n/**\n * Removes virtual fields (fields with virtual: true) from data recursively.\n * Virtual fields should never be persisted in the database.\n *\n * @todo It might be a good idea to combine `stripFields` with `stripFields`\n * in a new utility that receives a callback with conditions. I didn't do\n * it now because `stripFields` was copied from db-mongo and I'd like to\n * find a way to unify everything.\n */\nexport function removeVirtualFields(\n data: Record<string, unknown>,\n fieldConfigs: CollectionConfig['fields'],\n): void {\n for (const field of fieldConfigs) {\n // Handle UI fields (row, collapsible, tabs) - they don't have names\n // but contain other fields that might be virtual\n if (field.type === 'row' || field.type === 'collapsible') {\n if ('fields' in field) {\n removeVirtualFields(data, field.fields)\n }\n continue\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n for (const tab of field.tabs) {\n if ('fields' in tab) {\n removeVirtualFields(data, tab.fields)\n }\n }\n continue\n }\n\n // Skip fields without names\n if (!('name' in field) || !field.name) {\n continue\n }\n\n // Remove field if it has virtual: true\n if ('virtual' in field && field.virtual === true) {\n delete data[field.name]\n continue\n }\n\n // Recursively handle nested structures (groups, arrays with items, etc.)\n if ('fields' in field && field.name in data) {\n const value = data[field.name]\n\n if (field.type === 'array' && Array.isArray(value)) {\n // Process each array item\n for (const item of value) {\n if (item && typeof item === 'object') {\n removeVirtualFields(item as Record<string, unknown>, field.fields)\n }\n }\n } else if (field.type === 'group' && value && typeof value === 'object') {\n // Process group\n removeVirtualFields(value as Record<string, unknown>, field.fields)\n }\n }\n }\n}\n"],"names":["removeVirtualFields","data","fieldConfigs","field","type","fields","tab","tabs","name","virtual","value","Array","isArray","item"],"mappings":"AAEA;;;;;;;;CAQC,GACD,OAAO,SAASA,oBACdC,IAA6B,EAC7BC,YAAwC;IAExC,KAAK,MAAMC,SAASD,aAAc;QAChC,oEAAoE;QACpE,iDAAiD;QACjD,IAAIC,MAAMC,IAAI,KAAK,SAASD,MAAMC,IAAI,KAAK,eAAe;YACxD,IAAI,YAAYD,OAAO;gBACrBH,oBAAoBC,MAAME,MAAME,MAAM;YACxC;YACA;QACF;QAEA,IAAIF,MAAMC,IAAI,KAAK,UAAU,UAAUD,OAAO;YAC5C,KAAK,MAAMG,OAAOH,MAAMI,IAAI,CAAE;gBAC5B,IAAI,YAAYD,KAAK;oBACnBN,oBAAoBC,MAAMK,IAAID,MAAM;gBACtC;YACF;YACA;QACF;QAEA,4BAA4B;QAC5B,IAAI,CAAE,CAAA,UAAUF,KAAI,KAAM,CAACA,MAAMK,IAAI,EAAE;YACrC;QACF;QAEA,uCAAuC;QACvC,IAAI,aAAaL,SAASA,MAAMM,OAAO,KAAK,MAAM;YAChD,OAAOR,IAAI,CAACE,MAAMK,IAAI,CAAC;YACvB;QACF;QAEA,yEAAyE;QACzE,IAAI,YAAYL,SAASA,MAAMK,IAAI,IAAIP,MAAM;YAC3C,MAAMS,QAAQT,IAAI,CAACE,MAAMK,IAAI,CAAC;YAE9B,IAAIL,MAAMC,IAAI,KAAK,WAAWO,MAAMC,OAAO,CAACF,QAAQ;gBAClD,0BAA0B;gBAC1B,KAAK,MAAMG,QAAQH,MAAO;oBACxB,IAAIG,QAAQ,OAAOA,SAAS,UAAU;wBACpCb,oBAAoBa,MAAiCV,MAAME,MAAM;oBACnE;gBACF;YACF,OAAO,IAAIF,MAAMC,IAAI,KAAK,WAAWM,SAAS,OAAOA,UAAU,UAAU;gBACvE,gBAAgB;gBAChBV,oBAAoBU,OAAkCP,MAAME,MAAM;YACpE;QACF;IACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JoinQuery, Payload
|
|
1
|
+
import type { JoinQuery, Payload } from 'payload';
|
|
2
2
|
import type { components } from '../generated/content-api-types.js';
|
|
3
3
|
type ContentAPIJoin = components['schemas']['JoinClause'][number];
|
|
4
4
|
/**
|
|
@@ -26,7 +26,7 @@ type ContentAPIJoin = components['schemas']['JoinClause'][number];
|
|
|
26
26
|
* Payload's JoinQuery format (at runtime):
|
|
27
27
|
* {
|
|
28
28
|
* 'group.relatedPosts': { // joinPath - where results go in the document
|
|
29
|
-
* sort: '-title',
|
|
29
|
+
* sort: '-title',
|
|
30
30
|
* limit: 10,
|
|
31
31
|
* page: 2, // page-based pagination
|
|
32
32
|
* where: { ... }, // Payload where format
|
|
@@ -41,7 +41,7 @@ type ContentAPIJoin = components['schemas']['JoinClause'][number];
|
|
|
41
41
|
* path: 'group.relatedPosts', // where to put results
|
|
42
42
|
* count: false,
|
|
43
43
|
* where: { ... }, // Content API where format
|
|
44
|
-
* sort:
|
|
44
|
+
* sort: '-title',
|
|
45
45
|
* limit: 10,
|
|
46
46
|
* offset: 10 // offset-based pagination
|
|
47
47
|
* }]
|
|
@@ -50,6 +50,6 @@ type ContentAPIJoin = components['schemas']['JoinClause'][number];
|
|
|
50
50
|
* - Which collection each join field refers to
|
|
51
51
|
* - What the 'on' field is for each join
|
|
52
52
|
*/
|
|
53
|
-
export declare function convertPayloadJoinsToContentAPI(payload: Payload,
|
|
53
|
+
export declare function convertPayloadJoinsToContentAPI(payload: Payload, collectionSlug: string, joins: false | JoinQuery | undefined): ContentAPIJoin[] | undefined;
|
|
54
54
|
export {};
|
|
55
55
|
//# sourceMappingURL=joins.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joins.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/utilities/joins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"joins.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/utilities/joins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAMnE,KAAK,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GACnC,cAAc,EAAE,GAAG,SAAS,CAyF9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addFallbackSort } from '../temp-utilities/sorting.js';
|
|
2
2
|
import { convertPayloadWhereToContentAPI } from './where.js';
|
|
3
3
|
/**
|
|
4
4
|
* Convert Payload's JoinQuery to Content API's join format.
|
|
@@ -25,7 +25,7 @@ import { convertPayloadWhereToContentAPI } from './where.js';
|
|
|
25
25
|
* Payload's JoinQuery format (at runtime):
|
|
26
26
|
* {
|
|
27
27
|
* 'group.relatedPosts': { // joinPath - where results go in the document
|
|
28
|
-
* sort: '-title',
|
|
28
|
+
* sort: '-title',
|
|
29
29
|
* limit: 10,
|
|
30
30
|
* page: 2, // page-based pagination
|
|
31
31
|
* where: { ... }, // Payload where format
|
|
@@ -40,7 +40,7 @@ import { convertPayloadWhereToContentAPI } from './where.js';
|
|
|
40
40
|
* path: 'group.relatedPosts', // where to put results
|
|
41
41
|
* count: false,
|
|
42
42
|
* where: { ... }, // Content API where format
|
|
43
|
-
* sort:
|
|
43
|
+
* sort: '-title',
|
|
44
44
|
* limit: 10,
|
|
45
45
|
* offset: 10 // offset-based pagination
|
|
46
46
|
* }]
|
|
@@ -48,7 +48,11 @@ import { convertPayloadWhereToContentAPI } from './where.js';
|
|
|
48
48
|
* The mapping requires the collection config to resolve:
|
|
49
49
|
* - Which collection each join field refers to
|
|
50
50
|
* - What the 'on' field is for each join
|
|
51
|
-
*/ export function convertPayloadJoinsToContentAPI(payload,
|
|
51
|
+
*/ export function convertPayloadJoinsToContentAPI(payload, collectionSlug, joins) {
|
|
52
|
+
const collectionConfig = payload.config.collections.find((c)=>c.slug === collectionSlug);
|
|
53
|
+
if (!collectionConfig) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
52
56
|
// joins === false means explicitly disable all joins
|
|
53
57
|
// joins === undefined means use defaults (no custom query params)
|
|
54
58
|
if (joins === false || !joins) {
|
|
@@ -104,6 +108,8 @@ import { convertPayloadWhereToContentAPI } from './where.js';
|
|
|
104
108
|
if (joinQuery.page && joinQuery.page > 1 && joinQuery.limit) {
|
|
105
109
|
offset = (joinQuery.page - 1) * joinQuery.limit;
|
|
106
110
|
}
|
|
111
|
+
// Add fallback sort for the joined collection
|
|
112
|
+
const sortWithFallback = addFallbackSort(joinQuery.sort, payload, foundJoin.collectionSlug);
|
|
107
113
|
const contentAPIJoin = {
|
|
108
114
|
collectionId: foundJoin.collectionSlug,
|
|
109
115
|
count: joinQuery.count ?? false,
|
|
@@ -115,8 +121,8 @@ import { convertPayloadWhereToContentAPI } from './where.js';
|
|
|
115
121
|
...offset !== undefined && {
|
|
116
122
|
offset
|
|
117
123
|
},
|
|
118
|
-
...
|
|
119
|
-
sort:
|
|
124
|
+
...sortWithFallback && {
|
|
125
|
+
sort: sortWithFallback
|
|
120
126
|
},
|
|
121
127
|
...joinQuery.where && {
|
|
122
128
|
where: convertPayloadWhereToContentAPI(joinQuery.where)
|