payload 0.12.12-beta.0 → 0.13.2

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 (87) hide show
  1. package/CHANGELOG.md +18 -56
  2. package/components/forms.ts +2 -1
  3. package/components/index.js +2 -2
  4. package/dist/admin/components/elements/SearchFilter/index.js +6 -3
  5. package/dist/admin/components/elements/WhereBuilder/Condition/Relationship/types.d.ts +1 -1
  6. package/dist/admin/components/forms/DraggableSection/SectionTitle/index.js +2 -2
  7. package/dist/admin/components/forms/field-types/Array/Array.js +2 -2
  8. package/dist/admin/components/forms/field-types/Blocks/Blocks.js +2 -2
  9. package/dist/admin/components/forms/field-types/Checkbox/index.js +2 -2
  10. package/dist/admin/components/forms/field-types/Code/Code.js +2 -2
  11. package/dist/admin/components/forms/field-types/ConfirmPassword/index.js +2 -2
  12. package/dist/admin/components/forms/field-types/DateTime/index.js +2 -2
  13. package/dist/admin/components/forms/field-types/Email/index.js +2 -2
  14. package/dist/admin/components/forms/field-types/HiddenInput/index.js +2 -2
  15. package/dist/admin/components/forms/field-types/Number/index.js +2 -2
  16. package/dist/admin/components/forms/field-types/Password/index.js +2 -2
  17. package/dist/admin/components/forms/field-types/Point/index.js +2 -2
  18. package/dist/admin/components/forms/field-types/RadioGroup/index.js +2 -2
  19. package/dist/admin/components/forms/field-types/Relationship/index.js +2 -2
  20. package/dist/admin/components/forms/field-types/Relationship/types.d.ts +1 -1
  21. package/dist/admin/components/forms/field-types/RichText/RichText.js +2 -2
  22. package/dist/admin/components/forms/field-types/Select/index.js +32 -16
  23. package/dist/admin/components/forms/field-types/Text/index.js +19 -6
  24. package/dist/admin/components/forms/field-types/Textarea/index.js +2 -2
  25. package/dist/admin/components/forms/field-types/Upload/index.js +21 -8
  26. package/dist/admin/components/forms/useField/index.d.ts +3 -0
  27. package/dist/admin/components/forms/{useFieldType → useField}/index.js +30 -9
  28. package/dist/admin/components/forms/{useFieldType → useField}/types.d.ts +0 -0
  29. package/dist/admin/components/forms/{useFieldType → useField}/types.js +0 -0
  30. package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +2 -2
  31. package/dist/admin/components/views/collections/Edit/Upload/index.js +2 -2
  32. package/dist/admin/components/views/collections/List/types.d.ts +1 -1
  33. package/dist/auth/getExecuteStaticAccess.d.ts +1 -1
  34. package/dist/auth/getExecuteStaticAccess.js +20 -4
  35. package/dist/bin/generateTypes.js +5 -1
  36. package/dist/collections/config/types.d.ts +102 -39
  37. package/dist/collections/operations/create.d.ts +1 -0
  38. package/dist/collections/operations/create.js +12 -4
  39. package/dist/collections/operations/delete.js +6 -5
  40. package/dist/collections/operations/find.d.ts +2 -2
  41. package/dist/collections/operations/find.js +13 -11
  42. package/dist/collections/operations/findByID.d.ts +2 -3
  43. package/dist/collections/operations/findByID.js +1 -1
  44. package/dist/collections/operations/local/create.d.ts +1 -0
  45. package/dist/collections/operations/local/create.js +3 -2
  46. package/dist/collections/operations/local/delete.d.ts +2 -1
  47. package/dist/collections/operations/local/delete.js +1 -1
  48. package/dist/collections/operations/local/find.d.ts +2 -2
  49. package/dist/collections/operations/local/find.js +1 -1
  50. package/dist/collections/operations/local/findByID.d.ts +2 -1
  51. package/dist/collections/operations/local/findByID.js +1 -1
  52. package/dist/collections/operations/local/update.d.ts +2 -1
  53. package/dist/collections/operations/local/update.js +1 -1
  54. package/dist/collections/operations/update.js +11 -3
  55. package/dist/collections/requestHandlers/find.d.ts +2 -2
  56. package/dist/collections/requestHandlers/find.js +1 -1
  57. package/dist/config/types.d.ts +3 -0
  58. package/dist/express/static.js +2 -2
  59. package/dist/fields/baseFields/getBaseUploadFields.js +2 -1
  60. package/dist/fields/config/types.d.ts +20 -15
  61. package/dist/fields/config/types.js +1 -1
  62. package/dist/fields/validations.d.ts +17 -17
  63. package/dist/index.d.ts +8 -9
  64. package/dist/index.js +1 -1
  65. package/dist/mongoose/buildQuery.js +6 -2
  66. package/dist/uploads/docWithFilenameExists.d.ts +3 -0
  67. package/dist/uploads/docWithFilenameExists.js +10 -0
  68. package/dist/uploads/fileExists.d.ts +2 -2
  69. package/dist/uploads/fileExists.js +4 -3
  70. package/dist/uploads/getSafeFilename.d.ts +2 -1
  71. package/dist/uploads/getSafeFilename.js +4 -3
  72. package/dist/uploads/imageResizer.d.ts +11 -1
  73. package/dist/uploads/imageResizer.js +2 -2
  74. package/dist/utilities/sanitizeInternalFields.d.ts +2 -1
  75. package/dist/utilities/sanitizeInternalFields.js +1 -1
  76. package/docs/admin/components.mdx +3 -3
  77. package/docs/fields/blocks.mdx +9 -0
  78. package/docs/fields/overview.mdx +12 -0
  79. package/docs/fields/rich-text.mdx +11 -0
  80. package/docs/hooks/collections.mdx +23 -0
  81. package/docs/hooks/fields.mdx +28 -0
  82. package/docs/hooks/globals.mdx +17 -0
  83. package/docs/typescript/generating-types.mdx +114 -0
  84. package/docs/typescript/overview.mdx +36 -0
  85. package/package.json +1 -1
  86. package/types.d.ts +18 -2
  87. package/dist/admin/components/forms/useFieldType/index.d.ts +0 -3
