@payloadcms/figma 0.0.1-alpha.44 → 0.0.1-alpha.45
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/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +90 -54
- package/dist/api/control-plane.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/debug.d.ts +8 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +156 -0
- package/dist/commands/debug.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +17 -14
- package/dist/commands/init.js.map +1 -1
- package/dist/db-content-api/index.d.ts.map +1 -1
- package/dist/db-content-api/index.js +26 -7
- package/dist/db-content-api/index.js.map +1 -1
- package/dist/db-content-api/temp-utilities/types.d.ts +22 -0
- package/dist/db-content-api/temp-utilities/types.d.ts.map +1 -0
- package/dist/db-content-api/temp-utilities/types.js +15 -0
- package/dist/db-content-api/temp-utilities/types.js.map +1 -0
- package/dist/db-content-api/utilities/data/index.d.ts +14 -4
- package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
- package/dist/db-content-api/utilities/data/index.js +15 -8
- package/dist/db-content-api/utilities/data/index.js.map +1 -1
- package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +23 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.js +42 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.js.map +1 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts.map +1 -1
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +11 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js.map +1 -1
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +17 -2
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts.map +1 -1
- package/dist/db-content-api/utilities/meta/buildMeta.js +4 -1
- package/dist/db-content-api/utilities/meta/buildMeta.js.map +1 -1
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +8 -2
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts.map +1 -1
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +41 -11
- package/dist/db-content-api/utilities/meta/buildPathTypes.js.map +1 -1
- package/dist/db-content-api/utilities/where.d.ts +8 -0
- package/dist/db-content-api/utilities/where.d.ts.map +1 -1
- package/dist/db-content-api/utilities/where.js +6 -0
- package/dist/db-content-api/utilities/where.js.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +18 -13
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
- package/dist/templates/README.md +1 -1
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +0 -2
- package/dist/types/config.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/lambda-config.d.ts +1 -1
- package/dist/utils/lambda-config.d.ts.map +1 -1
- package/dist/utils/lambda-config.js +2 -2
- package/dist/utils/lambda-config.js.map +1 -1
- package/dist/utils/messages.d.ts +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +1 -0
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/package-manager.d.ts +24 -0
- package/dist/utils/package-manager.d.ts.map +1 -1
- package/dist/utils/package-manager.js +53 -0
- package/dist/utils/package-manager.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +1 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +4 -3
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +4 -2
- package/dist/utils/project.js.map +1 -1
- package/package.json +1 -1
- package/dist/db-content-api/utilities/meta/index.d.ts +0 -5
- package/dist/db-content-api/utilities/meta/index.d.ts.map +0 -1
- package/dist/db-content-api/utilities/meta/index.js +0 -5
- package/dist/db-content-api/utilities/meta/index.js.map +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathType can be either a simple string type or an object with additional metadata.
|
|
3
|
+
*
|
|
4
|
+
* Simple types: "array" - for array fields, blocks, or hasMany relationships/selects
|
|
5
|
+
*
|
|
6
|
+
* Relationship types include collection info needed for Content API to perform JOINs:
|
|
7
|
+
* - type: "relationship" for stored references, "join" for virtual reverse lookups
|
|
8
|
+
* - collection: target collection slug (or array for polymorphic)
|
|
9
|
+
* - hasMany: whether it stores multiple references
|
|
10
|
+
*
|
|
11
|
+
* TODO: This type is defined here temporarily so Content API can test the integration.
|
|
12
|
+
* Once Content API implements support for this, the type should be generated from openapi.json.
|
|
13
|
+
*/ export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/db-content-api/temp-utilities/types.ts"],"sourcesContent":["/**\n * PathType can be either a simple string type or an object with additional metadata.\n *\n * Simple types: \"array\" - for array fields, blocks, or hasMany relationships/selects\n *\n * Relationship types include collection info needed for Content API to perform JOINs:\n * - type: \"relationship\" for stored references, \"join\" for virtual reverse lookups\n * - collection: target collection slug (or array for polymorphic)\n * - hasMany: whether it stores multiple references\n *\n * TODO: This type is defined here temporarily so Content API can test the integration.\n * Once Content API implements support for this, the type should be generated from openapi.json.\n */\nexport type PathTypeValue =\n | 'array'\n | {\n collection: string | string[]\n hasMany?: boolean\n /** For join fields, the field path in the related collection that points back */\n on?: string\n type: 'join' | 'relationship'\n }\n\nexport type PathTypesRecord = Record<string, PathTypeValue>\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAWD,WAA2D"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { Payload } from 'payload';
|
|
2
2
|
import type { components } from '../../generated/content-api-types.js';
|
|
3
3
|
type DataWithOperations = components['schemas']['DataWithOperations'];
|
|
4
|
+
interface DataToContentAPIOptions {
|
|
5
|
+
/** Apply static defaults for undefined fields */
|
|
6
|
+
applyDefaults?: boolean;
|
|
7
|
+
/** Add createdAt timestamp */
|
|
8
|
+
createdAt?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Transform publishedLocale to localizeStatus format.
|
|
11
|
+
* When provided, converts `_status: 'published'` + `publishedLocale: 'en'`
|
|
12
|
+
* to `_status: { en: 'published' }` format.
|
|
13
|
+
*/
|
|
14
|
+
publishedLocale?: string;
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
* Transform data before sending to Content API (WRITE operations)
|
|
6
18
|
*
|
|
@@ -10,13 +22,11 @@ type DataWithOperations = components['schemas']['DataWithOperations'];
|
|
|
10
22
|
* - RichText fields: Objects -> JSON strings
|
|
11
23
|
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
12
24
|
* - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)
|
|
25
|
+
* - publishedLocale: Transform to localizeStatus format (when publishedLocale is provided)
|
|
13
26
|
*
|
|
14
27
|
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
15
28
|
*/
|
|
16
|
-
export declare function dataToContentAPI(payload: Payload, collectionSlug: string, data: unknown, options?:
|
|
17
|
-
applyDefaults?: boolean;
|
|
18
|
-
createdAt?: boolean;
|
|
19
|
-
}): DataWithOperations;
|
|
29
|
+
export declare function dataToContentAPI(payload: Payload, collectionSlug: string, data: unknown, options?: DataToContentAPIOptions): DataWithOperations;
|
|
20
30
|
/**
|
|
21
31
|
* Transform data received from Content API (READ operations)
|
|
22
32
|
*
|
|
@@ -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;AAQtE,KAAK,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAA;AAErE,UAAU,uBAAuB;IAC/B,iDAAiD;IACjD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,uBAAuB,GAChC,kBAAkB,CAoFpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,GACZ,OAAO,CA4GT"}
|
|
@@ -3,6 +3,7 @@ import { applyDefaults } from './applyDefaults.js';
|
|
|
3
3
|
import { castFieldValue } from './castFieldValue.js';
|
|
4
4
|
import { removeVirtualFields } from './removeVirtualFields.js';
|
|
5
5
|
import { stripFields } from './stripFields.js';
|
|
6
|
+
import { transformToLocalizeStatus } from './transformPublishedLocale.js';
|
|
6
7
|
/**
|
|
7
8
|
* Transform data before sending to Content API (WRITE operations)
|
|
8
9
|
*
|
|
@@ -12,14 +13,17 @@ import { stripFields } from './stripFields.js';
|
|
|
12
13
|
* - RichText fields: Objects -> JSON strings
|
|
13
14
|
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
14
15
|
* - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)
|
|
16
|
+
* - publishedLocale: Transform to localizeStatus format (when publishedLocale is provided)
|
|
15
17
|
*
|
|
16
18
|
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
17
19
|
*/ export function dataToContentAPI(payload, collectionSlug, data, options) {
|
|
18
20
|
if (!data || typeof data !== 'object') {
|
|
19
21
|
return data;
|
|
20
22
|
}
|
|
23
|
+
// Transform publishedLocale to localizeStatus format before other transformations
|
|
24
|
+
const dataWithLocalizedStatus = transformToLocalizeStatus(data, options?.publishedLocale);
|
|
21
25
|
// Deep clone to avoid mutating original data
|
|
22
|
-
const transformed = JSON.parse(JSON.stringify(
|
|
26
|
+
const transformed = JSON.parse(JSON.stringify(dataWithLocalizedStatus));
|
|
23
27
|
// Get collection config
|
|
24
28
|
const isGlobal = collectionSlug.startsWith('_global-');
|
|
25
29
|
const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug;
|
|
@@ -134,15 +138,18 @@ import { stripFields } from './stripFields.js';
|
|
|
134
138
|
// Content API may store localized fields as JSON strings like "{\"en\":\"value\"}"
|
|
135
139
|
// so we need to parse them back to objects.
|
|
136
140
|
// Note: We return the full locale object - Payload Core handles flattening to requested locale.
|
|
141
|
+
// When requesting a specific locale (not 'all'), values are simple strings that won't parse.
|
|
142
|
+
// In that case, we silently keep the original value.
|
|
137
143
|
if ('localized' in field && field.localized && typeof value === 'string') {
|
|
138
144
|
try {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
const parsed = JSON.parse(value);
|
|
146
|
+
// Only use parsed value if it's actually an object (locale -> value mapping)
|
|
147
|
+
// Simple strings like "EN Title" would parse to themselves, which we don't want
|
|
148
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
149
|
+
current[field.name] = parsed;
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
// Not valid JSON - keep original value (this is expected for single-locale requests)
|
|
146
153
|
}
|
|
147
154
|
} else if (field.type === 'richText' && typeof value === 'string') {
|
|
148
155
|
try {
|
|
@@ -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 { 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 * - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)\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; createdAt?: 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 // Add timestamps (Content API no longer auto-sets these in DB)\n // updatedAt is always set, createdAt only on create operations\n const now = new Date().toISOString()\n transformed.updatedAt = now\n if (options?.createdAt) {\n transformed.createdAt = now\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 // Normalize undefined → null for optional fields\n // Content API may omit fields (undefined) but Payload expects null for optional fields\n if (value === undefined) {\n const isRequired = 'required' in field && field.required\n if (!isRequired) {\n current[field.name] = null\n }\n return\n }\n\n if (value !== null) {\n // Localized fields: JSON string -> parsed object\n // Content API may store localized fields as JSON strings like \"{\\\"en\\\":\\\"value\\\"}\"\n // so we need to parse them back to objects.\n // Note: We return the full locale object - Payload Core handles flattening to requested locale.\n if ('localized' in field && field.localized && 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 localized field '${fieldPath}' in collection '${collectionSlug}'`,\n })\n }\n }\n // RichText: JSON string -> object\n else 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, fillEmpty: false, 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","now","Date","toISOString","updatedAt","createdAt","dataFromContentAPI","parentPath","isRequired","required","localized","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;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,iBACdC,OAAgB,EAChBC,cAAsB,EACtBC,IAAa,EACbC,OAA0D;IAE1D,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU;QACrC,OAAOA;IACT;IAEA,6CAA6C;IAC7C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AAKJ,iBAAiBK,QAAQL,QAAQ,IAAIK,MAAMhB,OAAOW;wBACvDM,KAAK,CAAC,gCAAgC,EAAEL,UAAU,iBAAiB,EAAE7C,eAAe,CAAC,CAAC;oBACxF;gBACF;YACF;QACA,0EAA0E;QAC5E;IACF;IAEAP,eAAe;QAAE2B;QAAUD,QAAQR,iBAAiBQ,MAAM;QAAES,WAAW;QAAON,KAAKnB;IAAY;IAE/F,mEAAmE;IACnE,MAAM4B,eAAehC,QAAQkB,WAAW,EAAE,CAACjB,eAAe,EAAE+B;IAC5D,IAAIA,iBAAiB,UAAU;QAC7B5B,YAAY6B,EAAE,GAAGmB,OAAOhD,YAAY6B,EAAE;IACxC;IAEAnC,YAAY;QACVe,QAAQb,QAAQa,MAAM;QACtBX,MAAME;QACNgB,QAAQ3B,iBAAiB;YAAEqC,OAAO;YAAMV,QAAQR,iBAAiBQ,MAAM;QAAC;QACxEW,cAAc;YAAC;YAAM;SAAa;IACpC;IAEA,wDAAwD;IACxDlC,oBAAoBO,aAAaQ,iBAAiBQ,MAAM;IAExD,8DAA8D;IAC9D,qFAAqF;IACrF,qDAAqD;IACrD,mDAAmD;IACnD,IAAI,UAAUR,oBAAoBA,iBAAiByC,IAAI,EAAE;QACvD,MAAMC,aAAa;YAAC;YAA2B;SAAY;QAC3D,KAAK,MAAMC,aAAaD,WAAY;YAClC,IAAI,CAAEC,CAAAA,aAAanD,WAAU,GAAI;gBAC/BA,WAAW,CAACmD,UAAU,GAAG;YAC3B;QACF;IACF;IAEA,OAAOnD;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'\nimport { transformToLocalizeStatus } from './transformPublishedLocale.js'\n\ntype DataWithOperations = components['schemas']['DataWithOperations']\n\ninterface DataToContentAPIOptions {\n /** Apply static defaults for undefined fields */\n applyDefaults?: boolean\n /** Add createdAt timestamp */\n createdAt?: boolean\n /**\n * Transform publishedLocale to localizeStatus format.\n * When provided, converts `_status: 'published'` + `publishedLocale: 'en'`\n * to `_status: { en: 'published' }` format.\n */\n publishedLocale?: string\n}\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 * - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)\n * - publishedLocale: Transform to localizeStatus format (when publishedLocale is provided)\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?: DataToContentAPIOptions,\n): DataWithOperations {\n if (!data || typeof data !== 'object') {\n return data as DataWithOperations\n }\n\n // Transform publishedLocale to localizeStatus format before other transformations\n const dataWithLocalizedStatus = transformToLocalizeStatus(\n data as Record<string, unknown>,\n options?.publishedLocale,\n )\n\n // Deep clone to avoid mutating original data\n const transformed = JSON.parse(JSON.stringify(dataWithLocalizedStatus))\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 // Add timestamps (Content API no longer auto-sets these in DB)\n // updatedAt is always set, createdAt only on create operations\n const now = new Date().toISOString()\n transformed.updatedAt = now\n if (options?.createdAt) {\n transformed.createdAt = now\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 // Normalize undefined → null for optional fields\n // Content API may omit fields (undefined) but Payload expects null for optional fields\n if (value === undefined) {\n const isRequired = 'required' in field && field.required\n if (!isRequired) {\n current[field.name] = null\n }\n return\n }\n\n if (value !== null) {\n // Localized fields: JSON string -> parsed object\n // Content API may store localized fields as JSON strings like \"{\\\"en\\\":\\\"value\\\"}\"\n // so we need to parse them back to objects.\n // Note: We return the full locale object - Payload Core handles flattening to requested locale.\n // When requesting a specific locale (not 'all'), values are simple strings that won't parse.\n // In that case, we silently keep the original value.\n if ('localized' in field && field.localized && typeof value === 'string') {\n try {\n const parsed = JSON.parse(value)\n // Only use parsed value if it's actually an object (locale -> value mapping)\n // Simple strings like \"EN Title\" would parse to themselves, which we don't want\n if (typeof parsed === 'object' && parsed !== null) {\n current[field.name] = parsed\n }\n } catch {\n // Not valid JSON - keep original value (this is expected for single-locale requests)\n }\n }\n // RichText: JSON string -> object\n else 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, fillEmpty: false, 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","transformToLocalizeStatus","dataToContentAPI","payload","collectionSlug","data","options","dataWithLocalizedStatus","publishedLocale","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","now","Date","toISOString","updatedAt","createdAt","dataFromContentAPI","parentPath","isRequired","required","localized","parsed","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;AAC9C,SAASC,yBAAyB,QAAQ,gCAA+B;AAiBzE;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,iBACdC,OAAgB,EAChBC,cAAsB,EACtBC,IAAa,EACbC,OAAiC;IAEjC,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU;QACrC,OAAOA;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AMjB,OAAOY;wBACvDM,KAAK,CAAC,gCAAgC,EAAEL,UAAU,iBAAiB,EAAEhD,eAAe,CAAC,CAAC;oBACxF;gBACF;YACF;QACA,0EAA0E;QAC5E;IACF;IAEAR,eAAe;QAAE8B;QAAUD,QAAQR,iBAAiBQ,MAAM;QAAES,WAAW;QAAON,KAAKnB;IAAY;IAE/F,mEAAmE;IACnE,MAAM4B,eAAelC,QAAQoB,WAAW,EAAE,CAACnB,eAAe,EAAEiC;IAC5D,IAAIA,iBAAiB,UAAU;QAC7B5B,YAAY6B,EAAE,GAAGoB,OAAOjD,YAAY6B,EAAE;IACxC;IAEAtC,YAAY;QACVkB,QAAQf,QAAQe,MAAM;QACtBb,MAAMI;QACNgB,QAAQ9B,iBAAiB;YAAEwC,OAAO;YAAMV,QAAQR,iBAAiBQ,MAAM;QAAC;QACxEW,cAAc;YAAC;YAAM;SAAa;IACpC;IAEA,wDAAwD;IACxDrC,oBAAoBU,aAAaQ,iBAAiBQ,MAAM;IAExD,8DAA8D;IAC9D,qFAAqF;IACrF,qDAAqD;IACrD,mDAAmD;IACnD,IAAI,UAAUR,oBAAoBA,iBAAiB0C,IAAI,EAAE;QACvD,MAAMC,aAAa;YAAC;YAA2B;SAAY;QAC3D,KAAK,MAAMC,aAAaD,WAAY;YAClC,IAAI,CAAEC,CAAAA,aAAapD,WAAU,GAAI;gBAC/BA,WAAW,CAACoD,UAAU,GAAG;YAC3B;QACF;IACF;IAEA,OAAOpD;AACT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform publishedLocale to localizeStatus format
|
|
3
|
+
*
|
|
4
|
+
* publishedLocale is a legacy API that is going to be removed in Payload v4 in favor of localizeStatus.
|
|
5
|
+
* The db-adapter transforms publishedLocale here so Content API doesn't need to know about it.
|
|
6
|
+
*/
|
|
7
|
+
type VersionData = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Transforms version data to use localizeStatus format
|
|
10
|
+
*
|
|
11
|
+
* If `publishedLocale` is provided and `_status` is a string, transforms to object format.
|
|
12
|
+
* If `_status` is already an object, leaves it unchanged.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Input (old format):
|
|
16
|
+
* { _status: 'published', text: 'Hello' }, publishedLocale: 'en'
|
|
17
|
+
*
|
|
18
|
+
* // Output (new format):
|
|
19
|
+
* { _status: { en: 'published' }, text: 'Hello' }
|
|
20
|
+
*/
|
|
21
|
+
export declare function transformToLocalizeStatus(versionData: VersionData, publishedLocale?: string): VersionData;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=transformPublishedLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformPublishedLocale.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/data/transformPublishedLocale.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1C;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,WAAW,EACxB,eAAe,CAAC,EAAE,MAAM,GACvB,WAAW,CA0Bb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform publishedLocale to localizeStatus format
|
|
3
|
+
*
|
|
4
|
+
* publishedLocale is a legacy API that is going to be removed in Payload v4 in favor of localizeStatus.
|
|
5
|
+
* The db-adapter transforms publishedLocale here so Content API doesn't need to know about it.
|
|
6
|
+
*/ /**
|
|
7
|
+
* Transforms version data to use localizeStatus format
|
|
8
|
+
*
|
|
9
|
+
* If `publishedLocale` is provided and `_status` is a string, transforms to object format.
|
|
10
|
+
* If `_status` is already an object, leaves it unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Input (old format):
|
|
14
|
+
* { _status: 'published', text: 'Hello' }, publishedLocale: 'en'
|
|
15
|
+
*
|
|
16
|
+
* // Output (new format):
|
|
17
|
+
* { _status: { en: 'published' }, text: 'Hello' }
|
|
18
|
+
*/ export function transformToLocalizeStatus(versionData, publishedLocale) {
|
|
19
|
+
// No publishedLocale provided - no transformation needed
|
|
20
|
+
if (!publishedLocale) {
|
|
21
|
+
return versionData;
|
|
22
|
+
}
|
|
23
|
+
const status = versionData._status;
|
|
24
|
+
// If _status is already an object (localizeStatus format), return as-is
|
|
25
|
+
if (typeof status === 'object' && status !== null) {
|
|
26
|
+
return versionData;
|
|
27
|
+
}
|
|
28
|
+
// Transform: publishedLocale + string status → object status
|
|
29
|
+
if (typeof status === 'string') {
|
|
30
|
+
// Only the specified locale gets the status, others remain undefined
|
|
31
|
+
// (Content API / Payload will handle merging with existing locale statuses)
|
|
32
|
+
return {
|
|
33
|
+
...versionData,
|
|
34
|
+
_status: {
|
|
35
|
+
[publishedLocale]: status
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return versionData;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=transformPublishedLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/data/transformPublishedLocale.ts"],"sourcesContent":["/**\n * Transform publishedLocale to localizeStatus format\n *\n * publishedLocale is a legacy API that is going to be removed in Payload v4 in favor of localizeStatus.\n * The db-adapter transforms publishedLocale here so Content API doesn't need to know about it.\n */\n\ntype VersionData = Record<string, unknown>\n\n/**\n * Transforms version data to use localizeStatus format\n *\n * If `publishedLocale` is provided and `_status` is a string, transforms to object format.\n * If `_status` is already an object, leaves it unchanged.\n *\n * @example\n * // Input (old format):\n * { _status: 'published', text: 'Hello' }, publishedLocale: 'en'\n *\n * // Output (new format):\n * { _status: { en: 'published' }, text: 'Hello' }\n */\nexport function transformToLocalizeStatus(\n versionData: VersionData,\n publishedLocale?: string,\n): VersionData {\n // No publishedLocale provided - no transformation needed\n if (!publishedLocale) {\n return versionData\n }\n\n const status = versionData._status\n\n // If _status is already an object (localizeStatus format), return as-is\n if (typeof status === 'object' && status !== null) {\n return versionData\n }\n\n // Transform: publishedLocale + string status → object status\n if (typeof status === 'string') {\n // Only the specified locale gets the status, others remain undefined\n // (Content API / Payload will handle merging with existing locale statuses)\n return {\n ...versionData,\n _status: {\n [publishedLocale]: status,\n },\n }\n }\n\n return versionData\n}\n"],"names":["transformToLocalizeStatus","versionData","publishedLocale","status","_status"],"mappings":"AAAA;;;;;CAKC,GAID;;;;;;;;;;;;CAYC,GACD,OAAO,SAASA,0BACdC,WAAwB,EACxBC,eAAwB;IAExB,yDAAyD;IACzD,IAAI,CAACA,iBAAiB;QACpB,OAAOD;IACT;IAEA,MAAME,SAASF,YAAYG,OAAO;IAElC,wEAAwE;IACxE,IAAI,OAAOD,WAAW,YAAYA,WAAW,MAAM;QACjD,OAAOF;IACT;IAEA,6DAA6D;IAC7D,IAAI,OAAOE,WAAW,UAAU;QAC9B,qEAAqE;QACrE,4EAA4E;QAC5E,OAAO;YACL,GAAGF,WAAW;YACdG,SAAS;gBACP,CAACF,gBAAgB,EAAEC;YACrB;QACF;IACF;IAEA,OAAOF;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildLocalizedPaths.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildLocalizedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"buildLocalizedPaths.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildLocalizedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAsCtF"}
|
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
}
|
|
13
13
|
const localizedPaths = [];
|
|
14
14
|
traverseFields(collectionConfig.fields, localizedPaths);
|
|
15
|
+
// Add _status to localized paths if localizeStatus is enabled for this collection
|
|
16
|
+
// _status is a base field added by Payload when versions.drafts is enabled,
|
|
17
|
+
// and it becomes localized when versions.drafts.localizeStatus is true
|
|
18
|
+
// localizeStatus requires both experimental flag AND collection-level config
|
|
19
|
+
const experimentalLocalizeStatus = 'experimental' in payload.config && payload.config.experimental && typeof payload.config.experimental === 'object' && 'localizeStatus' in payload.config.experimental && payload.config.experimental.localizeStatus === true;
|
|
20
|
+
const drafts = collectionConfig.versions && typeof collectionConfig.versions === 'object' ? collectionConfig.versions.drafts : false;
|
|
21
|
+
const collectionLocalizeStatus = drafts && typeof drafts === 'object' && 'localizeStatus' in drafts && drafts.localizeStatus === true;
|
|
22
|
+
const hasLocalizeStatus = payload.config.localization && experimentalLocalizeStatus && collectionLocalizeStatus;
|
|
23
|
+
if (hasLocalizeStatus && !localizedPaths.includes('_status')) {
|
|
24
|
+
localizedPaths.push('_status');
|
|
25
|
+
}
|
|
15
26
|
return localizedPaths;
|
|
16
27
|
}
|
|
17
28
|
/** Recursively traverses fields to find and collect localized paths */ function traverseFields(fields, localizedPaths, parentPath = '', parentIsLocalized = false) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildLocalizedPaths.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\n/**\n * Extracts all localized field paths from a collection's field configuration.\n * Recursively traverses nested structures (groups, arrays, blocks, tabs) to find fields marked as localized.\n *\n * @param payload - The Payload instance containing collection configurations\n * @param collectionSlug - The slug of the collection to extract localized paths from\n * @returns Array of dot-notation paths to localized fields (e.g., ['title', 'metadata.description'])\n */\nexport function buildLocalizedPaths(payload: Payload, collectionSlug: string): string[] {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n return []\n }\n\n const localizedPaths: string[] = []\n traverseFields(collectionConfig.fields, localizedPaths)\n return localizedPaths\n}\n\n/** Recursively traverses fields to find and collect localized paths */\nfunction traverseFields(\n fields: Field[],\n localizedPaths: string[],\n parentPath = '',\n parentIsLocalized = false,\n): void {\n for (const field of fields) {\n // Only field types that have names can support localization\n // See: https://payloadcms.com/docs/configuration/localization\n //\n // This will skip presentational fields like ui, collapsible, row, tabs (if unnamed), groups (if unnamed)\n // which do not store data in the database and thus are not relevant for querying localized paths\n // See: https://payloadcms.com/docs/fields/overview#presentational-fields\n if (!('name' in field)) {\n continue\n }\n\n const fieldPath = buildPath(parentPath, field.name)\n const isLocalized = 'localized' in field && field.localized === true\n const includeNestedPaths = isLocalized || parentIsLocalized\n\n // Add field to results if localized or parent is localized\n if (includeNestedPaths) {\n localizedPaths.push(fieldPath)\n }\n\n // Handle blocks field - has a special 'blocks' array structure and each block has its own nested fields\n if (field.type === 'blocks' && 'blocks' in field) {\n for (const block of field.blocks) {\n if ('fields' in block) {\n traverseFields(block.fields, localizedPaths, fieldPath, includeNestedPaths)\n }\n }\n continue\n }\n\n // Handle field type that support nested fields\n // Recursively handle nested structures (groups, arrays, tab, etc)\n if ('fields' in field) {\n traverseFields(field.fields, localizedPaths, fieldPath, includeNestedPaths)\n }\n }\n}\n\n/** Builds a dot-notation path from parent path and field name */\nfunction buildPath(parentPath: string, fieldName: string): string {\n return parentPath ? `${parentPath}.${fieldName}` : fieldName\n}\n"],"names":["buildLocalizedPaths","payload","collectionSlug","collectionConfig","config","collections","find","c","slug","localizedPaths","traverseFields","fields","parentPath","parentIsLocalized","field","fieldPath","buildPath","name","isLocalized","localized","includeNestedPaths","
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildLocalizedPaths.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\n/**\n * Extracts all localized field paths from a collection's field configuration.\n * Recursively traverses nested structures (groups, arrays, blocks, tabs) to find fields marked as localized.\n *\n * @param payload - The Payload instance containing collection configurations\n * @param collectionSlug - The slug of the collection to extract localized paths from\n * @returns Array of dot-notation paths to localized fields (e.g., ['title', 'metadata.description'])\n */\nexport function buildLocalizedPaths(payload: Payload, collectionSlug: string): string[] {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n return []\n }\n\n const localizedPaths: string[] = []\n traverseFields(collectionConfig.fields, localizedPaths)\n\n // Add _status to localized paths if localizeStatus is enabled for this collection\n // _status is a base field added by Payload when versions.drafts is enabled,\n // and it becomes localized when versions.drafts.localizeStatus is true\n // localizeStatus requires both experimental flag AND collection-level config\n const experimentalLocalizeStatus =\n 'experimental' in payload.config &&\n payload.config.experimental &&\n typeof payload.config.experimental === 'object' &&\n 'localizeStatus' in payload.config.experimental &&\n payload.config.experimental.localizeStatus === true\n\n const drafts =\n collectionConfig.versions && typeof collectionConfig.versions === 'object'\n ? collectionConfig.versions.drafts\n : false\n const collectionLocalizeStatus =\n drafts &&\n typeof drafts === 'object' &&\n 'localizeStatus' in drafts &&\n drafts.localizeStatus === true\n\n const hasLocalizeStatus =\n payload.config.localization && experimentalLocalizeStatus && collectionLocalizeStatus\n\n if (hasLocalizeStatus && !localizedPaths.includes('_status')) {\n localizedPaths.push('_status')\n }\n\n return localizedPaths\n}\n\n/** Recursively traverses fields to find and collect localized paths */\nfunction traverseFields(\n fields: Field[],\n localizedPaths: string[],\n parentPath = '',\n parentIsLocalized = false,\n): void {\n for (const field of fields) {\n // Only field types that have names can support localization\n // See: https://payloadcms.com/docs/configuration/localization\n //\n // This will skip presentational fields like ui, collapsible, row, tabs (if unnamed), groups (if unnamed)\n // which do not store data in the database and thus are not relevant for querying localized paths\n // See: https://payloadcms.com/docs/fields/overview#presentational-fields\n if (!('name' in field)) {\n continue\n }\n\n const fieldPath = buildPath(parentPath, field.name)\n const isLocalized = 'localized' in field && field.localized === true\n const includeNestedPaths = isLocalized || parentIsLocalized\n\n // Add field to results if localized or parent is localized\n if (includeNestedPaths) {\n localizedPaths.push(fieldPath)\n }\n\n // Handle blocks field - has a special 'blocks' array structure and each block has its own nested fields\n if (field.type === 'blocks' && 'blocks' in field) {\n for (const block of field.blocks) {\n if ('fields' in block) {\n traverseFields(block.fields, localizedPaths, fieldPath, includeNestedPaths)\n }\n }\n continue\n }\n\n // Handle field type that support nested fields\n // Recursively handle nested structures (groups, arrays, tab, etc)\n if ('fields' in field) {\n traverseFields(field.fields, localizedPaths, fieldPath, includeNestedPaths)\n }\n }\n}\n\n/** Builds a dot-notation path from parent path and field name */\nfunction buildPath(parentPath: string, fieldName: string): string {\n return parentPath ? `${parentPath}.${fieldName}` : fieldName\n}\n"],"names":["buildLocalizedPaths","payload","collectionSlug","collectionConfig","config","collections","find","c","slug","localizedPaths","traverseFields","fields","experimentalLocalizeStatus","experimental","localizeStatus","drafts","versions","collectionLocalizeStatus","hasLocalizeStatus","localization","includes","push","parentPath","parentIsLocalized","field","fieldPath","buildPath","name","isLocalized","localized","includeNestedPaths","type","block","blocks","fieldName"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,SAASA,oBAAoBC,OAAgB,EAAEC,cAAsB;IAC1E,MAAMC,mBAAmBF,QAAQG,MAAM,CAACC,WAAW,CAACC,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKN;IAC3E,IAAI,CAACC,kBAAkB;QACrB,OAAO,EAAE;IACX;IAEA,MAAMM,iBAA2B,EAAE;IACnCC,eAAeP,iBAAiBQ,MAAM,EAAEF;IAExC,kFAAkF;IAClF,4EAA4E;IAC5E,uEAAuE;IACvE,6EAA6E;IAC7E,MAAMG,6BACJ,kBAAkBX,QAAQG,MAAM,IAChCH,QAAQG,MAAM,CAACS,YAAY,IAC3B,OAAOZ,QAAQG,MAAM,CAACS,YAAY,KAAK,YACvC,oBAAoBZ,QAAQG,MAAM,CAACS,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F;AACF;AAEA,+DAA+D,GAC/D,SAASJ,UAAUJ,UAAkB,EAAEY,SAAiB;IACtD,OAAOZ,aAAa,GAAGA,WAAW,CAAC,EAAEY,WAAW,GAAGA;AACrD"}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import type { Payload, Where } from 'payload';
|
|
2
|
+
import type { components } from '../../generated/content-api-types.js';
|
|
3
|
+
import type { PathTypesRecord } from '../../temp-utilities/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Metadata sent to Content API for query processing.
|
|
6
|
+
*
|
|
7
|
+
* TODO: This interface is defined here temporarily so Content API can test the integration.
|
|
8
|
+
* Once Content API implements support for pathTypes with relationship info, this type
|
|
9
|
+
* should be generated from openapi.json and ContentAPIMeta can be removed.
|
|
10
|
+
*/
|
|
2
11
|
export interface ContentAPIMeta {
|
|
3
12
|
localizedPaths?: string[];
|
|
4
|
-
pathTypes?:
|
|
13
|
+
pathTypes?: PathTypesRecord;
|
|
5
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The type that Content API currently expects (from generated types).
|
|
17
|
+
* This is more restrictive than ContentAPIMeta until Content API is updated.
|
|
18
|
+
*/
|
|
19
|
+
type ContentAPIMetaGenerated = components['schemas']['RequestMeta'];
|
|
6
20
|
export interface BuildMetaOptions {
|
|
7
21
|
collection: string;
|
|
8
22
|
locale: string | undefined;
|
|
@@ -17,6 +31,7 @@ export interface BuildMetaOptions {
|
|
|
17
31
|
* @returns Object with meta property ready to spread into request body, or empty object if no meta needed
|
|
18
32
|
*/
|
|
19
33
|
export declare function buildMeta(payload: Payload, options: BuildMetaOptions): {
|
|
20
|
-
meta?:
|
|
34
|
+
meta?: ContentAPIMetaGenerated;
|
|
21
35
|
};
|
|
36
|
+
export {};
|
|
22
37
|
//# sourceMappingURL=buildMeta.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildMeta.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"buildMeta.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAKpE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,SAAS,CAAC,EAAE,eAAe,CAAA;CAC5B;AAED;;;GAGG;AACH,KAAK,uBAAuB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAA;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,gBAAgB,GACxB;IAAE,IAAI,CAAC,EAAE,uBAAuB,CAAA;CAAE,CAuBpC"}
|
|
@@ -22,8 +22,11 @@ import { buildPathTypes } from './buildPathTypes.js';
|
|
|
22
22
|
meta.localizedPaths = localizedPaths;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
// Cast to generated type - Content API will need to be updated to handle
|
|
26
|
+
// the new pathTypes format with relationship info. Until then, it will
|
|
27
|
+
// ignore the extra fields but still receive the data for testing.
|
|
25
28
|
return Object.keys(meta).length > 0 ? {
|
|
26
|
-
meta
|
|
29
|
+
meta: meta
|
|
27
30
|
} : {};
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildMeta.ts"],"sourcesContent":["import type { Payload, Where } from 'payload'\n\nimport { buildLocalizedPaths } from './buildLocalizedPaths.js'\nimport { buildPathTypes } from './buildPathTypes.js'\n\nexport interface ContentAPIMeta {\n localizedPaths?: string[]\n pathTypes?:
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildMeta.ts"],"sourcesContent":["import type { Payload, Where } from 'payload'\n\nimport type { components } from '../../generated/content-api-types.js'\nimport type { PathTypesRecord } from '../../temp-utilities/types.js'\n\nimport { buildLocalizedPaths } from './buildLocalizedPaths.js'\nimport { buildPathTypes } from './buildPathTypes.js'\n\n/**\n * Metadata sent to Content API for query processing.\n *\n * TODO: This interface is defined here temporarily so Content API can test the integration.\n * Once Content API implements support for pathTypes with relationship info, this type\n * should be generated from openapi.json and ContentAPIMeta can be removed.\n */\nexport interface ContentAPIMeta {\n localizedPaths?: string[]\n pathTypes?: PathTypesRecord\n}\n\n/**\n * The type that Content API currently expects (from generated types).\n * This is more restrictive than ContentAPIMeta until Content API is updated.\n */\ntype ContentAPIMetaGenerated = components['schemas']['RequestMeta']\n\nexport interface BuildMetaOptions {\n collection: string\n locale: string | undefined\n where?: Where\n}\n\n/**\n * Builds the `meta` object for Content API requests.\n * Combines pathTypes (for array field handling) and localizedPaths (for locale queries).\n *\n * @param payload - The Payload instance\n * @param options - Options including collection slug, locale, and where clause\n * @returns Object with meta property ready to spread into request body, or empty object if no meta needed\n */\nexport function buildMeta(\n payload: Payload,\n options: BuildMetaOptions,\n): { meta?: ContentAPIMetaGenerated } {\n const { collection, locale, where } = options\n\n const meta: ContentAPIMeta = {}\n\n // Add pathTypes if there are array fields in the where clause\n const pathTypes = buildPathTypes(payload, collection, where)\n if (Object.keys(pathTypes).length > 0) {\n meta.pathTypes = pathTypes\n }\n\n // Add localizedPaths if locale is specified (but not 'all')\n if (locale && locale !== 'all') {\n const localizedPaths = buildLocalizedPaths(payload, collection)\n if (localizedPaths.length > 0) {\n meta.localizedPaths = localizedPaths\n }\n }\n\n // Cast to generated type - Content API will need to be updated to handle\n // the new pathTypes format with relationship info. Until then, it will\n // ignore the extra fields but still receive the data for testing.\n return Object.keys(meta).length > 0 ? { meta: meta as unknown as ContentAPIMetaGenerated } : {}\n}\n"],"names":["buildLocalizedPaths","buildPathTypes","buildMeta","payload","options","collection","locale","where","meta","pathTypes","Object","keys","length","localizedPaths"],"mappings":"AAKA,SAASA,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,cAAc,QAAQ,sBAAqB;AA0BpD;;;;;;;CAOC,GACD,OAAO,SAASC,UACdC,OAAgB,EAChBC,OAAyB;IAEzB,MAAM,EAAEC,UAAU,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGH;IAEtC,MAAMI,OAAuB,CAAC;IAE9B,8DAA8D;IAC9D,MAAMC,YAAYR,eAAeE,SAASE,YAAYE;IACtD,IAAIG,OAAOC,IAAI,CAACF,WAAWG,MAAM,GAAG,GAAG;QACrCJ,KAAKC,SAAS,GAAGA;IACnB;IAEA,4DAA4D;IAC5D,IAAIH,UAAUA,WAAW,OAAO;QAC9B,MAAMO,iBAAiBb,oBAAoBG,SAASE;QACpD,IAAIQ,eAAeD,MAAM,GAAG,GAAG;YAC7BJ,KAAKK,cAAc,GAAGA;QACxB;IACF;IAEA,yEAAyE;IACzE,uEAAuE;IACvE,kEAAkE;IAClE,OAAOH,OAAOC,IAAI,CAACH,MAAMI,MAAM,GAAG,IAAI;QAAEJ,MAAMA;IAA2C,IAAI,CAAC;AAChG"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Payload, Where } from 'payload';
|
|
2
|
+
import type { PathTypesRecord } from '../../temp-utilities/types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Builds pathTypes metadata for Content API request.
|
|
4
|
-
* Returns a record of paths
|
|
5
|
+
* Returns a record of paths with their types for proper query generation.
|
|
6
|
+
*
|
|
7
|
+
* Includes:
|
|
8
|
+
* - Array fields (type: "array")
|
|
9
|
+
* - Relationship fields (type: { type: "relationship", collection, hasMany })
|
|
10
|
+
* - Join fields (type: { type: "join", collection, hasMany, on })
|
|
5
11
|
*/
|
|
6
|
-
export declare function buildPathTypes(payload: Payload, collectionSlug: string, where: undefined | Where):
|
|
12
|
+
export declare function buildPathTypes(payload: Payload, collectionSlug: string, where: undefined | Where): PathTypesRecord;
|
|
7
13
|
//# sourceMappingURL=buildPathTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPathTypes.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildPathTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"buildPathTypes.d.ts","sourceRoot":"","sources":["../../../../src/db-content-api/utilities/meta/buildPathTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,+BAA+B,CAAA;AAuKnF;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,SAAS,GAAG,KAAK,GACvB,eAAe,CAgCjB"}
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
return paths;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Determines the type of a field based on its configuration
|
|
38
|
+
* Determines the type of a field based on its configuration.
|
|
39
|
+
* Returns PathTypeValue for fields that need special handling in Content API queries.
|
|
39
40
|
*/ function getFieldType(field) {
|
|
40
41
|
// Array field
|
|
41
42
|
if (field.type === 'array') {
|
|
@@ -45,18 +46,38 @@
|
|
|
45
46
|
if (field.type === 'blocks') {
|
|
46
47
|
return 'array';
|
|
47
48
|
}
|
|
48
|
-
// Relationship field
|
|
49
|
-
if (field.type === 'relationship'
|
|
50
|
-
|
|
49
|
+
// Relationship field - always include for JOIN support
|
|
50
|
+
if (field.type === 'relationship') {
|
|
51
|
+
const { hasMany = false, relationTo: collection } = field;
|
|
52
|
+
return {
|
|
53
|
+
type: 'relationship',
|
|
54
|
+
collection,
|
|
55
|
+
hasMany
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Upload field - treated like relationship
|
|
59
|
+
if (field.type === 'upload') {
|
|
60
|
+
const { hasMany = false, relationTo: collection } = field;
|
|
61
|
+
return {
|
|
62
|
+
type: 'relationship',
|
|
63
|
+
collection,
|
|
64
|
+
hasMany
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Join field - virtual reverse lookup
|
|
68
|
+
if (field.type === 'join') {
|
|
69
|
+
const { collection, on } = field;
|
|
70
|
+
return {
|
|
71
|
+
type: 'join',
|
|
72
|
+
collection,
|
|
73
|
+
hasMany: true,
|
|
74
|
+
on
|
|
75
|
+
};
|
|
51
76
|
}
|
|
52
77
|
// Select field with hasMany (array)
|
|
53
78
|
if (field.type === 'select' && 'hasMany' in field && field.hasMany) {
|
|
54
79
|
return 'array';
|
|
55
80
|
}
|
|
56
|
-
// Upload field with hasMany (array)
|
|
57
|
-
if (field.type === 'upload' && 'hasMany' in field && field.hasMany) {
|
|
58
|
-
return 'array';
|
|
59
|
-
}
|
|
60
81
|
// Objects (group, collapsible, row, tabs) don't need traversal
|
|
61
82
|
return null;
|
|
62
83
|
}
|
|
@@ -124,7 +145,12 @@
|
|
|
124
145
|
}
|
|
125
146
|
/**
|
|
126
147
|
* Builds pathTypes metadata for Content API request.
|
|
127
|
-
* Returns a record of paths
|
|
148
|
+
* Returns a record of paths with their types for proper query generation.
|
|
149
|
+
*
|
|
150
|
+
* Includes:
|
|
151
|
+
* - Array fields (type: "array")
|
|
152
|
+
* - Relationship fields (type: { type: "relationship", collection, hasMany })
|
|
153
|
+
* - Join fields (type: { type: "join", collection, hasMany, on })
|
|
128
154
|
*/ export function buildPathTypes(payload, collectionSlug, where) {
|
|
129
155
|
if (!where) {
|
|
130
156
|
return {};
|
|
@@ -132,14 +158,18 @@
|
|
|
132
158
|
const pathTypes = {};
|
|
133
159
|
const paths = extractPathsFromWhere(where);
|
|
134
160
|
for (const path of paths){
|
|
135
|
-
// For each path, we need to check all segments to see if any intermediate ones are arrays/
|
|
161
|
+
// For each path, we need to check all segments to see if any intermediate ones are arrays/relationships
|
|
136
162
|
const segments = path.split('.');
|
|
137
163
|
for(let i = 0; i < segments.length; i++){
|
|
138
164
|
const partialPath = segments.slice(0, i + 1).join('.');
|
|
165
|
+
// Skip if we already have this path
|
|
166
|
+
if (partialPath in pathTypes) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
139
169
|
const field = findFieldByPath(payload, collectionSlug, partialPath);
|
|
140
170
|
if (field) {
|
|
141
171
|
const fieldType = getFieldType(field);
|
|
142
|
-
if (fieldType
|
|
172
|
+
if (fieldType !== null) {
|
|
143
173
|
pathTypes[partialPath] = fieldType;
|
|
144
174
|
}
|
|
145
175
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildPathTypes.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\n/**\n * Extracts all field paths from a where clause recursively\n */\nfunction extractPathsFromWhere(where: Where, paths: Set<string> = new Set()): Set<string> {\n if (!where || typeof where !== 'object') {\n return paths\n }\n\n // Handle 'and' operator\n if ('and' in where && Array.isArray(where.and)) {\n for (const clause of where.and) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle 'or' operator\n if ('or' in where && Array.isArray(where.or)) {\n for (const clause of where.or) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle regular conditions - keys are field paths\n for (const key in where) {\n if (key === 'and' || key === 'or') {\n continue\n }\n\n // Add the path\n paths.add(key)\n\n // Check if the value is a nested where clause (for relationships)\n const value = where[key]\n if (value && typeof value === 'object' && !('equals' in value) && !('in' in value)) {\n // Might be a nested where, recurse\n extractPathsFromWhere(value as Where, paths)\n }\n }\n\n return paths\n}\n\n/**\n * Determines the type of a field based on its configuration\n */\nfunction getFieldType(field: Field): 'array' | null {\n // Array field\n if (field.type === 'array') {\n return 'array'\n }\n\n // Blocks field (array of objects)\n if (field.type === 'blocks') {\n return 'array'\n }\n\n // Relationship field with hasMany (array)\n if (field.type === 'relationship' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Select field with hasMany (array)\n if (field.type === 'select' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Upload field with hasMany (array)\n if (field.type === 'upload' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Objects (group, collapsible, row, tabs) don't need traversal\n return null\n}\n\n/**\n * Finds a field in the collection schema by its path\n * Supports nested paths like \"access.read.users\"\n */\nfunction findFieldByPath(\n payload: Payload,\n collectionSlug: string,\n path: string,\n): Field | undefined {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n return undefined\n }\n\n const pathSegments = path.split('.')\n\n // Walk through the path segments to find the field\n let currentFields = collectionConfig.fields\n let currentField: Field | undefined = undefined\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]\n\n // First try to find a direct match\n currentField = currentFields.find((f) => 'name' in f && f.name === segment)\n\n // If not found, check if any unnamed container fields (collapsible, row) contain it\n if (!currentField) {\n for (const field of currentFields) {\n if (!('name' in field) || !field.name) {\n // This is an unnamed field, check its contents\n if (\n ('fields' in field && field.type === 'collapsible') ||\n ('fields' in field && field.type === 'row')\n ) {\n currentField = field.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n } else if ('tabs' in field && field.type === 'tabs') {\n // Check all tabs\n for (const tab of field.tabs) {\n currentField = tab.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n }\n if (currentField) {\n break\n }\n }\n }\n }\n }\n\n if (!currentField) {\n return undefined\n }\n\n // If we're not at the end, get nested fields\n if (i < pathSegments.length - 1) {\n if (currentField.type === 'group' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'array' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'blocks' && 'blocks' in currentField) {\n // For blocks, we can't determine the exact field without knowing the block type\n // Return the blocks field itself\n return currentField\n } else {\n // Field doesn't have nested fields, can't continue\n return undefined\n }\n }\n }\n\n return currentField\n}\n\n/**\n * Builds pathTypes metadata for Content API request.\n * Returns a record of paths that are arrays for proper query generation.\n */\nexport function buildPathTypes(\n payload: Payload,\n collectionSlug: string,\n where: undefined | Where,\n): Record<string, 'array'> {\n if (!where) {\n return {}\n }\n\n const pathTypes: Record<string, 'array'> = {}\n const paths = extractPathsFromWhere(where)\n\n for (const path of paths) {\n // For each path, we need to check all segments to see if any intermediate ones are arrays/objects\n const segments = path.split('.')\n\n for (let i = 0; i < segments.length; i++) {\n const partialPath = segments.slice(0, i + 1).join('.')\n const field = findFieldByPath(payload, collectionSlug, partialPath)\n\n if (field) {\n const fieldType = getFieldType(field)\n if (fieldType === 'array') {\n pathTypes[partialPath] = fieldType\n }\n }\n }\n }\n\n return pathTypes\n}\n"],"names":["extractPathsFromWhere","where","paths","Set","Array","isArray","and","clause","or","key","add","value","getFieldType","field","type","hasMany","findFieldByPath","payload","collectionSlug","path","collectionConfig","config","collections","find","c","slug","undefined","pathSegments","split","currentFields","fields","currentField","i","length","segment","f","name","tab","tabs","buildPathTypes","pathTypes","segments","partialPath","slice","join","fieldType"],"mappings":"AAEA;;CAEC,GACD,SAASA,sBAAsBC,KAAY,EAAEC,QAAqB,IAAIC,KAAK;IACzE,IAAI,CAACF,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,wBAAwB;IACxB,IAAI,SAASD,SAASG,MAAMC,OAAO,CAACJ,MAAMK,GAAG,GAAG;QAC9C,KAAK,MA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YAC/B,IAAIF,aAAajB,IAAI,KAAK,WAAW,YAAYiB,cAAc;gBAC7DF,gBAAgBE,aAAaD,MAAM;YACrC,OAAO,IAAIC,aAAajB,IAAI,KAAK,WAAW,YAAYiB,cAAc;gBACpEF,gBAAgBE,aAAaD,MAAM;YACrC,OAAO,IAAIC,aAAajB,IAAI,KAAK,YAAY,YAAYiB,cAAc;gBACrE,gFAAgF;gBAChF,iCAAiC;gBACjC,OAAOA;YACT,OAAO;gBACL,mDAAmD;gBACnD,OAAOL;YACT;QACF;IACF;IAEA,OAAOK;AACT;AAEA;;;CAGC,GACD,OAAO,SAASQ,eACdtB,OAAgB,EAChBC,cAAsB,EACtBjB,KAAwB;IAExB,IAAI,CAACA,OAAO;QACV,OAAO,CAAC;IACV;IAEA,MAAMuC,YAAqC,CAAC;IAC5C,MAAMtC,QAAQF,sBAAsBC;IAEpC,KAAK,MAAMkB,QAAQjB,MAAO;QACxB,kGAAkG;QAClG,MAAMuC,WAAWtB,KAAKS,KAAK,CAAC;QAE5B,IAAK,IAAII,IAAI,GAAGA,IAAIS,SAASR,MAAM,EAAED,IAAK;YACxC,MAAMU,cAAcD,SAASE,KAAK,CAAC,GAAGX,IAAI,GAAGY,IAAI,CAAC;YAClD,MAAM/B,QAAQG,gBAAgBC,SAASC,gBAAgBwB;YAEvD,IAAI7B,OAAO;gBACT,MAAMgC,YAAYjC,aAAaC;gBAC/B,IAAIgC,cAAc,SAAS;oBACzBL,SAAS,CAACE,YAAY,GAAGG;gBAC3B;YACF;QACF;IACF;IAEA,OAAOL;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/db-content-api/utilities/meta/buildPathTypes.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport type { PathTypesRecord, PathTypeValue } from '../../temp-utilities/types.js'\n\n/**\n * Extracts all field paths from a where clause recursively\n */\nfunction extractPathsFromWhere(where: Where, paths: Set<string> = new Set()): Set<string> {\n if (!where || typeof where !== 'object') {\n return paths\n }\n\n // Handle 'and' operator\n if ('and' in where && Array.isArray(where.and)) {\n for (const clause of where.and) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle 'or' operator\n if ('or' in where && Array.isArray(where.or)) {\n for (const clause of where.or) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle regular conditions - keys are field paths\n for (const key in where) {\n if (key === 'and' || key === 'or') {\n continue\n }\n\n // Add the path\n paths.add(key)\n\n // Check if the value is a nested where clause (for relationships)\n const value = where[key]\n if (value && typeof value === 'object' && !('equals' in value) && !('in' in value)) {\n // Might be a nested where, recurse\n extractPathsFromWhere(value as Where, paths)\n }\n }\n\n return paths\n}\n\n/**\n * Determines the type of a field based on its configuration.\n * Returns PathTypeValue for fields that need special handling in Content API queries.\n */\nfunction getFieldType(field: Field): null | PathTypeValue {\n // Array field\n if (field.type === 'array') {\n return 'array'\n }\n\n // Blocks field (array of objects)\n if (field.type === 'blocks') {\n return 'array'\n }\n\n // Relationship field - always include for JOIN support\n if (field.type === 'relationship') {\n const { hasMany = false, relationTo: collection } = field\n return { type: 'relationship', collection, hasMany }\n }\n\n // Upload field - treated like relationship\n if (field.type === 'upload') {\n const { hasMany = false, relationTo: collection } = field\n return { type: 'relationship', collection, hasMany }\n }\n\n // Join field - virtual reverse lookup\n if (field.type === 'join') {\n const { collection, on } = field\n return { type: 'join', collection, hasMany: true, on }\n }\n\n // Select field with hasMany (array)\n if (field.type === 'select' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Objects (group, collapsible, row, tabs) don't need traversal\n return null\n}\n\n/**\n * Finds a field in the collection schema by its path\n * Supports nested paths like \"access.read.users\"\n */\nfunction findFieldByPath(\n payload: Payload,\n collectionSlug: string,\n path: string,\n): Field | undefined {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n return undefined\n }\n\n const pathSegments = path.split('.')\n\n // Walk through the path segments to find the field\n let currentFields = collectionConfig.fields\n let currentField: Field | undefined = undefined\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]\n\n // First try to find a direct match\n currentField = currentFields.find((f) => 'name' in f && f.name === segment)\n\n // If not found, check if any unnamed container fields (collapsible, row) contain it\n if (!currentField) {\n for (const field of currentFields) {\n if (!('name' in field) || !field.name) {\n // This is an unnamed field, check its contents\n if (\n ('fields' in field && field.type === 'collapsible') ||\n ('fields' in field && field.type === 'row')\n ) {\n currentField = field.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n } else if ('tabs' in field && field.type === 'tabs') {\n // Check all tabs\n for (const tab of field.tabs) {\n currentField = tab.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n }\n if (currentField) {\n break\n }\n }\n }\n }\n }\n\n if (!currentField) {\n return undefined\n }\n\n // If we're not at the end, get nested fields\n if (i < pathSegments.length - 1) {\n if (currentField.type === 'group' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'array' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'blocks' && 'blocks' in currentField) {\n // For blocks, we can't determine the exact field without knowing the block type\n // Return the blocks field itself\n return currentField\n } else {\n // Field doesn't have nested fields, can't continue\n return undefined\n }\n }\n }\n\n return currentField\n}\n\n/**\n * Builds pathTypes metadata for Content API request.\n * Returns a record of paths with their types for proper query generation.\n *\n * Includes:\n * - Array fields (type: \"array\")\n * - Relationship fields (type: { type: \"relationship\", collection, hasMany })\n * - Join fields (type: { type: \"join\", collection, hasMany, on })\n */\nexport function buildPathTypes(\n payload: Payload,\n collectionSlug: string,\n where: undefined | Where,\n): PathTypesRecord {\n if (!where) {\n return {}\n }\n\n const pathTypes: PathTypesRecord = {}\n const paths = extractPathsFromWhere(where)\n\n for (const path of paths) {\n // For each path, we need to check all segments to see if any intermediate ones are arrays/relationships\n const segments = path.split('.')\n\n for (let i = 0; i < segments.length; i++) {\n const partialPath = segments.slice(0, i + 1).join('.')\n\n // Skip if we already have this path\n if (partialPath in pathTypes) {\n continue\n }\n\n const field = findFieldByPath(payload, collectionSlug, partialPath)\n\n if (field) {\n const fieldType = getFieldType(field)\n if (fieldType !== null) {\n pathTypes[partialPath] = fieldType\n }\n }\n }\n }\n\n return pathTypes\n}\n"],"names":["extractPathsFromWhere","where","paths","Set","Array","isArray","and","clause","or","key","add","value","getFieldType","field","type","hasMany","relationTo","collection","on","findFieldByPath","payload","collectionSlug","path","collectionConfig","config","collections","find","c","slug","undefined","pathSegments","split","currentFields","fields","currentField","i","length","segment","f","name","tab","tabs","buildPathTypes","pathTypes","segments","partialPath","slice","join","fieldType"],"mappings":"AAIA;;CAEC,GACD,SAASA,sBAAsBC,KAAY,EAAEC,QAAqB,IAAIC,KAAK;IACzE,IAAI,CAACF,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,wBAAwB;IACxB,IAAI,SAASD,SAASG,MAAMC,OAAO,CAACJ,MAAMK,GAAG,GAAG;QAC9C,KAAK,MAAMC,UAAUN,MAAMK,GAAG,CAAE;YAC9BN,sBAAsBO,QAAQL;QAChC;QACA,OAAOA;IACT;IAEA,uBAAuB;IACvB,IAAI,QAAQD,SAASG,MAAMC,OAAO,CAACJ,MAAMO,EAAE,GAAG;QAC5C,KAAK,MAAMD,UAAUN,MAAMO,EAAE,CAAE;YAC7BR,sBAAsBO,QAAQL;QAChC;QACA,OAAOA;IACT;IAEA,mDAAmD;IACnD,IAAK,MAAMO,OAAOR,MAAO;QACvB,IAAIQ,QAAQ,SAASA,QAAQ,MAAM;YACjC;QACF;QAEA,eAAe;QACfP,MAAMQ,GAAG,CAACD;QAEV,kEAAkE;QAClE,MAAME,QAAQV,KAAK,CAACQ,IAAI;QACxB,IAAIE,SAAS,OAAOA,UAAU,YAAY,CAAE,CAAA,YAAYA,KAAI,KAAM,CAAE,CAAA,QAAQA,KAAI,GAAI;YAClF,mCAAmC;YACnCX,sBAAsBW,OAAgBT;QACxC;IACF;IAEA,OAAOA;AACT;AAEA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DAAmD;gBACnD,OAAOL;YACT;QACF;IACF;IAEA,OAAOK;AACT;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASQ,eACdtB,OAAgB,EAChBC,cAAsB,EACtBpB,KAAwB;IAExB,IAAI,CAACA,OAAO;QACV,OAAO,CAAC;IACV;IAEA,MAAM0C,YAA6B,CAAC;IACpC,MAAMzC,QAAQF,sBAAsBC;IAEpC,KAAK,MAAMqB,QAAQpB,MAAO;QACxB,wGAAwG;QACxG,MAAM0C,WAAWtB,KAAKS,KAAK,CAAC;QAE5B,IAAK,IAAII,IAAI,GAAGA,IAAIS,SAASR,MAAM,EAAED,IAAK;YACxC,MAAMU,cAAcD,SAASE,KAAK,CAAC,GAAGX,IAAI,GAAGY,IAAI,CAAC;YAElD,oCAAoC;YACpC,IAAIF,eAAeF,WAAW;gBAC5B;YACF;YAEA,MAAM9B,QAAQM,gBAAgBC,SAASC,gBAAgBwB;YAEvD,IAAIhC,OAAO;gBACT,MAAMmC,YAAYpC,aAAaC;gBAC/B,IAAImC,cAAc,MAAM;oBACtBL,SAAS,CAACE,YAAY,GAAGG;gBAC3B;YACF;QACF;IACF;IAEA,OAAOL;AACT"}
|
|
@@ -6,6 +6,14 @@ type ConvertOptions = {
|
|
|
6
6
|
insideLogicalOperator?: boolean;
|
|
7
7
|
/** If true, transform 'parent' field to 'documentId' (used for version queries) */
|
|
8
8
|
parentToDocumentId?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* If true, strip 'version.' prefix from field paths (used for version queries).
|
|
11
|
+
*
|
|
12
|
+
* Payload queries version content with paths like 'version._status.en', but Content API
|
|
13
|
+
* stores version data directly in the 'data' column (not nested under 'version').
|
|
14
|
+
* The 'version' wrapper is only added in API responses for client compatibility.
|
|
15
|
+
*/
|
|
16
|
+
stripVersionPrefix?: boolean;
|
|
9
17
|
};
|
|
10
18
|
export declare function convertPayloadWhereToContentAPI(where: undefined | Where, options?: ConvertOptions): WhereClause;
|
|
11
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"where.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/utilities/where.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,KAAK,WAAW,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAA;AASvD,KAAK,cAAc,GAAG;IACpB,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,mFAAmF;IACnF,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,SAAS,GAAG,KAAK,EACxB,OAAO,GAAE,cAAmB,GAC3B,WAAW,
|
|
1
|
+
{"version":3,"file":"where.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/utilities/where.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,KAAK,WAAW,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAA;AASvD,KAAK,cAAc,GAAG;IACpB,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,mFAAmF;IACnF,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,SAAS,GAAG,KAAK,EACxB,OAAO,GAAE,cAAmB,GAC3B,WAAW,CAoIb"}
|
|
@@ -68,6 +68,12 @@ export function convertPayloadWhereToContentAPI(where, options = {}) {
|
|
|
68
68
|
if (options.parentToDocumentId && key === 'parent') {
|
|
69
69
|
fieldPath = 'documentId';
|
|
70
70
|
}
|
|
71
|
+
// Strip 'version.' prefix from field paths for version queries
|
|
72
|
+
// Payload uses paths like 'version._status.en' but Content API stores version data
|
|
73
|
+
// directly in the 'data' column, not nested under 'version'
|
|
74
|
+
if (options.stripVersionPrefix && fieldPath.startsWith('version.')) {
|
|
75
|
+
fieldPath = fieldPath.slice('version.'.length);
|
|
76
|
+
}
|
|
71
77
|
// Convert field conditions: { fieldName: { operator: value } }
|
|
72
78
|
// to: { path: fieldName, operator, value }
|
|
73
79
|
// Handle Payload's shorthand: { fieldName: value } → { fieldName: { equals: value } }
|