@payloadcms/figma 0.1.0-alpha.0 → 0.1.0-alpha.10
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/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +1 -9
- package/dist/api/control-plane.js +2 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +69 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +13 -8
- package/dist/auth/token-store.d.ts +4 -1
- package/dist/auth/token-store.js +14 -0
- package/dist/auth/types.d.ts +12 -0
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +2 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +164 -79
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +661 -16
- package/dist/db-content-api/index.d.ts +3 -0
- package/dist/db-content-api/index.js +155 -161
- package/dist/db-content-api/utilities/clientVersionHeaders.d.ts +7 -0
- package/dist/db-content-api/utilities/clientVersionHeaders.js +15 -0
- package/dist/db-content-api/utilities/data/atomicOperations.d.ts +16 -0
- package/dist/db-content-api/utilities/data/atomicOperations.js +48 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.d.ts +25 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.js +109 -0
- package/dist/db-content-api/utilities/data/index.js +73 -57
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.d.ts +10 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.js +13 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.d.ts +18 -0
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.js +21 -0
- package/dist/db-content-api/utilities/data/validateRelationships.js +19 -12
- package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.d.ts +6 -8
- package/dist/db-content-api/utilities/joins.js +13 -22
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +21 -4
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +118 -36
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +3 -17
- package/dist/db-content-api/utilities/where.js +21 -21
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +4 -2
- package/dist/plugin/build-config.js +95 -31
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +8 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +32 -0
- package/dist/plugin/sandbox-upload-fetch.js +53 -0
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/client-uploads/generate.js +2 -1
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +27 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/staticHandler.js +2 -1
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/load-payload-config.d.ts +2 -2
- package/dist/utils/messages.js +24 -3
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +31 -7
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +0 -10
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +0 -71
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +0 -41
- package/dist/db-content-api/utilities/meta/buildMeta.js +0 -39
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +0 -16
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +0 -243
- package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +0 -12
- package/dist/db-content-api/utilities/meta/buildUniquePaths.js +0 -60
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER = "X-Figma-Payload-Plugin-Version";
|
|
2
|
+
type ClientVersionHeadersArgs = {
|
|
3
|
+
payloadPluginVersion: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function getClientVersionHeaders(): Record<string, string>;
|
|
6
|
+
export declare function buildClientVersionHeaders({ payloadPluginVersion, }: ClientVersionHeadersArgs): Record<string, string>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import packageJson from '../../../package.json' with {
|
|
2
|
+
type: 'json'
|
|
3
|
+
};
|
|
4
|
+
// KEEP_IN_SYNC(payload/content-api/src/server/clientVersionTelemetry.ts)
|
|
5
|
+
export const FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER = 'X-Figma-Payload-Plugin-Version';
|
|
6
|
+
export function getClientVersionHeaders() {
|
|
7
|
+
return buildClientVersionHeaders({
|
|
8
|
+
payloadPluginVersion: packageJson.version
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export function buildClientVersionHeaders({ payloadPluginVersion }) {
|
|
12
|
+
return {
|
|
13
|
+
[FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER]: payloadPluginVersion
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type AtomicOperator = '$inc' | '$push' | '$remove';
|
|
2
|
+
export declare const ATOMIC_OPERATORS: readonly AtomicOperator[];
|
|
3
|
+
/** Relationship/upload values are lists, so they only ever carry list operators. */
|
|
4
|
+
export declare const RELATIONSHIP_ATOMIC_OPERATORS: readonly ('$push' | '$remove')[];
|
|
5
|
+
/**
|
|
6
|
+
* Recognizes an atomic-operation wrapper, returning its operator and the wrapped
|
|
7
|
+
* value, or `null` when the value is not such a wrapper.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchAtomicOperation<T extends AtomicOperator>(value: unknown, operators: readonly T[]): {
|
|
10
|
+
inner: unknown;
|
|
11
|
+
operator: T;
|
|
12
|
+
} | null;
|
|
13
|
+
/** Whether the value is an atomic-operation wrapper rather than a plain value. */
|
|
14
|
+
export declare function isAtomicOperation(value: unknown, operators: readonly AtomicOperator[]): boolean;
|
|
15
|
+
/** Returns the wrapped value of an atomic operation, or the value itself. */
|
|
16
|
+
export declare function unwrapAtomicOperation(value: unknown, operators: readonly AtomicOperator[]): unknown;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Payload expresses an atomic field update as a single-key wrapper around the
|
|
2
|
+
// value — e.g. `{ $push: ['id'] }` on a has-many relationship, `{ $inc: 1 }` on a
|
|
3
|
+
// number field. Which operators are legal depends on the field type, so callers
|
|
4
|
+
// pass the set they accept; the default is every operator the adapter knows about.
|
|
5
|
+
export const ATOMIC_OPERATORS = [
|
|
6
|
+
'$inc',
|
|
7
|
+
'$push',
|
|
8
|
+
'$remove'
|
|
9
|
+
];
|
|
10
|
+
/** Relationship/upload values are lists, so they only ever carry list operators. */ export const RELATIONSHIP_ATOMIC_OPERATORS = [
|
|
11
|
+
'$push',
|
|
12
|
+
'$remove'
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Recognizes an atomic-operation wrapper, returning its operator and the wrapped
|
|
16
|
+
* value, or `null` when the value is not such a wrapper.
|
|
17
|
+
*/ export function matchAtomicOperation(value, operators) {
|
|
18
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const keys = Object.keys(value);
|
|
22
|
+
if (keys.length !== 1) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const key = keys[0];
|
|
26
|
+
if (!isOneOf(key, operators)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
inner: value[key],
|
|
31
|
+
operator: key
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Whether the value is an atomic-operation wrapper rather than a plain value. */ export function isAtomicOperation(value, operators) {
|
|
35
|
+
return matchAtomicOperation(value, operators) !== null;
|
|
36
|
+
}
|
|
37
|
+
/** Returns the wrapped value of an atomic operation, or the value itself. */ export function unwrapAtomicOperation(value, operators) {
|
|
38
|
+
const match = matchAtomicOperation(value, operators);
|
|
39
|
+
return match ? match.inner : value;
|
|
40
|
+
}
|
|
41
|
+
function isOneOf(value, options) {
|
|
42
|
+
for (const option of options){
|
|
43
|
+
if (option === value) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Payload, RelationshipField, UploadField } from 'payload';
|
|
2
|
+
type Direction = 'fromWire' | 'toWire';
|
|
3
|
+
export declare function convertRelationshipFieldIdsFromWire(options: {
|
|
4
|
+
field: RelationshipField | UploadField;
|
|
5
|
+
payload: Payload;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}): unknown;
|
|
8
|
+
export declare function convertRelationshipFieldIdsToWire(options: {
|
|
9
|
+
field: RelationshipField | UploadField;
|
|
10
|
+
payload: Payload;
|
|
11
|
+
value: unknown;
|
|
12
|
+
}): unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Converts the id(s) inside a relationship/upload field value between Payload's
|
|
15
|
+
* representation (numeric ids kept as numbers) and the Content API wire form
|
|
16
|
+
* (all ids as strings). No-op for uuid/text targets. Preserves has-many arrays,
|
|
17
|
+
* polymorphic shapes, localized locale-maps, and atomic operators.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertRelationshipFieldIds(options: {
|
|
20
|
+
direction: Direction;
|
|
21
|
+
field: RelationshipField | UploadField;
|
|
22
|
+
payload: Payload;
|
|
23
|
+
value: unknown;
|
|
24
|
+
}): unknown;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { valueIsValueWithRelation } from 'payload/shared';
|
|
2
|
+
import { matchAtomicOperation, RELATIONSHIP_ATOMIC_OPERATORS } from './atomicOperations.js';
|
|
3
|
+
import { isLocaleMap } from './isLocaleMap.js';
|
|
4
|
+
export function convertRelationshipFieldIdsFromWire(options) {
|
|
5
|
+
return convertRelationshipFieldIds({
|
|
6
|
+
...options,
|
|
7
|
+
direction: 'fromWire'
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function convertRelationshipFieldIdsToWire(options) {
|
|
11
|
+
return convertRelationshipFieldIds({
|
|
12
|
+
...options,
|
|
13
|
+
direction: 'toWire'
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts the id(s) inside a relationship/upload field value between Payload's
|
|
18
|
+
* representation (numeric ids kept as numbers) and the Content API wire form
|
|
19
|
+
* (all ids as strings). No-op for uuid/text targets. Preserves has-many arrays,
|
|
20
|
+
* polymorphic shapes, localized locale-maps, and atomic operators.
|
|
21
|
+
*/ export function convertRelationshipFieldIds(options) {
|
|
22
|
+
const { direction, field, payload, value } = options;
|
|
23
|
+
if (value == null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const relationTo = field.relationTo;
|
|
27
|
+
const localized = field.localized ?? false;
|
|
28
|
+
const hasMany = field.hasMany ?? false;
|
|
29
|
+
// The value shape is fully determined by the localized × hasMany combination:
|
|
30
|
+
// !localized, !hasMany → a single value
|
|
31
|
+
// !localized, hasMany → an array of values (or a `$push`/`$remove` wrapper)
|
|
32
|
+
// localized, !hasMany → a locale-map of single values
|
|
33
|
+
// localized, hasMany → a locale-map of arrays
|
|
34
|
+
// Localized values arrive as a locale-map on write and all-locales reads, but
|
|
35
|
+
// as the bare per-locale value on single-locale reads, so a localized field
|
|
36
|
+
// dispatches through `convertLocalized`, which handles both.
|
|
37
|
+
const convertValue = (entry)=>hasMany ? convertHasManyValue(entry, relationTo, payload, direction) : convertSingleValue(entry, relationTo, payload, direction);
|
|
38
|
+
return localized ? convertLocalized(value, convertValue) : convertValue(value);
|
|
39
|
+
}
|
|
40
|
+
// Applies `convertValue` to each entry of a localized locale-map. A single-locale
|
|
41
|
+
// read delivers the bare per-locale value instead of a map (a plain object then
|
|
42
|
+
// is a polymorphic ref, not a locale-map), so that case is converted directly.
|
|
43
|
+
function convertLocalized(value, convertValue) {
|
|
44
|
+
if (!isLocaleMap(value)) {
|
|
45
|
+
return convertValue(value);
|
|
46
|
+
}
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const [locale, localeValue] of Object.entries(value)){
|
|
49
|
+
out[locale] = localeValue == null ? localeValue : convertValue(localeValue);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
// A has-many value normalizes to an array of single values: Payload may pass a
|
|
54
|
+
// lone value (e.g. `children: 'uuid'`), which is wrapped into a single-element
|
|
55
|
+
// array. Writes may instead wrap the value in an atomic `$push`/`$remove`
|
|
56
|
+
// operator, which is preserved — its payload is converted but not array-wrapped,
|
|
57
|
+
// since those operators accept a single value or an array.
|
|
58
|
+
function convertHasManyValue(value, relationTo, payload, direction) {
|
|
59
|
+
const atomic = matchAtomicOperation(value, RELATIONSHIP_ATOMIC_OPERATORS);
|
|
60
|
+
if (atomic) {
|
|
61
|
+
return {
|
|
62
|
+
[atomic.operator]: convertAtomicPayload(atomic.inner, relationTo, payload, direction)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map((entry)=>convertSingleValue(entry, relationTo, payload, direction));
|
|
67
|
+
}
|
|
68
|
+
return [
|
|
69
|
+
convertSingleValue(value, relationTo, payload, direction)
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
// The payload of a `$push`/`$remove` operator may be a single value or an array;
|
|
73
|
+
// convert either without changing its arity.
|
|
74
|
+
function convertAtomicPayload(value, relationTo, payload, direction) {
|
|
75
|
+
return Array.isArray(value) ? value.map((entry)=>convertSingleValue(entry, relationTo, payload, direction)) : convertSingleValue(value, relationTo, payload, direction);
|
|
76
|
+
}
|
|
77
|
+
// A single relationship value is a polymorphic `{ relationTo, value }` (when the
|
|
78
|
+
// field targets multiple collections) or a bare id (when it targets one). The id
|
|
79
|
+
// type comes from the referenced collection.
|
|
80
|
+
function convertSingleValue(value, relationTo, payload, direction) {
|
|
81
|
+
if (value == null) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
if (valueIsValueWithRelation(value)) {
|
|
85
|
+
return {
|
|
86
|
+
...value,
|
|
87
|
+
value: convertLeafId(value.value, customIdTypeFor(payload, value.relationTo), direction)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// A non-polymorphic field targets a single collection (string `relationTo`).
|
|
91
|
+
const customIDType = typeof relationTo === 'string' ? customIdTypeFor(payload, relationTo) : undefined;
|
|
92
|
+
return convertLeafId(value, customIDType, direction);
|
|
93
|
+
}
|
|
94
|
+
function customIdTypeFor(payload, slug) {
|
|
95
|
+
return payload.collections?.[slug]?.customIDType;
|
|
96
|
+
}
|
|
97
|
+
function convertLeafId(id, customIDType, direction) {
|
|
98
|
+
if (id == null || id === '') {
|
|
99
|
+
return id;
|
|
100
|
+
}
|
|
101
|
+
// Only numeric custom ids differ between Payload (number) and the wire (string).
|
|
102
|
+
if (customIDType !== 'number') {
|
|
103
|
+
return id;
|
|
104
|
+
}
|
|
105
|
+
if (direction === 'toWire') {
|
|
106
|
+
return typeof id === 'number' ? String(id) : id;
|
|
107
|
+
}
|
|
108
|
+
return typeof id === 'string' ? Number(id) : id;
|
|
109
|
+
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { flattenAllFields, traverseFields } from 'payload';
|
|
2
2
|
import { applyDefaults } from './applyDefaults.js';
|
|
3
|
+
import { ATOMIC_OPERATORS, isAtomicOperation } from './atomicOperations.js';
|
|
3
4
|
import { castFieldValue } from './castFieldValue.js';
|
|
5
|
+
import { convertRelationshipFieldIds } from './convertRelationshipIds.js';
|
|
6
|
+
import { decodePointFromRead, encodePointForWrite } from './pointShape.js';
|
|
4
7
|
import { removeVirtualFields } from './removeVirtualFields.js';
|
|
8
|
+
import { resolveFieldLocalization } from './resolveFieldLocalization.js';
|
|
9
|
+
import { decodeRichTextFromRead, encodeRichTextForWrite } from './richTextShape.js';
|
|
5
10
|
import { stripFields } from './stripFields.js';
|
|
6
11
|
import { transformToLocalizeStatus } from './transformPublishedLocale.js';
|
|
7
|
-
const ATOMIC_OPERATION_KEYS = [
|
|
8
|
-
'$push',
|
|
9
|
-
'$remove',
|
|
10
|
-
'$inc'
|
|
11
|
-
];
|
|
12
|
-
function isAtomicOperation(value) {
|
|
13
|
-
if (value === null || value === undefined || typeof value !== 'object' || Array.isArray(value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const keys = Object.keys(value);
|
|
17
|
-
return keys.length === 1 && ATOMIC_OPERATION_KEYS.includes(keys[0]);
|
|
18
|
-
}
|
|
19
12
|
/**
|
|
20
13
|
* Transform data before sending to Content API (WRITE operations)
|
|
21
14
|
*
|
|
@@ -49,16 +42,21 @@ function isAtomicOperation(value) {
|
|
|
49
42
|
applyDefaults(transformed, collectionConfig.fields, payload.config.blocks);
|
|
50
43
|
}
|
|
51
44
|
// Use Payload's traverseFields to iterate over all fields for transformations
|
|
52
|
-
const callback = ({ field, ref })=>{
|
|
53
|
-
if (!('name' in
|
|
45
|
+
const callback = ({ field: declaredField, parentIsLocalized, ref })=>{
|
|
46
|
+
if (!('name' in declaredField) || declaredField.name == null) {
|
|
54
47
|
return;
|
|
55
48
|
}
|
|
56
49
|
if (!ref || typeof ref !== 'object') {
|
|
57
50
|
return;
|
|
58
51
|
}
|
|
52
|
+
const fieldName = declaredField.name;
|
|
53
|
+
const field = resolveFieldLocalization({
|
|
54
|
+
field: declaredField,
|
|
55
|
+
isAbsorbed: parentIsLocalized
|
|
56
|
+
});
|
|
59
57
|
const current = ref;
|
|
60
|
-
let value = current[
|
|
61
|
-
if (isAtomicOperation(value)) {
|
|
58
|
+
let value = current[fieldName];
|
|
59
|
+
if (isAtomicOperation(value, ATOMIC_OPERATORS) && field.type !== 'relationship' && field.type !== 'upload') {
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
64
62
|
// null → [] for non-localized array-like fields. SQL adapters return null for empty join
|
|
@@ -68,25 +66,33 @@ function isAtomicOperation(value) {
|
|
|
68
66
|
const isArrayLike = field.type === 'array' || field.type === 'blocks';
|
|
69
67
|
const isHasManySelect = field.type === 'select' && 'hasMany' in field && field.hasMany;
|
|
70
68
|
if (isHasManyArray || isArrayLike || isHasManySelect) {
|
|
71
|
-
current[
|
|
69
|
+
current[fieldName] = [];
|
|
72
70
|
return;
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
if (value !== null && value !== undefined) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
|
75
|
+
// Convert ids that point at a numeric-custom-id collection to strings —
|
|
76
|
+
// the wire (and the server's relationshipSchema) only accepts string ids —
|
|
77
|
+
// and normalize a has-many value to an array.
|
|
78
|
+
current[fieldName] = convertRelationshipFieldIds({
|
|
79
|
+
direction: 'toWire',
|
|
80
|
+
field,
|
|
81
|
+
payload,
|
|
83
82
|
value
|
|
84
|
-
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if (field.type === 'point') {
|
|
87
|
+
current[fieldName] = encodePointForWrite(field, value);
|
|
88
|
+
return;
|
|
89
89
|
}
|
|
90
|
+
if (field.type === 'richText') {
|
|
91
|
+
current[fieldName] = encodeRichTextForWrite(field, value);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
value = castFieldValue(field, value);
|
|
95
|
+
current[fieldName] = value;
|
|
90
96
|
}
|
|
91
97
|
};
|
|
92
98
|
traverseFields({
|
|
@@ -103,11 +109,10 @@ function isAtomicOperation(value) {
|
|
|
103
109
|
fields: collectionConfig.fields
|
|
104
110
|
}),
|
|
105
111
|
reservedKeys: [
|
|
106
|
-
'id'
|
|
107
|
-
'globalType'
|
|
112
|
+
'id'
|
|
108
113
|
]
|
|
109
114
|
});
|
|
110
|
-
removeVirtualFields(transformed, collectionConfig.fields);
|
|
115
|
+
removeVirtualFields(transformed, collectionConfig.fields, payload.config);
|
|
111
116
|
// Convert numeric ID to string for Content API
|
|
112
117
|
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
113
118
|
if (customIDType === 'number') {
|
|
@@ -169,21 +174,28 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
169
174
|
}
|
|
170
175
|
const isAllLocales = locale === 'all' || locale === '*';
|
|
171
176
|
// Use Payload's traverseFields to iterate over all fields
|
|
172
|
-
const callback = ({ field, parentPath, ref })=>{
|
|
173
|
-
if (!('name' in
|
|
177
|
+
const callback = ({ field: declaredField, parentIsLocalized, parentPath, ref })=>{
|
|
178
|
+
if (!('name' in declaredField) || !declaredField.name) {
|
|
174
179
|
return;
|
|
175
180
|
}
|
|
176
181
|
if (!ref || typeof ref !== 'object') {
|
|
177
182
|
return;
|
|
178
183
|
}
|
|
184
|
+
// Value shaping below depends on whether locale keys appear at this path, so
|
|
185
|
+
// work from the resolved field rather than the declared one.
|
|
186
|
+
const fieldName = declaredField.name;
|
|
187
|
+
const field = resolveFieldLocalization({
|
|
188
|
+
field: declaredField,
|
|
189
|
+
isAbsorbed: parentIsLocalized
|
|
190
|
+
});
|
|
179
191
|
const current = ref;
|
|
180
|
-
const value = current[
|
|
181
|
-
const isLocalized = 'localized' in field && field.localized;
|
|
192
|
+
const value = current[fieldName];
|
|
193
|
+
const isLocalized = 'localized' in field && field.localized === true;
|
|
182
194
|
// Group fields must always be an object so Payload can traverse sub-fields
|
|
183
195
|
// (e.g. join fields inside a group). A null/undefined group crashes afterRead.
|
|
184
196
|
if (field.type === 'group') {
|
|
185
197
|
if (value == null || typeof value !== 'object') {
|
|
186
|
-
current[
|
|
198
|
+
current[fieldName] = {};
|
|
187
199
|
}
|
|
188
200
|
return;
|
|
189
201
|
}
|
|
@@ -191,7 +203,7 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
191
203
|
// Content API returns join data directly at the field path (e.g. { docs: [...] }),
|
|
192
204
|
// but Payload's afterRead expects localized fields as { [locale]: value }.
|
|
193
205
|
if (field.type === 'join' && isLocalized && value !== undefined && !isAllLocales && locale) {
|
|
194
|
-
current[
|
|
206
|
+
current[fieldName] = {
|
|
195
207
|
[locale]: value
|
|
196
208
|
};
|
|
197
209
|
return;
|
|
@@ -202,22 +214,36 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
202
214
|
const isRequired = 'required' in field && field.required;
|
|
203
215
|
const isJoin = field.type === 'join';
|
|
204
216
|
if (!isRequired && !isJoin) {
|
|
205
|
-
current[
|
|
217
|
+
current[fieldName] = isLocalized && isAllLocales ? {} : null;
|
|
206
218
|
}
|
|
207
219
|
return;
|
|
208
220
|
}
|
|
209
221
|
// null localized field in all-locales mode → {} (empty locale map)
|
|
210
222
|
if (value === null && isLocalized && isAllLocales) {
|
|
211
|
-
current[
|
|
223
|
+
current[fieldName] = {};
|
|
212
224
|
return;
|
|
213
225
|
}
|
|
214
226
|
if (value !== null) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
|
228
|
+
// The Content API returns ids as strings; convert back to numbers for
|
|
229
|
+
// relationships that point at a numeric-custom-id collection so Payload
|
|
230
|
+
// sees its native type, and normalize a has-many value to an array.
|
|
231
|
+
current[fieldName] = convertRelationshipFieldIds({
|
|
232
|
+
direction: 'fromWire',
|
|
233
|
+
field,
|
|
234
|
+
payload,
|
|
219
235
|
value
|
|
220
|
-
|
|
236
|
+
});
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (field.type === 'point') {
|
|
240
|
+
current[fieldName] = decodePointFromRead(field, value);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (field.type === 'richText') {
|
|
244
|
+
const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name;
|
|
245
|
+
current[fieldName] = decodeRichTextFromRead(field, value, payload, fieldPath, collectionSlug);
|
|
246
|
+
return;
|
|
221
247
|
}
|
|
222
248
|
// Localized array/blocks: empty per-locale arrays → null in single-locale mode.
|
|
223
249
|
// Payload's afterRead fallback triggers on null (not []), matching SQL adapter behavior.
|
|
@@ -232,25 +258,15 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
232
258
|
}
|
|
233
259
|
// Localized fields: JSON string → parsed object (locale map).
|
|
234
260
|
// Simple strings that fail to parse as objects are kept as-is (expected for single-locale).
|
|
235
|
-
if (
|
|
261
|
+
if (isLocalized && typeof value === 'string') {
|
|
236
262
|
try {
|
|
237
263
|
const parsed = JSON.parse(value);
|
|
238
264
|
if (typeof parsed === 'object' && parsed !== null) {
|
|
239
|
-
current[
|
|
265
|
+
current[fieldName] = parsed;
|
|
240
266
|
}
|
|
241
267
|
} catch {
|
|
242
268
|
// Not valid JSON - keep original value
|
|
243
269
|
}
|
|
244
|
-
} else if (field.type === 'richText' && typeof value === 'string') {
|
|
245
|
-
try {
|
|
246
|
-
current[field.name] = JSON.parse(value);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name;
|
|
249
|
-
payload.logger.warn({
|
|
250
|
-
err: error instanceof Error ? error : new Error(String(error)),
|
|
251
|
-
msg: `Failed to parse richtext field '${fieldPath}' in collection '${collectionSlug}'`
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
270
|
}
|
|
255
271
|
// Date fields: Already ISO strings from Content API, no conversion needed
|
|
256
272
|
}
|
|
@@ -279,7 +295,7 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
279
295
|
]
|
|
280
296
|
});
|
|
281
297
|
// Remove virtual fields - must happen AFTER stripFields
|
|
282
|
-
removeVirtualFields(transformed, collectionConfig.fields);
|
|
298
|
+
removeVirtualFields(transformed, collectionConfig.fields, payload.config);
|
|
283
299
|
// Handle auth-specific fields that aren't in the field schema
|
|
284
300
|
// When these fields are null in DB, Content API omits them from response (undefined)
|
|
285
301
|
// But Payload expects them to be null, not undefined
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload expects globals to carry a `globalType` (their slug) alongside the stored data.
|
|
3
|
+
* Globals are stored as `_global-<slug>` collections that have no such column, so the adapter
|
|
4
|
+
* attaches it to every global document it returns.
|
|
5
|
+
*/
|
|
6
|
+
export declare function injectGlobalType<T>(doc: T, slug: string): T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isRecord } from '../isRecord.js';
|
|
2
|
+
/**
|
|
3
|
+
* Payload expects globals to carry a `globalType` (their slug) alongside the stored data.
|
|
4
|
+
* Globals are stored as `_global-<slug>` collections that have no such column, so the adapter
|
|
5
|
+
* attaches it to every global document it returns.
|
|
6
|
+
*/ export function injectGlobalType(doc, slug) {
|
|
7
|
+
return isRecord(doc) ? {
|
|
8
|
+
...doc,
|
|
9
|
+
globalType: slug
|
|
10
|
+
} : doc;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A locale-map is a plain object keyed by locale (e.g. `{ en: 'id', fr: 'id' }`) —
|
|
3
|
+
* distinct from the other object shapes a field value can take: a polymorphic
|
|
4
|
+
* relationship ref (`{ relationTo, value }`) or an atomic wrapper (`{ $push: … }`).
|
|
5
|
+
*
|
|
6
|
+
* Localized values arrive as a locale-map on write and all-locales reads, but as
|
|
7
|
+
* the bare per-locale value on single-locale reads, so a localized field cannot
|
|
8
|
+
* assume the map and has to discriminate on the shape.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isLocaleMap(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { valueIsValueWithRelation } from 'payload/shared';
|
|
2
|
+
import { ATOMIC_OPERATORS, isAtomicOperation } from './atomicOperations.js';
|
|
3
|
+
/**
|
|
4
|
+
* A locale-map is a plain object keyed by locale (e.g. `{ en: 'id', fr: 'id' }`) —
|
|
5
|
+
* distinct from the other object shapes a field value can take: a polymorphic
|
|
6
|
+
* relationship ref (`{ relationTo, value }`) or an atomic wrapper (`{ $push: … }`).
|
|
7
|
+
*
|
|
8
|
+
* Localized values arrive as a locale-map on write and all-locales reads, but as
|
|
9
|
+
* the bare per-locale value on single-locale reads, so a localized field cannot
|
|
10
|
+
* assume the map and has to discriminate on the shape.
|
|
11
|
+
*/ export function isLocaleMap(value) {
|
|
12
|
+
return !!value && typeof value === 'object' && !Array.isArray(value) && !valueIsValueWithRelation(value) && !isAtomicOperation(value, ATOMIC_OPERATORS);
|
|
13
|
+
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
|
|
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;
|
|
1
|
+
import type { Field, SanitizedConfig } from 'payload';
|
|
2
|
+
/** Remove pure virtual fields from document data at every schema depth. */
|
|
3
|
+
export declare function removeVirtualFields(data: Record<string, unknown>, fields: Field[], config: SanitizedConfig): void;
|
|
@@ -1,52 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
1
|
+
import { traverseFields } from 'payload';
|
|
2
|
+
/** Remove pure virtual fields from document data at every schema depth. */ export function removeVirtualFields(data, fields, config) {
|
|
3
|
+
traverseFields({
|
|
4
|
+
callback: ({ field, ref })=>{
|
|
5
|
+
if ('name' in field && field.name && 'virtual' in field && field.virtual === true) {
|
|
6
|
+
delete ref[field.name];
|
|
16
7
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
}
|
|
8
|
+
},
|
|
9
|
+
config,
|
|
10
|
+
fields,
|
|
11
|
+
fillEmpty: false,
|
|
12
|
+
ref: data
|
|
13
|
+
});
|
|
52
14
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Field, TabAsField } from 'payload';
|
|
2
|
+
interface ResolveFieldLocalizationOptions<TField extends Field | TabAsField> {
|
|
3
|
+
field: TField;
|
|
4
|
+
isAbsorbed: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns the field with `localized` collapsed to whether locale keys actually
|
|
8
|
+
* appear in its data — `false` for a field whose localized ancestor already
|
|
9
|
+
* absorbed them (see `createIsLocaleAbsorbed`).
|
|
10
|
+
*
|
|
11
|
+
* Every value-shaping helper keys off `field.localized` to decide whether it is
|
|
12
|
+
* looking at a locale map or a bare value, so handing them the resolved field
|
|
13
|
+
* keeps that decision correct without each one needing to know about absorption.
|
|
14
|
+
* The field is returned as-is when nothing changes, so the common path allocates
|
|
15
|
+
* nothing and any narrowing the caller has already done survives.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveFieldLocalization<TField extends Field | TabAsField>({ field, isAbsorbed, }: ResolveFieldLocalizationOptions<TField>): TField;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the field with `localized` collapsed to whether locale keys actually
|
|
3
|
+
* appear in its data — `false` for a field whose localized ancestor already
|
|
4
|
+
* absorbed them (see `createIsLocaleAbsorbed`).
|
|
5
|
+
*
|
|
6
|
+
* Every value-shaping helper keys off `field.localized` to decide whether it is
|
|
7
|
+
* looking at a locale map or a bare value, so handing them the resolved field
|
|
8
|
+
* keeps that decision correct without each one needing to know about absorption.
|
|
9
|
+
* The field is returned as-is when nothing changes, so the common path allocates
|
|
10
|
+
* nothing and any narrowing the caller has already done survives.
|
|
11
|
+
*/ export function resolveFieldLocalization({ field, isAbsorbed }) {
|
|
12
|
+
if (!isAbsorbed || !('localized' in field) || field.localized !== true) {
|
|
13
|
+
return field;
|
|
14
|
+
}
|
|
15
|
+
// Only `localized` changes, so the result is still the same field type; TypeScript
|
|
16
|
+
// cannot see that through a spread of a generic union member.
|
|
17
|
+
return {
|
|
18
|
+
...field,
|
|
19
|
+
localized: false
|
|
20
|
+
};
|
|
21
|
+
}
|