@@ -17,4 +17,4 @@ const sanitizeInternalFields = (incomingDoc) => Object.entries(incomingDoc).redu
17
17
  };
18
18
  }, {});
19
19
  exports.default = sanitizeInternalFields;
20
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2FuaXRpemVJbnRlcm5hbEZpZWxkcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvc2FuaXRpemVJbnRlcm5hbEZpZWxkcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLE1BQU0sY0FBYyxHQUFHLENBQUMsS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQztBQUUvQyxNQUFNLHNCQUFzQixHQUFHLENBQUMsV0FBVyxFQUFFLEVBQUUsQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDL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QUcsTUFBTTtZQUNULEVBQUUsRUFBRSxHQUFHO1NBQ1IsQ0FBQztLQUNIO0lBRUQsSUFBSSxjQUFjLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFO1FBQ3BDLE9BQU8sTUFBTSxDQUFDO0tBQ2Y7SUFFRCxPQUFPO1FBQ0wsR0FBRyxNQUFNO1FBQ1QsQ0FBQyxHQUFHLENBQUMsRUFBRSxHQUFHO0tBQ1gsQ0FBQztBQUNKLENBQUMsRUFBRSxFQUFPLENBQUMsQ0FBQztBQUVaLGtCQUFlLHNCQUFzQixDQUFDIn0=
@@ -90,13 +90,13 @@ All Payload fields support the ability to swap in your own React components. So,
90
90
 
91
91
  #### Sending and receiving values from the form
92
92
 
