payload 1.0.27 → 1.0.28

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/admin/components/elements/Status/index.js +1 -1
  3. package/dist/admin/components/elements/ViewDescription/types.d.ts +1 -1
  4. package/dist/admin/components/elements/WhereBuilder/index.js +13 -7
  5. package/dist/admin/components/forms/field-types/Array/index.d.ts +3 -2
  6. package/dist/admin/components/forms/field-types/Array/index.js +201 -6
  7. package/dist/admin/components/forms/field-types/Blocks/index.d.ts +3 -2
  8. package/dist/admin/components/forms/field-types/Blocks/index.js +213 -6
  9. package/dist/admin/components/forms/field-types/Collapsible/index.js +2 -2
  10. package/dist/admin/components/forms/field-types/Row/index.js +2 -2
  11. package/dist/admin/components/forms/field-types/Tabs/index.js +2 -2
  12. package/dist/admin/components/forms/field-types/getFieldPath.d.ts +2 -0
  13. package/dist/admin/components/forms/field-types/getFieldPath.js +6 -0
  14. package/dist/admin/components/forms/field-types/index.d.ts +23 -23
  15. package/dist/admin/components/utilities/RenderCustomComponent/types.d.ts +2 -2
  16. package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +1 -1
  17. package/dist/auth/operations/local/forgotPassword.js +3 -6
  18. package/dist/auth/operations/local/login.js +6 -9
  19. package/dist/auth/operations/local/resetPassword.js +4 -7
  20. package/dist/auth/operations/local/unlock.js +4 -7
  21. package/dist/collections/config/types.d.ts +2 -2
  22. package/dist/collections/dataloader.js +16 -8
  23. package/dist/collections/operations/local/create.d.ts +2 -2
  24. package/dist/collections/operations/local/create.js +11 -13
  25. package/dist/collections/operations/local/find.js +6 -10
  26. package/dist/collections/operations/local/findByID.js +6 -10
  27. package/dist/collections/operations/local/findVersionByID.js +6 -9
  28. package/dist/config/types.d.ts +13 -13
  29. package/dist/fields/config/sanitize.js +3 -3
  30. package/dist/fields/config/schema.js +3 -3
  31. package/dist/fields/config/types.d.ts +9 -9
  32. package/dist/fields/validations.js +43 -1
  33. package/dist/globals/config/types.d.ts +1 -1
  34. package/dist/utilities/getIDType.d.ts +2 -0
  35. package/dist/utilities/getIDType.js +11 -0
  36. package/dist/utilities/isValidID.d.ts +1 -0
  37. package/dist/utilities/isValidID.js +16 -0
  38. package/docs/access-control/collections.mdx +21 -12
  39. package/docs/access-control/fields.mdx +5 -3
  40. package/docs/access-control/globals.mdx +8 -4
  41. package/docs/access-control/overview.mdx +1 -1
  42. package/docs/admin/components.mdx +29 -25
  43. package/docs/admin/customizing-css.mdx +2 -2
  44. package/docs/admin/overview.mdx +2 -2
  45. package/docs/admin/webpack.mdx +8 -7
  46. package/docs/authentication/config.mdx +14 -9
  47. package/docs/authentication/operations.mdx +22 -22
  48. package/docs/authentication/overview.mdx +8 -6
  49. package/docs/authentication/using-middleware.mdx +1 -1
  50. package/docs/configuration/collections.mdx +11 -7
  51. package/docs/configuration/globals.mdx +9 -5
  52. package/docs/configuration/localization.mdx +33 -31
  53. package/docs/configuration/overview.mdx +4 -7
  54. package/docs/email/overview.mdx +11 -7
  55. package/docs/fields/array.mdx +6 -5
  56. package/docs/fields/blocks.mdx +6 -4
  57. package/docs/fields/checkbox.mdx +6 -5
  58. package/docs/fields/code.mdx +6 -5
  59. package/docs/fields/collapsible.mdx +6 -5
  60. package/docs/fields/date.mdx +6 -5
  61. package/docs/fields/email.mdx +6 -5
  62. package/docs/fields/group.mdx +6 -5
  63. package/docs/fields/number.mdx +6 -5
  64. package/docs/fields/overview.mdx +40 -38
  65. package/docs/fields/point.mdx +6 -4
  66. package/docs/fields/radio.mdx +5 -3
  67. package/docs/fields/relationship.mdx +21 -21
  68. package/docs/fields/rich-text.mdx +9 -7
  69. package/docs/fields/row.mdx +5 -3
  70. package/docs/fields/select.mdx +4 -3
  71. package/docs/fields/tabs.mdx +5 -3
  72. package/docs/fields/text.mdx +5 -3
  73. package/docs/fields/textarea.mdx +5 -3
  74. package/docs/fields/ui.mdx +5 -3
  75. package/docs/fields/upload.mdx +5 -3
  76. package/docs/getting-started/concepts.mdx +1 -1
  77. package/docs/graphql/extending.mdx +1 -1
  78. package/docs/graphql/overview.mdx +8 -4
  79. package/docs/hooks/collections.mdx +62 -36
  80. package/docs/hooks/fields.mdx +5 -3
  81. package/docs/hooks/globals.mdx +25 -17
  82. package/docs/local-api/overview.mdx +27 -4
  83. package/docs/plugins/overview.mdx +3 -4
  84. package/docs/production/deployment.mdx +1 -1
  85. package/docs/queries/overview.mdx +4 -2
  86. package/docs/queries/pagination.mdx +1 -1
  87. package/docs/rest-api/overview.mdx +4 -2
  88. package/docs/upload/overview.mdx +35 -29
  89. package/docs/versions/autosave.mdx +4 -2
  90. package/docs/versions/drafts.mdx +8 -4
  91. package/docs/versions/overview.mdx +1 -1
  92. package/package.json +1 -1
  93. package/types.d.ts +21 -0
  94. package/dist/admin/components/forms/field-types/Array/Array.d.ts +0 -5
  95. package/dist/admin/components/forms/field-types/Array/Array.js +0 -201
  96. package/dist/admin/components/forms/field-types/Blocks/Blocks.d.ts +0 -5
  97. package/dist/admin/components/forms/field-types/Blocks/Blocks.js +0 -213
