payload 0.15.1 → 0.15.4

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 (115) hide show
  1. package/.eslintrc.js +6 -0
  2. package/CHANGELOG.md +35 -0
  3. package/dist/admin/components/elements/WhereBuilder/field-types.d.ts +2 -2
  4. package/dist/admin/components/elements/WhereBuilder/field-types.js +11 -7
  5. package/dist/admin/components/elements/elements.spec.d.ts +1 -0
  6. package/dist/admin/components/elements/elements.spec.js +12 -0
  7. package/dist/admin/components/forms/DraggableSection/index.js +2 -3
  8. package/dist/admin/components/forms/Form/buildStateFromSchema.d.ts +10 -1
  9. package/dist/admin/components/forms/Form/buildStateFromSchema.js +14 -6
  10. package/dist/admin/components/forms/Form/getDataByPath.js +6 -11
  11. package/dist/admin/components/forms/Form/getSiblingData.js +12 -14
  12. package/dist/admin/components/forms/Form/index.js +23 -6
  13. package/dist/admin/components/forms/Form/reduceFieldsToValues.d.ts +1 -1
  14. package/dist/admin/components/forms/Form/reduceFieldsToValues.js +1 -2
  15. package/dist/admin/components/forms/Form/types.d.ts +3 -2
  16. package/dist/admin/components/forms/RenderFields/index.d.ts +1 -2
  17. package/dist/admin/components/forms/RenderFields/index.js +6 -16
  18. package/dist/admin/components/forms/RenderFields/types.d.ts +0 -5
  19. package/dist/admin/components/forms/field-types/Array/Array.js +18 -9
  20. package/dist/admin/components/forms/field-types/Blocks/Blocks.js +21 -15
  21. package/dist/admin/components/forms/field-types/Checkbox/index.js +3 -4
  22. package/dist/admin/components/forms/field-types/Code/Code.js +4 -5
  23. package/dist/admin/components/forms/field-types/DateTime/index.js +2 -3
  24. package/dist/admin/components/forms/field-types/Email/index.js +2 -3
  25. package/dist/admin/components/forms/field-types/Number/index.js +3 -4
  26. package/dist/admin/components/forms/field-types/Password/index.js +2 -2
  27. package/dist/admin/components/forms/field-types/Point/index.js +2 -3
  28. package/dist/admin/components/forms/field-types/RadioGroup/index.js +3 -4
  29. package/dist/admin/components/forms/field-types/Relationship/index.js +49 -17
  30. package/dist/admin/components/forms/field-types/RichText/RichText.js +3 -4
  31. package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.js +4 -2
  32. package/dist/admin/components/forms/field-types/Row/index.js +7 -2
  33. package/dist/admin/components/forms/field-types/Select/index.js +4 -5
  34. package/dist/admin/components/forms/field-types/Text/index.js +6 -3
  35. package/dist/admin/components/forms/field-types/Textarea/index.js +4 -5
  36. package/dist/admin/components/forms/field-types/Upload/Add/index.js +1 -1
  37. package/dist/admin/components/forms/field-types/Upload/Input.d.ts +2 -1
  38. package/dist/admin/components/forms/field-types/Upload/Input.js +3 -1
  39. package/dist/admin/components/forms/field-types/Upload/SelectExisting/index.js +27 -4
  40. package/dist/admin/components/forms/field-types/Upload/SelectExisting/types.d.ts +3 -0
  41. package/dist/admin/components/forms/field-types/Upload/index.js +4 -5
  42. package/dist/admin/components/forms/field-types/getFilterOptionsQuery.d.ts +5 -0
  43. package/dist/admin/components/forms/field-types/getFilterOptionsQuery.js +11 -0
  44. package/dist/admin/components/forms/useField/index.js +39 -8
  45. package/dist/admin/components/utilities/OperationProvider/index.d.ts +4 -0
  46. package/dist/admin/components/utilities/OperationProvider/index.js +3 -0
  47. package/dist/admin/components/views/Account/Default.js +41 -39
  48. package/dist/admin/components/views/Account/index.js +4 -2
  49. package/dist/admin/components/views/CreateFirstUser/index.js +1 -1
  50. package/dist/admin/components/views/Global/Default.js +45 -43
  51. package/dist/admin/components/views/Global/index.js +5 -5
  52. package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +1 -1
  53. package/dist/admin/components/views/collections/Edit/Default.js +55 -53
  54. package/dist/admin/components/views/collections/Edit/index.js +5 -5
  55. package/dist/auth/auth.spec.d.ts +1 -0
  56. package/dist/auth/auth.spec.js +198 -0
  57. package/dist/collections/graphql/resolvers/resolvers.spec.d.ts +1 -0
  58. package/dist/collections/graphql/resolvers/resolvers.spec.js +360 -0
  59. package/dist/collections/operations/local/local.spec.d.ts +1 -0
  60. package/dist/collections/operations/local/local.spec.js +175 -0
  61. package/dist/collections/tests/collections.spec.d.ts +1 -0
  62. package/dist/collections/tests/collections.spec.js +725 -0
  63. package/dist/collections/tests/hooks.spec.d.ts +1 -0
  64. package/dist/collections/tests/hooks.spec.js +152 -0
  65. package/dist/collections/tests/pointField.spec.d.ts +1 -0
  66. package/dist/collections/tests/pointField.spec.js +219 -0
  67. package/dist/collections/tests/relationships.spec.d.ts +1 -0
  68. package/dist/collections/tests/relationships.spec.js +194 -0
  69. package/dist/collections/tests/uploads.spec.d.ts +1 -0
  70. package/dist/collections/tests/uploads.spec.js +328 -0
  71. package/dist/config/load.d.ts +3 -1
  72. package/dist/config/load.js +5 -3
  73. package/dist/config/types.d.ts +3 -0
  74. package/dist/config/types.js +1 -1
  75. package/dist/config/validate.d.ts +2 -1
  76. package/dist/config/validate.js +2 -4
  77. package/dist/email/build.d.ts +2 -1
  78. package/dist/email/build.js +7 -9
  79. package/dist/errors/errors.spec.d.ts +1 -0
  80. package/dist/errors/errors.spec.js +29 -0
  81. package/dist/express/middleware/errorHandler.spec.d.ts +1 -0
  82. package/dist/express/middleware/errorHandler.spec.js +91 -0
  83. package/dist/fields/config/sanitize.js +2 -2
  84. package/dist/fields/config/schema.js +3 -1
  85. package/dist/fields/config/types.d.ts +25 -1
  86. package/dist/fields/config/types.js +1 -1
  87. package/dist/fields/performFieldOperations.js +3 -3
  88. package/dist/fields/traverseFields.js +15 -5
  89. package/dist/fields/validationPromise.d.ts +10 -3
  90. package/dist/fields/validationPromise.js +16 -5
  91. package/dist/fields/validations.d.ts +33 -35
  92. package/dist/fields/validations.js +130 -76
  93. package/dist/fields/validations.spec.js +115 -43
  94. package/dist/globals/requestHandlers/globals.spec.d.ts +4 -0
  95. package/dist/globals/requestHandlers/globals.spec.js +161 -0
  96. package/dist/graphql/schema/buildMutationInputType.js +2 -2
  97. package/dist/graphql/schema/fieldToSchemaMap.js +7 -7
  98. package/dist/index.d.ts +2 -2
  99. package/dist/index.js +5 -5
  100. package/dist/mongoose/buildQuery.js +2 -2
  101. package/dist/mongoose/connect.d.ts +2 -1
  102. package/dist/mongoose/connect.js +2 -4
  103. package/dist/mongoose/sanitizeFormattedValue.js +12 -3
  104. package/dist/preferences/graphql/resolvers.spec.d.ts +1 -0
  105. package/dist/preferences/graphql/resolvers.spec.js +115 -0
  106. package/dist/utilities/logger.d.ts +1 -1
  107. package/dist/utilities/logger.js +10 -6
  108. package/dist/versions/drafts/appendVersionToQueryKey.js +8 -5
  109. package/dist/webpack/getBaseConfig.js +2 -1
  110. package/docs/fields/overview.mdx +39 -3
  111. package/docs/fields/relationship.mdx +45 -0
  112. package/docs/fields/upload.mdx +1 -0
  113. package/docs/getting-started/installation.mdx +14 -10
  114. package/docs/queries/overview.mdx +2 -1
  115. package/package.json +1 -1