93
- When swapping out the `Field` component, you'll be responsible for sending and receiving the field's `value` from the form itself. To do so, import the `useFieldType` hook as follows:
93
+ When swapping out the `Field` component, you'll be responsible for sending and receiving the field's `value` from the form itself. To do so, import the `useField` hook as follows:
94
94
 
95
95
  ```js
96
- import { useFieldType } from 'payload/components/forms';
96
+ import { useField } from 'payload/components/forms';
97
97
 
98
98
  const CustomTextField = ({ path }) => {
99
- const { value, setValue } = useFieldType({ path });
99
+ const { value, setValue } = useField({ path });
100
100
 
101
101
  return (
102
102
  <input
@@ -106,3 +106,12 @@ const ExampleCollection = {
106
106
  }
107
107
 
108
108
  ```
109
+
110
+ ### TypeScript
111
+
112
+ As you build your own Block configs, you might want to store them in separate files but retain typing accordingly. To do so, you can import and use Payload's `Block` type:
113
+
114
+ ```js
115
+ import type { Block } from 'payload/types';
116
+
117
+ ```
@@ -239,3 +239,15 @@ This example will display the number of characters allowed as the user types.
239
239
  }
240
240
  ```
241
241
  This component will count the number of characters entered.
242
+
243
+ ### TypeScript
244
+
245
+ You can import the internal Payload `Field` type as well as other common field types as follows:
246
+
247
+ ```js
248
+ import type {
249
+ Field,
250
+ Validate,
251
+ Condition,
252
+ } from 'payload/types';
253
+ ```
@@ -313,3 +313,14 @@ Above, you can see that we are creating a custom SlateJS element with a name of
313
313
 
314
314
  The plugin itself extends Payload's built-in `shouldBreakOutOnEnter` Slate function to add its own element name to the list of elements that should "break out" when the `enter` key is pressed.
315
315
 
316
+ ### TypeScript
317
+
318
+ If you are building your own custom Rich Text elements or leaves, you may benefit from importing the following types:
319
+
320
+ ```js
321
+ import type {
322
+ RichTextCustomElement,
323
+ RichTextCustomLeaf,
324
+ } from 'payload/types';
325
+
326
+ ```
@@ -188,3 +188,26 @@ const afterLoginHook = async ({
188
188
  return user;
189
189
  }
190
190
  ```
191
+
192
+ ## TypeScript
193
+
194
+ Payload exports a type for each Collection hook which can be accessed as follows:
195
+
196
+ ```js
197
+ import type {
198
+ CollectionBeforeOperationHook,
199
+ CollectionBeforeValidateHook,
200
+ CollectionBeforeChangeHook,
201
+ CollectionAfterChangeHook,
202
+ CollectionAfterReadHook,
203
+ CollectionBeforeReadHook,
204
+ CollectionBeforeDeleteHook,
205
+ CollectionAfterDeleteHook,
206
+ CollectionBeforeLoginHook,
207
+ CollectionAfterLoginHook,
208
+ CollectionAfterForgotPasswordHook,
209
+ } from 'payload/types';
210
+
211
+ // Use hook types here...
212
+ }
213
+ ```
@@ -70,3 +70,31 @@ All field hooks can optionally modify the return value of the field before the o
70
70
  <strong>Important</strong><br/>
71
71
  Due to GraphQL's typed nature, you should never change the type of data that you return from a field, otherwise GraphQL will produce errors. If you need to change the shape or type of data, reconsider Field Hooks and instead evaluate if Collection / Global hooks might suit you better.
72
72
  </Banner>
73
+
74
+ ## TypeScript
75
+
76
+ Payload exports a type for field hooks which can be accessed and used as follows:
77
+
78
+ ```js
79
+ import type { FieldHook } from 'payload/types';
80
+
81
+ // Field hook type is a generic that takes two arguments:
82
+ // 1: The document type
83
+ // 2: the value type
84
+
85
+ type ExampleFieldHook = FieldHook<ExampleDocumentType, string>;
86
+
87
+ const exampleFieldHook: ExampleFieldHook = (args) => {
88
+ const {
89
+ value, // Typed as `string` as shown above
90
+ data, // Typed as a Partial of your ExampleDocumentType
91
+ originalDoc, // Typed as ExampleDocumentType
92
+ operation,
93
+ req,
94
+ }
95
+
96
+ // Do something here...
97
+
98
+ return value; // should return a string as typed above, undefined, or null
99
+ }
100
+ ```
@@ -98,3 +98,20 @@ const afterReadHook = async ({
98
98
  req, // full express request
99
99
  }) => {...}