@@ -29,8 +29,10 @@ At the top of your Payload config you can define all the options to manage Graph
29
29
 
30
30
  Everything that can be done to a Collection via the REST or Local API can be done with GraphQL (outside of uploading files, which is REST-only). If you have a collection as follows:
31
31
 
32
- ```js
33
- const PublicUser = {
32
+ ```ts
33
+ import { CollectionConfig } from 'payload/types';
34
+
35
+ const PublicUser: CollectionConfig = {
34
36
  slug: 'public-users',
35
37
  auth: true, // Auth is enabled
36
38
  labels: {
@@ -70,8 +72,10 @@ const PublicUser = {
70
72
 
71
73
  Globals are also fully supported. For example:
72
74
 
73
- ```js
74
- const Header = {
75
+ ```ts
76
+ import { GlobalConfig } from 'payload/types';
77
+
78
+ const Header: GlobalConfig = {
75
79
  slug: 'header',
76
80
  fields: [
77
81
  ...
@@ -30,10 +30,11 @@ Additionally, `auth`-enabled collections feature the following hooks:
30
30
 
31
31
  All collection Hook properties accept arrays of synchronous or asynchronous functions. Each Hook type receives specific arguments and has the ability to modify specific outputs.
32
32
 
33
- `collections/example-hooks.js`
34
- ```js
35
- // Collection config
36
- module.exports = {
33
+ `collections/exampleHooks.js`
34
+ ```ts
35
+ import { CollectionConfig } from 'payload/types';
36
+
37
+ const ExampleHooks: CollectionConfig = {
37
38
  slug: 'example-hooks',
38
39
  fields: [
39
40
  { name: 'name', type: 'text'},
@@ -65,8 +66,10 @@ The `beforeOperation` Hook type can be used to modify the arguments that operati
65
66
 
66
67
  Available Collection operations include `create`, `read`, `update`, `delete`, `login`, `refresh` and `forgotPassword`.
67
68
 
68
- ```js
69
- const beforeOperationHook = async ({
69
+ ```ts
70
+ import { CollectionBeforeOperationHook } from 'payload/types';
71
+
72
+ const beforeOperationHook: CollectionBeforeOperationHook = async ({
70
73
  args, // Original arguments passed into the operation
71
74
  operation, // name of the operation
72
75
  }) => {
@@ -78,8 +81,10 @@ const beforeOperationHook = async ({
78
81
 
79
82
  Runs before the `create` and `update` operations. This hook allows you to add or format data before the incoming data is validated.
80
83
 
81
- ```js
82
- const beforeValidateHook = async ({
84
+ ```ts
85
+ import { CollectionBeforeOperationHook } from 'payload/types';
86
+
87
+ const beforeValidateHook: CollectionBeforeValidateHook = async ({
83
88
  data, // incoming data to update or create with
84
89
  req, // full express request
85
90
  operation, // name of the operation ie. 'create', 'update'
@@ -93,8 +98,10 @@ const beforeValidateHook = async ({
93
98
 
94
99
  Immediately following validation, `beforeChange` hooks will run within `create` and `update` operations. At this stage, you can be confident that the data that will be saved to the document is valid in accordance to your field validations. You can optionally modify the shape of data to be saved.
95
100
 
96
- ```js
97
- const beforeChangeHook = async ({
101
+ ```ts
102
+ import { CollectionBeforeChangeHook } from 'payload/types';
103
+
104
+ const beforeChangeHook: CollectionBeforeChangeHook = async ({
98
105
  data, // incoming data to update or create with
99
106
  req, // full express request
100
107
  operation, // name of the operation ie. 'create', 'update'
@@ -108,8 +115,10 @@ const beforeChangeHook = async ({
108
115
 
109
116
  After a document is created or updated, the `afterChange` hook runs. This hook is helpful to recalculate statistics such as total sales within a global, syncing user profile changes to a CRM, and more.
110
117
 
111
- ```js
112
- const afterChangeHook = async ({
118
+ ```ts
119
+ import { CollectionAfterChangeHook } from 'payload/types';
120
+
121
+ const afterChangeHook: CollectionAfterChangeHook = async ({
113
122
  doc, // full document data
114
123
  req, // full express request
115
124
  operation, // name of the operation ie. 'create', 'update'
@@ -122,8 +131,10 @@ const afterChangeHook = async ({
122
131
 
123
132
  Runs before `find` and `findByID` operations are transformed for output by `afterRead`. This hook fires before hidden fields are removed and before localized fields are flattened into the requested locale. Using this Hook will provide you with all locales and all hidden fields via the `doc` argument.
124
133
 
125
- ```js
126
- const beforeReadHook = async ({
134
+ ```ts
135
+ import { CollectionBeforeReadHook } from 'payload/types';
136
+
137
+ const beforeReadHook: CollectionBeforeReadHook = async ({
127
138
  doc, // full document data
128
139
  req, // full express request
129
140
  query, // JSON formatted query
@@ -136,8 +147,10 @@ const beforeReadHook = async ({
136
147
 
137
148
  Runs as the last step before documents are returned. Flattens locales, hides protected fields, and removes fields that users do not have access to.
138
149
 
139
- ```js
140
- const afterReadHook = async ({
150
+ ```ts
151
+ import { CollectionAfterReadHook } from 'payload/types';
152
+
153
+ const afterReadHook: CollectionAfterReadHook = async ({
141
154
  doc, // full document data
142
155
  req, // full express request
143
156
  query, // JSON formatted query
@@ -151,8 +164,10 @@ const afterReadHook = async ({
151
164
 
152
165
  Runs before the `delete` operation. Returned values are discarded.
153
166
 
154
- ```js
155
- const beforeDeleteHook = async ({
167
+ ```ts
168
+ import { CollectionBeforeDeleteHook } from 'payload/types';
169
+
170
+ const beforeDeleteHook: CollectionBeforeDeleteHook = async ({
156
171
  req, // full express request
157
172
  id, // id of document to delete
158
173
  }) => {...}
@@ -162,8 +177,10 @@ const beforeDeleteHook = async ({
162
177
 
163
178
  Runs immediately after the `delete` operation removes records from the database. Returned values are discarded.
164
179
 
165
- ```js
166
- const afterDeleteHook = async ({
180
+ ```ts
181
+ import { CollectionAfterDeleteHook } from 'payload/types';
182
+
183
+ const afterDeleteHook: CollectionAfterDeleteHook = async ({
167
184
  req, // full express request
168
185
  id, // id of document to delete
169
186
  doc, // deleted document
@@ -174,8 +191,10 @@ const afterDeleteHook = async ({
174
191
 
175
192
  For auth-enabled Collections, this hook runs after successful `login` operations. You can optionally modify the user that is returned.
176
193
 
177
- ```js
178
- const beforeLoginHook = async ({
194
+ ```ts
195
+ import { CollectionBeforeLoginHook } from 'payload/types';
196
+
197
+ const beforeLoginHook: CollectionBeforeLoginHook = async ({
179
198
  req, // full express request
180
199
  user, // user being logged in
181
200
  token, // user token
@@ -188,8 +207,10 @@ const beforeLoginHook = async ({
188
207
 
189
208
  For auth-enabled Collections, this hook runs after successful `login` operations. You can optionally modify the user that is returned.
190
209
 
191
- ```js
192
- const afterLoginHook = async ({
210
+ ```ts
211
+ import { CollectionAfterLoginHook } from 'payload/types';
212
+
213
+ const afterLoginHook: CollectionAfterLoginHook = async ({
193
214
  req, // full express request
194
215
  }) => {...}
195
216
  ```
@@ -198,8 +219,10 @@ const afterLoginHook = async ({
198
219
 
199
220
  For auth-enabled Collections, this hook runs after `logout` operations.
200
221
 
201
- ```js
202
- const afterLogoutHook = async ({
222
+ ```ts
223
+ import { CollectionAfterLogoutHook } from 'payload/types';
224
+
225
+ const afterLogoutHook: CollectionAfterLogoutHook = async ({
203
226
  req, // full express request
204
227
  }) => {...}
205
228
  ```
@@ -208,8 +231,10 @@ const afterLogoutHook = async ({
208
231
 
209
232
  For auth-enabled Collections, this hook runs after `refresh` operations.
210
233
 
211
- ```js
212
- const afterRefreshHook = async ({
234
+ ```ts
235
+ import { CollectionAfterRefreshHook } from 'payload/types';
236
+
237
+ const afterRefreshHook: CollectionAfterRefreshHook = async ({
213
238
  req, // full express request
214
239
  res, // full express response
215
240
  token, // newly refreshed user token
@@ -220,8 +245,10 @@ const afterRefreshHook = async ({
220
245
 
221
246
  For auth-enabled Collections, this hook runs after `me` operations.
222
247
 
223
- ```js
224
- const afterMeHook = async ({
248
+ ```ts
249
+ import { CollectionAfterMeHook } from 'payload/types';
250
+
251
+ const afterMeHook: CollectionAfterMeHook = async ({
225
252
  req, // full express request
226
253
  response, // response to return
227
254
  }) => {...}
@@ -231,8 +258,10 @@ const afterMeHook = async ({
231
258
 
232
259
  For auth-enabled Collections, this hook runs after successful `forgotPassword` operations. Returned values are discarded.
233
260
 
234
- ```js
235
- const afterLoginHook = async ({
261
+ ```ts
262
+ import { CollectionAfterForgotPasswordHook } from 'payload/types';
263
+
264
+ const afterLoginHook: CollectionAfterForgotPasswordHook = async ({
236
265
  req, // full express request
237
266
  user, // user being logged in
238
267
  token, // user token
@@ -245,7 +274,7 @@ const afterLoginHook = async ({
245
274
 
246
275
  Payload exports a type for each Collection hook which can be accessed as follows:
247
276
 
248
- ```js
277
+ ```ts
249
278
  import type {
250
279
  CollectionBeforeOperationHook,
251
280
  CollectionBeforeValidateHook,
@@ -262,7 +291,4 @@ import type {
262
291
  CollectionAfterMeHook,
263
292
  CollectionAfterForgotPasswordHook,
264
293
  } from 'payload/types';
265
-
266
- // Use hook types here...
267
- }
268
294
  ```
@@ -26,8 +26,10 @@ Field-level hooks offer incredible potential for encapsulating your logic. They
26
26
  ## Config
27
27
 
28
28
  Example field configuration:
29
- ```js
30
- {
29
+ ```ts
30
+ import { CollectionConfig } from 'payload/types';
31
+
32
+ const ExampleCollection: CollectionConfig = {
31
33
  name: 'name',
32
34
  type: 'text',
33
35
  // highlight-start
@@ -77,7 +79,7 @@ All field hooks can optionally modify the return value of the field before the o
77
79
 
78
80
  Payload exports a type for field hooks which can be accessed and used as follows:
79
81
 
80
- ```js
82
+ ```ts
81
83
  import type { FieldHook } from 'payload/types';
82
84
 
83
85
  // Field hook type is a generic that takes three arguments:
@@ -19,9 +19,10 @@ Globals feature the ability to define the following hooks:
19
19
  All Global Hook properties accept arrays of synchronous or asynchronous functions. Each Hook type receives specific arguments and has the ability to modify specific outputs.
20
20
 
21
21
  `globals/example-hooks.js`
22
- ```js
23
- // Global config
24
- module.exports = {
22
+ ```ts
23
+ import { GlobalConfig } from 'payload/types';
24
+
25
+ const ExampleHooks: GlobalConfig = {
25
26
  slug: 'header',
26
27
  fields: [
27
28
  { name: 'title', type: 'text'},
@@ -40,8 +41,10 @@ module.exports = {
40
41
 
41
42
  Runs before the `update` operation. This hook allows you to add or format data before the incoming data is validated.
42
43
 
43
- ```js
44
- const beforeValidateHook = async ({
44
+ ```ts
45
+ import { GlobalBeforeValidateHook } from 'payload/types'
46
+
47
+ const beforeValidateHook: GlobalBeforeValidateHook = async ({
45
48
  data, // incoming data to update or create with
46
49
  req, // full express request
47
50
  originalDoc, // original document
@@ -54,8 +57,10 @@ const beforeValidateHook = async ({
54
57
 
55
58
  Immediately following validation, `beforeChange` hooks will run within the `update` operation. At this stage, you can be confident that the data that will be saved to the document is valid in accordance to your field validations. You can optionally modify the shape of data to be saved.
56
59
 
57
- ```js
58
- const beforeChangeHook = async ({
60
+ ```ts
61
+ import { GlobalBeforeChangeHook } from 'payload/types'
62
+
63
+ const beforeChangeHook: GlobalBeforeChangeHook = async ({
59
64
  data, // incoming data to update or create with
60
65
  req, // full express request
61
66
  originalDoc, // original document
@@ -68,8 +73,10 @@ const beforeChangeHook = async ({
68
73
 
69
74
  After a global is updated, the `afterChange` hook runs. Use this hook to purge caches of your applications, sync site data to CRMs, and more.
70
75
 
71
- ```js
72
- const afterChangeHook = async ({
76
+ ```ts
77
+ import { GlobalAfterChangeHook } from 'payload/types'
78
+
79
+ const afterChangeHook: GlobalAfterChangeHook = async ({
73
80
  doc, // full document data
74
81
  req, // full express request
75
82
  }) => {
@@ -81,8 +88,10 @@ const afterChangeHook = async ({
81
88
 
82
89
  Runs before `findOne` global operation is transformed for output by `afterRead`. This hook fires before hidden fields are removed and before localized fields are flattened into the requested locale. Using this Hook will provide you with all locales and all hidden fields via the `doc` argument.
83
90
 
84
- ```js
85
- const beforeReadHook = async ({
91
+ ```ts
92
+ import { GlobalBeforeReadHook } from 'payload/types'
93
+
94
+ const beforeReadHook: GlobalBeforeReadHook = async ({
86
95
  doc, // full document data
87
96
  req, // full express request
88
97
  }) => {...}
@@ -92,8 +101,10 @@ const beforeReadHook = async ({
92
101
 
93
102
  Runs as the last step before a global is returned. Flattens locales, hides protected fields, and removes fields that users do not have access to.
94
103
 
95
- ```js
96
- const afterReadHook = async ({
104
+ ```ts
105
+ import { GlobalAfterReadHook } from 'payload/types'
106
+
107
+ const afterReadHook: GlobalAfterReadHook = async ({
97
108
  doc, // full document data
98
109
  req, // full express request
99
110
  findMany, // boolean to denote if this hook is running against finding one, or finding many (useful in versions)
@@ -104,7 +115,7 @@ const afterReadHook = async ({
104
115
 
105
116
  Payload exports a type for each Global hook which can be accessed as follows:
106
117
 
107
- ```js
118
+ ```ts
108
119
  import type {
109
120
  GlobalBeforeValidateHook,
110
121
  GlobalBeforeChangeHook,
@@ -112,7 +123,4 @@ import type {
112
123
  GlobalBeforeReadHook,
113
124
  GlobalAfterReadHook,
114
125
  } from 'payload/types';
115
-
116
- // Use hook types here...
117
- }
118
126
  ```
@@ -28,10 +28,11 @@ You can gain access to the currently running `payload` object via two ways:
28
28
  You can import or require `payload` into your own files after it's been initialized, but you need to make sure that your `import` / `require` statements come **after** you call `payload.init()`—otherwise Payload won't have been initialized yet. That might be obvious. To us, it's usually not.
29
29
 
30
30
  Example:
31
- ```js
31
+ ```ts
32
32
  import payload from 'payload';
33
+ import { CollectionAfterChangeHook } from 'payload/types';
33
34
 
34
- const afterChangeHook = async () => {
35
+ const afterChangeHook: CollectionAfterChangeHook = async () => {
35
36
  const posts = await payload.find({
36
37
  collection: 'posts',
37
38
  });
@@ -43,8 +44,8 @@ const afterChangeHook = async () => {
43
44
  Payload is available anywhere you have access to the Express `req` - including within your access control and hook functions.
44
45
 
45
46
  Example:
46
- ```js
47
- const afterChangeHook = async ({ req: { payload }}) => {
47
+ ```ts
48
+ const afterChangeHook: CollectionAfterChangeHook = async ({ req: { payload }}) => {
48
49
  const posts = await payload.find({
49
50
  collection: 'posts',
50
51
  });
@@ -319,3 +320,25 @@ const result = await payload.updateGlobal({
319
320
  showHiddenFields: true,
320
321
  })
321
322
  ```
323
+
324
+ ## TypeScript
325
+
326
+ Local API calls also support passing in a generic. This is especially useful if you generate your TS types using a [generate types script](/docs/typescript/generate-types).
327
+
328
+ Here is an example of usage:
329
+
330
+ ```ts
331
+ // Our generated types
332
+ import { Post } from './payload-types'
333
+
334
+ // Add Post types as generic to create function
335
+ const post: Post = await payload.create<Post>({
336
+ collection: 'posts',
337
+
338
+ // Data will now be typed as Post and give you type hints
339
+ data: {
340
+ title: 'my title',
341
+ description: 'my description',
342
+ },
343
+ })
344
+ ```
@@ -83,11 +83,10 @@ After all plugins are executed, the full config with all plugins will be sanitiz
83
83
 
84
84
  Here is an example for how to automatically add a `lastModifiedBy` field to all Payload collections using a Plugin written in TypeScript.
85
85
 
86
- ```js
87
- import { Config } from 'payload/config';
88
- import { CollectionConfig } from 'payload/dist/collections/config/types';
86
+ ```ts
87
+ import { Config, Plugin } from 'payload/config';
89
88
 
90
- const addLastModified = (incomingConfig: Config): Config => {
89
+ const addLastModified: Plugin = (incomingConfig: Config): Config => {
91
90
  // Find all incoming auth-enabled collections
92
91
  // so we can create a lastModifiedBy relationship field
93
92
  // to all auth collections
@@ -37,7 +37,7 @@ Because _**you**_ are in complete control of who can do what with your data, you
37
37
  Before running in Production, you need to have built a production-ready copy of the Payload Admin panel. To do this, Payload provides the `build` NPM script. You can use it by adding a `script` to your `package.json` file like this:
38
38
 
39
39
  `package.json`:
40
- ```js
40
+ ```json
41
41
  {
42
42
  "name": "project-name-here",
43
43
  "scripts": {
@@ -16,8 +16,10 @@ Payload provides an extremely granular querying language through all APIs. Each
16
16
 
17
17
  For example, say you have a collection as follows:
18
18
 
19
- ```js
20
- const Post = {
19
+ ```ts
20
+ import { CollectionConfig } from 'payload/types';
21
+
22
+ const Post: CollectionConfig = {
21
23
  slug: 'posts',
22
24
  fields: [
23
25
  {
@@ -24,7 +24,7 @@ All collection `find` queries are paginated automatically. Responses are returne
24
24
  | nextPage | `number` of next page, `null` if it doesn't exist |
25
25
 
26
26
  **Example response:**
27
- ```js
27
+ ```json
28
28
  {
29
29
  // Document Array // highlight-line
30
30
  "docs": [
@@ -89,9 +89,11 @@ Each endpoint object needs to have:
89
89
 
90
90
  Example:
91
91
 
92
- ```js
92
+ ```ts
93
+ import { CollectionConfig } from 'payload/types';
94
+
93
95
  // a collection of 'orders' with an additional route for tracking details, reachable at /api/orders/:id/tracking
94
- const Orders = {
96
+ const Orders: CollectionConfig = {
95
97
  slug: 'orders',
96
98
  fields: [ /* ... */ ],
97
99
  // highlight-start
@@ -55,38 +55,40 @@ _An asterisk denotes that a property above is required._
55
55
 
56
56
  **Example Upload collection:**
57
57
 
58
- ```js
59
- const Media = {
60
- slug: "media",
58
+ ```ts
59
+ import { CollectionConfig } from 'payload/types';
60
+
61
+ const Media: CollectionConfig = {
62
+ slug: 'media',
61
63
  upload: {
62
- staticURL: "/media",
63
- staticDir: "media",
64
+ staticURL: '/media',
65
+ staticDir: 'media',
64
66
  imageSizes: [
65
67
  {
66
- name: "thumbnail",
68
+ name: 'thumbnail',
67
69
  width: 400,
68
70
  height: 300,
69
- crop: "centre",
71
+ crop: 'centre',
70
72
  },
71
73
  {
72
- name: "card",
74
+ name: 'card',
73
75
  width: 768,
74
76
  height: 1024,
75
- crop: "centre",
77
+ crop: 'centre',
76
78
  },
77
79
  {
78
- name: "tablet",
80
+ name: 'tablet',
79
81
  width: 1024,
80
82
  // By specifying `null` or leaving a height undefined,
81
83
  // the image will be sized to a certain width,
82
84
  // but it will retain its original aspect ratio
83
85
  // and calculate a height automatically.
84
86
  height: null,
85
- crop: "centre",
87
+ crop: 'centre',
86
88
  },
87
89
  ],
88
- adminThumbnail: "thumbnail",
89
- mimeTypes: ["image/*"],
90
+ adminThumbnail: 'thumbnail',
91
+ mimeTypes: ['image/*'],
90
92
  },
91
93
  };
92
94
  ```
@@ -97,17 +99,17 @@ Payload relies on the [`express-fileupload`](https://www.npmjs.com/package/expre
97
99
 
98
100
  A common example of what you might want to customize within Payload-wide Upload options would be to increase the allowed `fileSize` of uploads sent to Payload:
99
101
 
100
- ```js
101
- import { buildConfig } from "payload/config";
102
+ ```ts
103
+ import { buildConfig } from 'payload/config';
102
104
 
103
105
  export default buildConfig({
104
106
  collections: [
105
107
  {
106
- slug: "media",
108
+ slug: 'media',
107
109
  fields: [
108
110
  {
109
- name: "alt",
110
- type: "text",
111
+ name: 'alt',
112
+ type: 'text',
111
113
  },
112
114
  ],
113
115
  upload: true,
@@ -158,12 +160,14 @@ You can specify how Payload retrieves admin thumbnails for your upload-enabled C
158
160
 
159
161
  **Example custom Admin thumbnail:**
160
162
 
161
- ```js
162
- const Media = {
163
- slug: "media",
163
+ ```ts
164
+ import { CollectionConfig } from 'payload/types';
165
+
166
+ const Media: CollectionConfig = {
167
+ slug: 'media',
164
168
  upload: {
165
- staticURL: "/media",
166
- staticDir: "media",
169
+ staticURL: '/media',
170
+ staticDir: 'media',
167
171
  imageSizes: [
168
172
  // ... image sizes here
169
173
  ],
@@ -191,13 +195,15 @@ Some example values are: `image/*`, `audio/*`, `video/*`, `image/png`, `applicat
191
195
 
192
196
  **Example mimeTypes usage:**
193
197
 
194
- ```js
195
- const Media = {
196
- slug: "media",
198
+ ```ts
199
+ import { CollectionConfig } from 'payload/types';
200
+
201
+ const Media: CollectionConfig = {
202
+ slug: 'media',
197
203
  upload: {
198
- staticURL: "/media",
199
- staticDir: "media",
200
- mimeTypes: ["image/*", "application/pdf"], // highlight-line
204
+ staticURL: '/media',
205
+ staticDir: 'media',
206
+ mimeTypes: ['image/*', 'application/pdf'], // highlight-line
201
207
  },
202
208
  };
203
209
  ```
@@ -25,8 +25,10 @@ Collections and Globals both support the same options for configuring autosave.
25
25
 
26
26
  **Example config with versions, drafts, and autosave enabled:**
27
27
 
28
- ```js
29
- const Pages = {
28
+ ```ts
29
+ import { CollectionConfig } from 'payload/types';
30
+
31
+ const Pages: CollectionConfig = {
30
32
  slug: 'pages',
31
33
  access: {
32
34
  read: ({ req }) => {
@@ -81,8 +81,10 @@ You can use the `read` [Access Control](/docs/access-control/collections#read) m
81
81
 
82
82
  Here is an example that utilizes the `_status` field to require a user to be logged in to retrieve drafts:
83
83
 
84
- ```js
85
- const Pages = {
84
+ ```ts
85
+ import { CollectionConfig } from 'payload/types';
86
+
87
+ const Pages: CollectionConfig = {
86
88
  slug: 'pages',
87
89
  access: {
88
90
  read: ({ req }) => {
@@ -114,8 +116,10 @@ const Pages = {
114
116
 
115
117
  Here is an example for how to write an access control function that grants access to both documents where `_status` is equal to "published" and where `_status` does not exist:
116
118
 
117
- ```js
118
- const Pages = {
119
+ ```ts
120
+ import { CollectionConfig } from 'payload/types';
121
+
122
+ const Pages: CollectionConfig = {
119
123
  slug: 'pages',
120
124
  access: {
121
125
  read: ({ req }) => {
@@ -77,7 +77,7 @@ _slug_versions
77
77
 
78
78
  Each document in this new `versions` collection will store a set of meta properties about the version as well as a _full_ copy of the document. For example, a version's data might look like this for a Collection document:
79
79
 
80
- ```js
80
+ ```json
81
81
  {
82
82
  "_id": "61cf752c19cdf1b1af7b61f1", // a unique ID of this version
83
83
  "parent": "61ce1354091d5b3ffc20ea6e", // the ID of the parent document
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Node, React and MongoDB Headless CMS and Application Framework",
5
5
  "license": "MIT",
6
6
  "author": {