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.
- package/.eslintrc.js +6 -0
- package/CHANGELOG.md +35 -0
- package/dist/admin/components/elements/WhereBuilder/field-types.d.ts +2 -2
- package/dist/admin/components/elements/WhereBuilder/field-types.js +11 -7
- package/dist/admin/components/elements/elements.spec.d.ts +1 -0
- package/dist/admin/components/elements/elements.spec.js +12 -0
- package/dist/admin/components/forms/DraggableSection/index.js +2 -3
- package/dist/admin/components/forms/Form/buildStateFromSchema.d.ts +10 -1
- package/dist/admin/components/forms/Form/buildStateFromSchema.js +14 -6
- package/dist/admin/components/forms/Form/getDataByPath.js +6 -11
- package/dist/admin/components/forms/Form/getSiblingData.js +12 -14
- package/dist/admin/components/forms/Form/index.js +23 -6
- package/dist/admin/components/forms/Form/reduceFieldsToValues.d.ts +1 -1
- package/dist/admin/components/forms/Form/reduceFieldsToValues.js +1 -2
- package/dist/admin/components/forms/Form/types.d.ts +3 -2
- package/dist/admin/components/forms/RenderFields/index.d.ts +1 -2
- package/dist/admin/components/forms/RenderFields/index.js +6 -16
- package/dist/admin/components/forms/RenderFields/types.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Array/Array.js +18 -9
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +21 -15
- package/dist/admin/components/forms/field-types/Checkbox/index.js +3 -4
- package/dist/admin/components/forms/field-types/Code/Code.js +4 -5
- package/dist/admin/components/forms/field-types/DateTime/index.js +2 -3
- package/dist/admin/components/forms/field-types/Email/index.js +2 -3
- package/dist/admin/components/forms/field-types/Number/index.js +3 -4
- package/dist/admin/components/forms/field-types/Password/index.js +2 -2
- package/dist/admin/components/forms/field-types/Point/index.js +2 -3
- package/dist/admin/components/forms/field-types/RadioGroup/index.js +3 -4
- package/dist/admin/components/forms/field-types/Relationship/index.js +49 -17
- package/dist/admin/components/forms/field-types/RichText/RichText.js +3 -4
- package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.js +4 -2
- package/dist/admin/components/forms/field-types/Row/index.js +7 -2
- package/dist/admin/components/forms/field-types/Select/index.js +4 -5
- package/dist/admin/components/forms/field-types/Text/index.js +6 -3
- package/dist/admin/components/forms/field-types/Textarea/index.js +4 -5
- package/dist/admin/components/forms/field-types/Upload/Add/index.js +1 -1
- package/dist/admin/components/forms/field-types/Upload/Input.d.ts +2 -1
- package/dist/admin/components/forms/field-types/Upload/Input.js +3 -1
- package/dist/admin/components/forms/field-types/Upload/SelectExisting/index.js +27 -4
- package/dist/admin/components/forms/field-types/Upload/SelectExisting/types.d.ts +3 -0
- package/dist/admin/components/forms/field-types/Upload/index.js +4 -5
- package/dist/admin/components/forms/field-types/getFilterOptionsQuery.d.ts +5 -0
- package/dist/admin/components/forms/field-types/getFilterOptionsQuery.js +11 -0
- package/dist/admin/components/forms/useField/index.js +39 -8
- package/dist/admin/components/utilities/OperationProvider/index.d.ts +4 -0
- package/dist/admin/components/utilities/OperationProvider/index.js +3 -0
- package/dist/admin/components/views/Account/Default.js +41 -39
- package/dist/admin/components/views/Account/index.js +4 -2
- package/dist/admin/components/views/CreateFirstUser/index.js +1 -1
- package/dist/admin/components/views/Global/Default.js +45 -43
- package/dist/admin/components/views/Global/index.js +5 -5
- package/dist/admin/components/views/collections/Edit/Auth/APIKey.js +1 -1
- package/dist/admin/components/views/collections/Edit/Default.js +55 -53
- package/dist/admin/components/views/collections/Edit/index.js +5 -5
- package/dist/auth/auth.spec.d.ts +1 -0
- package/dist/auth/auth.spec.js +198 -0
- package/dist/collections/graphql/resolvers/resolvers.spec.d.ts +1 -0
- package/dist/collections/graphql/resolvers/resolvers.spec.js +360 -0
- package/dist/collections/operations/local/local.spec.d.ts +1 -0
- package/dist/collections/operations/local/local.spec.js +175 -0
- package/dist/collections/tests/collections.spec.d.ts +1 -0
- package/dist/collections/tests/collections.spec.js +725 -0
- package/dist/collections/tests/hooks.spec.d.ts +1 -0
- package/dist/collections/tests/hooks.spec.js +152 -0
- package/dist/collections/tests/pointField.spec.d.ts +1 -0
- package/dist/collections/tests/pointField.spec.js +219 -0
- package/dist/collections/tests/relationships.spec.d.ts +1 -0
- package/dist/collections/tests/relationships.spec.js +194 -0
- package/dist/collections/tests/uploads.spec.d.ts +1 -0
- package/dist/collections/tests/uploads.spec.js +328 -0
- package/dist/config/load.d.ts +3 -1
- package/dist/config/load.js +5 -3
- package/dist/config/types.d.ts +3 -0
- package/dist/config/types.js +1 -1
- package/dist/config/validate.d.ts +2 -1
- package/dist/config/validate.js +2 -4
- package/dist/email/build.d.ts +2 -1
- package/dist/email/build.js +7 -9
- package/dist/errors/errors.spec.d.ts +1 -0
- package/dist/errors/errors.spec.js +29 -0
- package/dist/express/middleware/errorHandler.spec.d.ts +1 -0
- package/dist/express/middleware/errorHandler.spec.js +91 -0
- package/dist/fields/config/sanitize.js +2 -2
- package/dist/fields/config/schema.js +3 -1
- package/dist/fields/config/types.d.ts +25 -1
- package/dist/fields/config/types.js +1 -1
- package/dist/fields/performFieldOperations.js +3 -3
- package/dist/fields/traverseFields.js +15 -5
- package/dist/fields/validationPromise.d.ts +10 -3
- package/dist/fields/validationPromise.js +16 -5
- package/dist/fields/validations.d.ts +33 -35
- package/dist/fields/validations.js +130 -76
- package/dist/fields/validations.spec.js +115 -43
- package/dist/globals/requestHandlers/globals.spec.d.ts +4 -0
- package/dist/globals/requestHandlers/globals.spec.js +161 -0
- package/dist/graphql/schema/buildMutationInputType.js +2 -2
- package/dist/graphql/schema/fieldToSchemaMap.js +7 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/mongoose/buildQuery.js +2 -2
- package/dist/mongoose/connect.d.ts +2 -1
- package/dist/mongoose/connect.js +2 -4
- package/dist/mongoose/sanitizeFormattedValue.js +12 -3
- package/dist/preferences/graphql/resolvers.spec.d.ts +1 -0
- package/dist/preferences/graphql/resolvers.spec.js +115 -0
- package/dist/utilities/logger.d.ts +1 -1
- package/dist/utilities/logger.js +10 -6
- package/dist/versions/drafts/appendVersionToQueryKey.js +8 -5
- package/dist/webpack/getBaseConfig.js +2 -1
- package/docs/fields/overview.mdx +39 -3
- package/docs/fields/relationship.mdx +45 -0
- package/docs/fields/upload.mdx +1 -0
- package/docs/getting-started/installation.mdx +14 -10
- package/docs/queries/overview.mdx +2 -1
- 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.
|
package/docs/fields/upload.mdx
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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` |
|
|
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`). |
|