100
100
  ```
101
+
102
+ ## TypeScript
103
+
104
+ Payload exports a type for each Global hook which can be accessed as follows:
105
+
106
+ ```js
107
+ import type {
108
+ GlobalBeforeValidateHook,
109
+ GlobalBeforeChangeHook,
110
+ GlobalAfterChangeHook,
111
+ GlobalBeforeReadHook,
112
+ GlobalAfterReadHook,
113
+ } from 'payload/types';
114
+
115
+ // Use hook types here...
116
+ }
117
+ ```
@@ -0,0 +1,114 @@
1
+ ---
2
+ title: Generating TypeScript Interfaces
3
+ label: Generating Types
4
+ order: 20
5
+ desc: Generate your own TypeScript interfaces based on your collections and globals.
6
+ keywords: headless cms, typescript, documentation, Content Management System, cms, headless, javascript, node, react, express
7
+ ---
8
+
9
+ While building your own custom functionality into Payload, like plugins, hooks, access control functions, custom routes, GraphQL queries / mutations, or anything else, you may benefit from generating your own TypeScript types dynamically from your Payload config itself.
10
+
11
+ Run the following command in a Payload project to generate types:
12
+
13
+ ```
14
+ payload generate:types
15
+ ```
16
+
17
+ You can run this command whenever you need to regenerate your types, and then you can use these types in your Payload code directly.
18
+
19
+ For example, let's look at the following simple Payload config:
20
+
21
+ ```ts
22
+ const config: Config = {
23
+ serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
24
+ admin: {
25
+ user: 'users',
26
+ }
27
+ collections: [
28
+ {
29
+ slug: 'users',
30
+ fields: [
31
+ {
32
+ name: 'name',
33
+ type: 'text',
34
+ required: true,
35
+ }
36
+ ]
37
+ },
38
+ {
39
+ slug: 'posts',
40
+ admin: {
41
+ useAsTitle: 'title',
42
+ },
43
+ fields: [
44
+ {
45
+ name: 'title',
46
+ type: 'text',
47
+ },
48
+ {
49
+ name: 'author',
50
+ type: 'relationship',
51
+ relationTo: 'users',
52
+ },
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ By generating types, we'll end up with a file containing the following two TypeScript interfaces:
60
+
61
+ ```ts
62
+ export interface User {
63
+ id: string;
64
+ name: string;
65
+ email?: string;
66
+ resetPasswordToken?: string;
67
+ resetPasswordExpiration?: string;
68
+ loginAttempts?: number;
69
+ lockUntil?: string;
70
+ }
71
+
72
+ export interface Post {
73
+ id: string;
74
+ title?: string;
75
+ author?: string | User;
76
+ }
77
+
78
+ ```
79
+
80
+ #### Customizing the output path of your generated types
81
+
82
+ You can specify where you want your types to be generated by adding a property to your Payload config:
83
+
84
+ ```
85
+ {
86
+ // the remainder of your config
87
+ typescript: {
88
+ outputFile: path.resolve(__dirname, './generated-types.ts'),
89
+ },
90
+ }
91
+ ```
92
+
93
+ The above example places your types next to your Payload config itself as the file `generated-types.ts`. By default, the file will be output to your current working directory as `payload-types.ts`.
94
+
95
+ #### Adding an NPM script
96
+
97
+ <Banner type="warning">
98
+ <strong>Important:</strong><br/>
99
+ Payload needs to be able to find your config to generate your types.
100
+ </Banner>
101
+
102
+ Payload will automatically try and locate your config, but might not always be able to find it. For example, if you are working in a `/src` directory or similar, you need to tell Payload where to find your config manually by using an environment variable. If this applies to you, you can create an NPM script to make generating your types easier.
103
+
104
+ To add an NPM script to generate your types and show Payload where to find your config, open your `package.json` and update the `scripts` property to the following:
105
+
106
+ ```
107
+ {
108
+ "scripts": {
109
+ "generate:types": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
110
+ },
111
+ }
112
+ ```
113
+
114
+ Now you can run `yarn generate:types` to easily generate your types.
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: TypeScript - Overview
3
+ label: Overview
4
+ order: 10
5
+ desc: Payload is the most powerful TypeScript headless CMS available.
6
+ keywords: headless cms, typescript, documentation, Content Management System, cms, headless, javascript, node, react, express
7
+ ---
8
+
9
+ Payload supports TypeScript natively, and not only that, the entirety of the CMS is built with TypeScript. To get started developing with Payload and TypeScript, you can use one of Payload's built-in boilerplates in one line via `create-payload-app`:
10
+
11
+ ```
12
+ npx create-payload-app
13
+ ```
14
+
15
+ Pick a TypeScript project type to get started easily.
16
+
17
+ #### Setting up from Scratch
18
+
19
+ It's also possible to set up a TypeScript project from scratch. We plan to write up a guide for exactly how—so keep an eye out for that, too.
20
+
21
+ ## Using Payload's Exported Types
22
+
23
+ Payload exports a number of types that you may find useful while writing your own plugins, hooks, access control functions, custom routes, GraphQL queries / mutations, or anything else.
24
+
25
+ ##### Config Types
26
+
27
+ - [Base config](/docs/configuration/overview#typescript)
28
+ - [Collections](/docs/configuration/collections#typescript)
29
+ - [Globals](/docs/configuration/globals#typescript)
30
+ - [Fields](/docs/fields/overview#typescript)
31
+
32
+ ##### Hook Types
33
+
34
+ - [Collection hooks](/docs/hooks/collections#typescript)
35
+ - [Global hooks](/docs/hooks/globals#typescript)
36
+ - [Field hooks](/docs/hooks/fields#typescript)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "0.12.12-beta.0",
3
+ "version": "0.13.2",
4
4
  "description": "Node, React and MongoDB Headless CMS and Application Framework",
5
5
  "license": "SEE LICENSE IN license.md",
6
6
  "author": {
package/types.d.ts CHANGED
@@ -16,5 +16,21 @@ export {
16
16
  AfterForgotPasswordHook as CollectionAfterForgotPasswordHook,
17
17
  } from './dist/collections/config/types';
18
18
 
19
- export { GlobalConfig, SanitizedGlobalConfig } from './dist/globals/config/types';
20
- export { Field, FieldHook, FieldAccess, RichTextCustomElement, RichTextCustomLeaf, Block } from './dist/fields/config/types';
19
+ export {
20
+ GlobalConfig,
21
+ SanitizedGlobalConfig,
22
+ BeforeValidateHook as GlobalBeforeValidateHook,
23
+ BeforeChangeHook as GlobalBeforeChangeHook,
24
+ AfterChangeHook as GlobalAfterChangeHook,
25
+ BeforeReadHook as GlobalBeforeReadHook,
26
+ AfterReadHook as GlobalAfterReadHook,
27
+ } from './dist/globals/config/types';
28
+
29
+ export {
30
+ Field,
31
+ FieldHook,
32
+ FieldAccess,
33
+ RichTextCustomElement,
34
+ RichTextCustomLeaf,
35
+ Block,
36
+ } from './dist/fields/config/types';
@@ -1,3 +0,0 @@
1
- import { Options, FieldType } from './types';
2
- declare const useFieldType: <T extends unknown>(options: Options) => FieldType<T>;
3
- export default useFieldType;