diff --git a/docs/access-control/collections.mdx b/docs/access-control/collections.mdx index 8bf552228..9b0969de1 100644 --- a/docs/access-control/collections.mdx +++ b/docs/access-control/collections.mdx @@ -30,7 +30,7 @@ If a Collection supports [`Authentication`](/docs/authentication/overview), the ```ts import { CollectionConfig } from 'payload/types'; -const Posts: CollectionConfig = { +export const Posts: CollectionConfig = { slug: "posts", // highlight-start access: { @@ -42,8 +42,6 @@ const Posts: CollectionConfig = { }, // highlight-end }; - -export default Posts; ``` ### Create diff --git a/docs/access-control/fields.mdx b/docs/access-control/fields.mdx index 3a5b23614..513f140e9 100644 --- a/docs/access-control/fields.mdx +++ b/docs/access-control/fields.mdx @@ -20,7 +20,7 @@ Field Access Control is specified with functions inside a field's config. All fi ```ts import { CollectionConfig } from 'payload/types'; -const Posts: CollectionConfig = { +export const Posts: CollectionConfig = { slug: 'posts', fields: [ { @@ -67,6 +67,8 @@ Returns a boolean which allows or denies the ability to read a field's value. If Returns a boolean which allows or denies the ability to update a field's value. If `false` is returned, any passed values will be discarded. +If `false` is returned and you attempt to update the field's value, the operation will **not** throw an error however the field will be omitted from the update operation and the value will remain unchanged. + **Available argument properties:** | Option | Description | diff --git a/docs/admin/webpack.mdx b/docs/admin/webpack.mdx index 74f4b3c4c..ddfa1599f 100644 --- a/docs/admin/webpack.mdx +++ b/docs/admin/webpack.mdx @@ -56,7 +56,7 @@ You may rely on server-only packages such as the above to perform logic in acces import { CollectionConfig } from 'payload/types'; import createStripeSubscription from './hooks/createStripeSubscription'; -const Subscription: CollectionConfig = { +export const Subscription: CollectionConfig = { slug: 'subscriptions', hooks: { beforeChange: [ @@ -71,8 +71,6 @@ const Subscription: CollectionConfig = { } ] }; - -export default Subscription; ``` The collection above features a `beforeChange` hook that creates a Stripe subscription whenever a Subscription document is created in Payload. diff --git a/docs/authentication/config.mdx b/docs/authentication/config.mdx index a15672b87..0aa9d59b6 100644 --- a/docs/authentication/config.mdx +++ b/docs/authentication/config.mdx @@ -82,7 +82,7 @@ Example: ```ts import { CollectionConfig } from 'payload/types'; -const Customers: CollectionConfig = { +export const Customers: CollectionConfig = { slug: 'customers', auth: { forgotPassword: { @@ -156,7 +156,7 @@ Example: import { CollectionConfig } from 'payload/types'; -const Customers: CollectionConfig = { +export const Customers: CollectionConfig = { slug: 'customers', auth: { verify: { diff --git a/docs/authentication/overview.mdx b/docs/authentication/overview.mdx index 22b05e0f1..f107f5711 100644 --- a/docs/authentication/overview.mdx +++ b/docs/authentication/overview.mdx @@ -35,8 +35,8 @@ Simple example collection: ```ts import { CollectionConfig } from 'payload/types'; -const Admins: CollectionConfig = { - slug: +export const Admins: CollectionConfig = { + slug: 'admins', // highlight-start auth: { tokenExpiration: 7200, // How many seconds to keep the user logged in diff --git a/docs/configuration/collections.mdx b/docs/configuration/collections.mdx index 93a8dc19b..307b18dac 100644 --- a/docs/configuration/collections.mdx +++ b/docs/configuration/collections.mdx @@ -39,7 +39,7 @@ It's often best practice to write your Collections in separate files and then im ```ts import { CollectionConfig } from 'payload/types'; -const Orders: CollectionConfig = { +export const Orders: CollectionConfig = { slug: 'orders', fields: [ { @@ -95,7 +95,7 @@ If the function is specified, a Preview button will automatically appear in the ```ts import { CollectionConfig } from 'payload/types'; -const Posts: CollectionConfig = { +export const Posts: CollectionConfig = { slug: 'posts', fields: [ { diff --git a/docs/configuration/globals.mdx b/docs/configuration/globals.mdx index fe14da729..4dd649400 100644 --- a/docs/configuration/globals.mdx +++ b/docs/configuration/globals.mdx @@ -87,7 +87,7 @@ If the function is specified, a Preview button will automatically appear in the ```ts import { GlobalConfig } from "payload/types"; -const MyGlobal: GlobalConfig = { +export const MyGlobal: GlobalConfig = { slug: "my-global", fields: [ { diff --git a/docs/configuration/i18n.mdx b/docs/configuration/i18n.mdx index da426061e..df34bdbc2 100644 --- a/docs/configuration/i18n.mdx +++ b/docs/configuration/i18n.mdx @@ -12,7 +12,9 @@ While Payload's built-in features come translated, you may want to also translat Here is an example of a simple collection supporting both English and Spanish editors: ```ts -const Articles: CollectionConfig = { +import { CollectionConfig } from 'payload/types'; + +export const Articles: CollectionConfig = { slug: 'articles', labels: { singular: { diff --git a/docs/fields/array.mdx b/docs/fields/array.mdx index b17c957ed..5de9f13b7 100644 --- a/docs/fields/array.mdx +++ b/docs/fields/array.mdx @@ -56,7 +56,7 @@ In addition to the default [field admin config](/docs/fields/overview#admin-conf ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/blocks.mdx b/docs/fields/blocks.mdx index 7103e57dc..bc8a19d1d 100644 --- a/docs/fields/blocks.mdx +++ b/docs/fields/blocks.mdx @@ -102,7 +102,7 @@ const QuoteBlock: Block = { ] }; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/checkbox.mdx b/docs/fields/checkbox.mdx index 54f725f23..47745a621 100644 --- a/docs/fields/checkbox.mdx +++ b/docs/fields/checkbox.mdx @@ -36,7 +36,7 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/code.mdx b/docs/fields/code.mdx index e70010f14..1ec79469b 100644 --- a/docs/fields/code.mdx +++ b/docs/fields/code.mdx @@ -51,7 +51,7 @@ In addition to the default [field admin config](/docs/fields/overview#admin-conf ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/collapsible.mdx b/docs/fields/collapsible.mdx index 8a6a4c808..0ecd0f55e 100644 --- a/docs/fields/collapsible.mdx +++ b/docs/fields/collapsible.mdx @@ -35,7 +35,7 @@ In addition to the default [field admin config](/docs/fields/overview#admin-conf ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/date.mdx b/docs/fields/date.mdx index 6e358fb39..1c79df063 100644 --- a/docs/fields/date.mdx +++ b/docs/fields/date.mdx @@ -70,7 +70,7 @@ When only `pickerAppearance` is set, an equivalent format will be rendered in th ```ts import { CollectionConfig } from "payload/types"; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: "example-collection", fields: [ { diff --git a/docs/fields/email.mdx b/docs/fields/email.mdx index 9e5a305b3..0115d9780 100644 --- a/docs/fields/email.mdx +++ b/docs/fields/email.mdx @@ -49,7 +49,7 @@ Set this property to a string that will be used for browser autocomplete. ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/group.mdx b/docs/fields/group.mdx index a7dc8f320..3eaf00560 100644 --- a/docs/fields/group.mdx +++ b/docs/fields/group.mdx @@ -43,7 +43,7 @@ Set this property to `true` to hide this field's gutter within the admin panel. ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/json.mdx b/docs/fields/json.mdx index 89a7ace77..17c8fbd58 100644 --- a/docs/fields/json.mdx +++ b/docs/fields/json.mdx @@ -48,7 +48,7 @@ In addition to the default [field admin config](/docs/fields/overview#admin-conf ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/number.mdx b/docs/fields/number.mdx index c18c685ac..263c88cbc 100644 --- a/docs/fields/number.mdx +++ b/docs/fields/number.mdx @@ -55,7 +55,7 @@ Set this property to a string that will be used for browser autocomplete. ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/overview.mdx b/docs/fields/overview.mdx index c051d5276..29146f8b3 100644 --- a/docs/fields/overview.mdx +++ b/docs/fields/overview.mdx @@ -19,7 +19,7 @@ The required `type` property on a field determines what values it can accept, ho ```ts import { CollectionConfig } from 'payload/types'; -const Page: CollectionConfig = { +export const Page: CollectionConfig = { slug: 'pages', fields: [ { @@ -90,7 +90,7 @@ Example: ```ts import { CollectionConfig } from 'payload/types'; -const Orders: CollectionConfig = { +export const Orders: CollectionConfig = { slug: 'orders', fields: [ { diff --git a/docs/fields/point.mdx b/docs/fields/point.mdx index ebd459596..9a9894948 100644 --- a/docs/fields/point.mdx +++ b/docs/fields/point.mdx @@ -40,7 +40,7 @@ The data structure in the database matches the GeoJSON structure to represent po ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/radio.mdx b/docs/fields/radio.mdx index 664582dd2..0934e37e2 100644 --- a/docs/fields/radio.mdx +++ b/docs/fields/radio.mdx @@ -50,7 +50,7 @@ The `layout` property allows for the radio group to be styled as a horizonally o ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { @@ -73,5 +73,4 @@ const ExampleCollection: CollectionConfig = { } ] } - ``` diff --git a/docs/fields/relationship.mdx b/docs/fields/relationship.mdx index bb64160bc..702a9abc8 100644 --- a/docs/fields/relationship.mdx +++ b/docs/fields/relationship.mdx @@ -20,7 +20,7 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma ### Config | Option | Description | -|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **`name`** \* | To be used as the property name when stored and retrieved from the database. [More](/docs/fields/overview#field-names) | | **`relationTo`** \* | Provide one or many collection `slug`s to be able to assign relationships to. | | **`filterOptions`** | A query to filter which options appear in the UI and validate against. [More](#filtering-relationship-options). | @@ -77,27 +77,34 @@ The `filterOptions` property can either be a `Where` query directly, or a functi | `id` | The value of the collection `id`, will be `undefined` on create request | | `user` | The currently authenticated user object | -**Example:** +### Example ```ts -const relationshipField = { - name: "purchase", - type: "relationship", - relationTo: ["products", "services"], - filterOptions: ({ relationTo, siblingData }) => { - // returns a Where query dynamically by the type of relationship - if (relationTo === "products") { - return { - stock: { greater_than: siblingData.quantity }, - }; - } +import { CollectionConfig } from "payload/types"; - if (relationTo === "services") { - return { - isAvailable: { equals: true }, - }; - } - }, +export const ExampleCollection: CollectionConfig = { + slug: "example-collection", + fields: [ + { + name: "purchase", + type: "relationship", + relationTo: ["products", "services"], + filterOptions: ({ relationTo, siblingData }) => { + // returns a Where query dynamically by the type of relationship + if (relationTo === "products") { + return { + stock: { greater_than: siblingData.quantity }, + }; + } + + if (relationTo === "services") { + return { + isAvailable: { equals: true }, + }; + } + }, + }, + ], }; ``` diff --git a/docs/fields/rich-text.mdx b/docs/fields/rich-text.mdx index b071e1c3d..791d7036b 100644 --- a/docs/fields/rich-text.mdx +++ b/docs/fields/rich-text.mdx @@ -141,7 +141,7 @@ Custom `Leaf` objects follow a similar pattern but require you to define the `Le ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { @@ -371,5 +371,4 @@ import type { RichTextCustomElement, RichTextCustomLeaf, } from 'payload/types'; - ``` diff --git a/docs/fields/row.mdx b/docs/fields/row.mdx index 5987e59f3..07be9d496 100644 --- a/docs/fields/row.mdx +++ b/docs/fields/row.mdx @@ -26,7 +26,7 @@ keywords: row, fields, config, configuration, documentation, Content Management ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/select.mdx b/docs/fields/select.mdx index a0a92aee0..264c17a2f 100644 --- a/docs/fields/select.mdx +++ b/docs/fields/select.mdx @@ -62,7 +62,7 @@ Set to `true` if you'd like this field to be sortable within the Admin UI using ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/tabs.mdx b/docs/fields/tabs.mdx index 9d1a49856..cc6150800 100644 --- a/docs/fields/tabs.mdx +++ b/docs/fields/tabs.mdx @@ -40,7 +40,7 @@ Each tab has its own required `label` and `fields` array. You can also optionall ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/text.mdx b/docs/fields/text.mdx index 3c44e2605..61c8c87f5 100644 --- a/docs/fields/text.mdx +++ b/docs/fields/text.mdx @@ -51,7 +51,7 @@ Set this property to a string that will be used for browser autocomplete. ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/textarea.mdx b/docs/fields/textarea.mdx index 29005aba6..69be15112 100644 --- a/docs/fields/textarea.mdx +++ b/docs/fields/textarea.mdx @@ -51,7 +51,7 @@ Set this property to a string that will be used for browser autocomplete. ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/ui.mdx b/docs/fields/ui.mdx index 7f393ccf8..78f4ac72c 100644 --- a/docs/fields/ui.mdx +++ b/docs/fields/ui.mdx @@ -39,7 +39,7 @@ With this field, you can also inject custom `Cell` components that appear as add ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/fields/upload.mdx b/docs/fields/upload.mdx index 44d0d2e8c..4a593caf9 100644 --- a/docs/fields/upload.mdx +++ b/docs/fields/upload.mdx @@ -51,7 +51,7 @@ keywords: upload, images media, fields, config, configuration, documentation, Co ```ts import { CollectionConfig } from 'payload/types'; -const ExampleCollection: CollectionConfig = { +export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { diff --git a/docs/graphql/overview.mdx b/docs/graphql/overview.mdx index bde500b7e..1f90e6653 100644 --- a/docs/graphql/overview.mdx +++ b/docs/graphql/overview.mdx @@ -32,7 +32,7 @@ Everything that can be done to a Collection via the REST or Local API can be don ```ts import { CollectionConfig } from 'payload/types'; -const PublicUser: CollectionConfig = { +export const PublicUser: CollectionConfig = { slug: 'public-users', auth: true, // Auth is enabled fields: [ diff --git a/docs/hooks/collections.mdx b/docs/hooks/collections.mdx index e7fe7a1bd..8923f6527 100644 --- a/docs/hooks/collections.mdx +++ b/docs/hooks/collections.mdx @@ -34,7 +34,7 @@ All collection Hook properties accept arrays of synchronous or asynchronous func ```ts import { CollectionConfig } from 'payload/types'; -const ExampleHooks: CollectionConfig = { +export const ExampleHooks: CollectionConfig = { slug: 'example-hooks', fields: [ { name: 'name', type: 'text'}, diff --git a/docs/queries/overview.mdx b/docs/queries/overview.mdx index ba42e8096..5e96e697a 100644 --- a/docs/queries/overview.mdx +++ b/docs/queries/overview.mdx @@ -19,7 +19,7 @@ For example, say you have a collection as follows: ```ts import { CollectionConfig } from 'payload/types'; -const Post: CollectionConfig = { +export const Post: CollectionConfig = { slug: 'posts', fields: [ { diff --git a/docs/rest-api/overview.mdx b/docs/rest-api/overview.mdx index fde6fcf8f..3e92229db 100644 --- a/docs/rest-api/overview.mdx +++ b/docs/rest-api/overview.mdx @@ -99,7 +99,7 @@ Example: import { CollectionConfig } from 'payload/types'; // a collection of 'orders' with an additional route for tracking details, reachable at /api/orders/:id/tracking -const Orders: CollectionConfig = { +export const Orders: CollectionConfig = { slug: 'orders', fields: [ /* ... */ ], // highlight-start diff --git a/docs/upload/overview.mdx b/docs/upload/overview.mdx index b355f8f49..4ec42653c 100644 --- a/docs/upload/overview.mdx +++ b/docs/upload/overview.mdx @@ -60,7 +60,7 @@ _An asterisk denotes that a property above is required._ ```ts import { CollectionConfig } from 'payload/types'; -const Media: CollectionConfig = { +export const Media: CollectionConfig = { slug: 'media', upload: { staticURL: '/media', @@ -165,7 +165,7 @@ You can specify how Payload retrieves admin thumbnails for your upload-enabled C ```ts import { CollectionConfig } from 'payload/types'; -const Media: CollectionConfig = { +export const Media: CollectionConfig = { slug: 'media', upload: { staticURL: '/media', @@ -200,7 +200,7 @@ Some example values are: `image/*`, `audio/*`, `video/*`, `image/png`, `applicat ```ts import { CollectionConfig } from 'payload/types'; -const Media: CollectionConfig = { +export const Media: CollectionConfig = { slug: 'media', upload: { staticURL: '/media', diff --git a/docs/versions/autosave.mdx b/docs/versions/autosave.mdx index f2bc2b7d6..a01ea4f1c 100644 --- a/docs/versions/autosave.mdx +++ b/docs/versions/autosave.mdx @@ -28,7 +28,7 @@ Collections and Globals both support the same options for configuring autosave. ```ts import { CollectionConfig } from 'payload/types'; -const Pages: CollectionConfig = { +export const Pages: CollectionConfig = { slug: 'pages', access: { read: ({ req }) => { diff --git a/docs/versions/drafts.mdx b/docs/versions/drafts.mdx index 7cffd18f0..af08dcc26 100644 --- a/docs/versions/drafts.mdx +++ b/docs/versions/drafts.mdx @@ -84,7 +84,7 @@ Here is an example that utilizes the `_status` field to require a user to be log ```ts import { CollectionConfig } from 'payload/types'; -const Pages: CollectionConfig = { +export const Pages: CollectionConfig = { slug: 'pages', access: { read: ({ req }) => { @@ -119,7 +119,7 @@ Here is an example for how to write an access control function that grants acces ```ts import { CollectionConfig } from 'payload/types'; -const Pages: CollectionConfig = { +export const Pages: CollectionConfig = { slug: 'pages', access: { read: ({ req }) => {