@@ -22,6 +22,7 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma
22
22
  | ---------------- | ----------- |
23
23
  | **`name`** * | To be used as the property name when stored and retrieved from the database. |
24
24
  | **`relationTo`** * | Provide one or many collection `slug`s to be able to assign relationships to. |
25
+ | **`filterOptions`** | A query to filter which options appear in the UI and validate against. [More](#filtering-relationship-options). |
25
26
  | **`hasMany`** | Boolean when, if set to `true`, allows this field to have many relations instead of only one. |
26
27
  | **`maxDepth`** | Sets a number limit on iterations of related documents to populate when queried. [Depth](/docs/getting-started/concepts#depth) |
27
28
  | **`label`** | Used as a field label in the Admin panel and to name the generated GraphQL type. |
@@ -44,6 +45,50 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma
44
45
  The <a href="/docs/getting-started/concepts#depth">Depth</a> parameter can be used to automatically populate related documents that are returned by the API.
45
46
  </Banner>
46
47
 
48
+ ### Filtering relationship options
49
+
50
+ Options can be dynamically limited by supplying a [query constraint](/docs/queries/overview), which will be used both for validating input and filtering available relationships in the UI.
51
+
52
+ The `filterOptions` property can either be a `Where` query directly, or a function that returns one. When using a function, it will be called with an argument object with the following properties:
53
+
54
+ | Property | Description |
55
+ | ------------- | -------------|
56
+ | `relationTo` | The `relationTo` to filter against (as defined on the field) |
57
+ | `data` | An object of the full collection or global document currently being edited |
58
+ | `siblingData` | An object of the document data limited to fields within the same parent to the field |
59
+ | `id` | The value of the collection `id`, will be `undefined` on create request |
60
+ | `user` | The currently authenticated user object |
61
+
62
+ **Example:**
63
+
64
+ ```js
65
+ const relationshipField = {
66
+ name: 'purchase',
67
+ type: 'relationship',
68
+ relationTo: ['products', 'services'],
69
+ filterOptions: ({ relationTo, siblingData }) => {
70
+ // returns a Where query dynamically by the type of relationship
71
+ if (relationTo === 'products') {
72
+ return {
73
+ 'stock': { is_greater_than: siblingData.quantity }
74
+ }
75
+ }
76
+
77
+ if (relationTo === 'services') {
78
+ return {
79
+ 'isAvailable': { equals: true }
80
+ }
81
+ }
82
+ },
83
+ };
84
+ ```
85
+
86
+ You can learn more about writing queries [here](/docs/queries/overview).
87
+
88
+ <Banner type="warning">
89
+ When a relationship field has both <strong>filterOptions</strong> and a custom <strong>validate</strong> function, the server-side validation will not enforce <strong>filterOptions</strong>unless you call the default relationship field validation function imported from <strong>payload/fields/validations</strong> within your custom function.
90
+ </Banner>
91
+
47
92
  ### How the data is saved
48
93
 
49
94
  Given the variety of options possible within the `relationship` field type, the shape of the data needed for creating and updating these fields can vary. The following sections will describe the variety of data shapes that can arise from this field.
@@ -27,6 +27,7 @@ keywords: upload, images media, fields, config, configuration, documentation, Co
27
27
  | ---------------- | ----------- |
28
28
  | **`name`** * | To be used as the property name when stored and retrieved from the database. |
29
29
  | **`*relationTo`** * | Provide a single collection `slug` to allow this field to accept a relation to. <strong>Note: the related collection must be configured to support Uploads.</strong> |
30
+ | **`filterOptions`** | A query to filter which options appear in the UI and validate against. [More](#filtering-relationship-options). |
30
31
  | **`maxDepth`** | Sets a number limit on iterations of related documents to populate when queried. [Depth](/docs/getting-started/concepts#depth) |
31
32
  | **`label`** | Used as a field label in the Admin panel and to name the generated GraphQL type. |
32
33
  | **`unique`** | Enforce that each entry in the Collection has a unique value for this field. |
@@ -88,15 +88,19 @@ app.listen(3000, async () => {
88
88
 
89
89
  ```
90
90
 
91
- As you can see above, the required arguments to the `init` function are as follows:
91
+ Here is a list of all properties available to pass through `payload.init`:
92
+
93
+ ##### `express`
94
+
95
+ **Required**. This is your Express app as shown above. Payload will tie into your existing `app` and scope all of its functionalities to sub-routers. By default, Payload will add an `/admin` router and an `/api` router, but you can customize these paths.
92
96
 
93
97
  ##### `secret`
94
98
 
95
- This is a secure string that will be used to authenticate with Payload. It can be random but should be at least 14 characters and be very difficult to guess. Often, it's smart to store this value in an `env` and set different values for each of your environments (local, stage, prod, etc). The `dotenv` package is very handy and works well alongside of Payload.
99
+ **Required**. This is a secure string that will be used to authenticate with Payload. It can be random but should be at least 14 characters and be very difficult to guess. Often, it's smart to store this value in an `env` and set different values for each of your environments (local, stage, prod, etc). The `dotenv` package is very handy and works well alongside of Payload.
96
100
 
97
101
  ##### `mongoURL`
98
102
 
99
- This is a fully qualified MongoDB connection string that points to your Mongo database. If you don't have Mongo installed locally, you can [follow these steps for Mac OSX](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/) and [these steps](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/) for Windows 10. If you want to use a local database and you know you have MongoDB installed locally, a typical connection string will look like this:
103
+ **Required**. This is a fully qualified MongoDB connection string that points to your Mongo database. If you don't have Mongo installed locally, you can [follow these steps for Mac OSX](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/) and [these steps](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/) for Windows 10. If you want to use a local database and you know you have MongoDB installed locally, a typical connection string will look like this:
100
104
 
101
105
  `mongodb://localhost/payload`
102
106
 
@@ -104,11 +108,7 @@ In contrast to running Mongo locally, a popular option is to sign up for a free
104
108
 
105
109
  ##### `mongoOptions`
106
110
 
107
- An optional object to customize connection options. Payload will connect to your MongoDB database using default options which you can override and extend to include all the [options](https://mongoosejs.com/docs/connections.html#options) available to mongoose.
108
-
109
- ##### `express`
110
-
111
- This is your Express app as shown above. Payload will tie into your existing `app` and scope all of its functionalities to sub-routers. By default, Payload will add an `/admin` router and an `/api` router, but you can customize these paths.
111
+ Customize Mongo connection options. Payload will connect to your MongoDB database using default options which you can override and extend to include all the [options](https://mongoosejs.com/docs/connections.html#options) available to mongoose.
112
112
 
113
113
  ##### `license`
114
114
 
@@ -116,15 +116,19 @@ Your Payload license key. Not needed for development purposes, but when it's tim
116
116
 
117
117
  ##### `email`
118
118
 
119
- An Optional object used to configure SMTP. [Read more](/docs/email/overview).
119
+ An object used to configure SMTP. [Read more](/docs/email/overview).
120
120
 
121
121
  ##### `local`
122
122
 
123
123
  A boolean that when set to `true` tells Payload to start in local-only mode which will bypass setting up API routes. When set to `true`, `express` is not required. This is useful when running scripts that need to use Payload's [local-api](/docs/local-api/overview).
124
124
 
125
+ ##### `loggerOptions`
126
+
127
+ Specify options for the built-in Pino logger that Payload uses for internal logging. See [Pino Docs](https://getpino.io/#/docs/api?id=options) for more info on what is available.
128
+
125
129
  ##### `onInit`
126
130
 
127
- An optional function that is called immediately following startup that receives the Payload instance as it's only argument.
131
+ A function that is called immediately following startup that receives the Payload instance as it's only argument.
128
132
 
129
133
  ### Test it out
130
134
 
@@ -59,7 +59,8 @@ The above example demonstrates a simple query but you can get much more complex.
59
59
  | `greater_than_equal` | For numeric or date-based fields. |
60
60
  | `less_than` | For numeric or date-based fields. |
61
61
  | `less_than_equal` | For numeric or date-based fields. |
62
- | `like` | The value must partially match. |
62
+ | `like` | Case-insensitive string must be present. If string of words, all words must be present, in any order. |
63
+ | `contains` | Must contain the value entered, case-insensitive. |
63
64
  | `in` | The value must be found within the provided comma-delimited list of values. |
64
65
  | `not_in` | The value must NOT be within the provided comma-delimited list of values. |
65
66
  | `exists` | Only return documents where the value either exists (`true`) or does not exist (`false`). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "0.15.1",
3
+ "version": "0.15.4",
4
4
  "description": "Node, React and MongoDB Headless CMS and Application Framework",
5
5
  "license": "SEE LICENSE IN license.md",
6
6
  "author": {