Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,16 @@ Introducing new Parse Errors requires the following steps:
Introducing new [Parse Server configuration][config] parameters requires the following steps:

1. Add parameters definitions in [/src/Options/index.js][config-index].
1. If a nested configuration object has been added, add the environment variable option prefix to `getENVPrefix` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js).
1. Execute `npm run definitions` to automatically create the definitions in [/src/Options/Definitions.js][config-def] and [/src/Options/docs.js][config-docs].
1. Add parameter value validation in [/src/Config.js](https://github.com/parse-community/parse-server/blob/master/src/Config.js).
1. Add test cases to ensure the correct parameter value validation. Parse Server throws an error at launch if an invalid value is set for any configuration parameter.
1. Execute `npm run docs` to generate the documentation in the `/out` directory. Take a look at the documentation whether the description and formatting of the newly introduced parameters is satisfactory.
2. If the new parameter does not have one single value but is a parameter group (an object containing multiple sub-parameters):
- add the environment variable prefix for the parameter group to `nestedOptionEnvPrefix` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js)
- add the parameter group type to `nestedOptionTypes` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js)

For example, take a look at the existing Parse Server `security` parameter. It is a parameter group, because it has multiple sub-parameter such as `checkGroups`. Its interface is defined in [index.js][config-index] as `export interface SecurityOptions`. Therefore, the value to add to `nestedOptionTypes` would be `SecurityOptions`, the value to add to `nestedOptionEnvPrefix` would be `PARSE_SERVER_SECURITY_`.

3. Execute `npm run definitions` to automatically create the definitions in [/src/Options/Definitions.js][config-def] and [/src/Options/docs.js][config-docs].
Copy link
Member

@dplewis dplewis Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter group / group type / nested parameters sounds confusing. I think we should make the user aware of the /resources/buildConfigDefinition.js file. Like if you need to add definition types add them to buildConfigDefinition.js

I want to add a new type NumberOrObject, which file should I use?

Copy link
Member Author

@mtrezza mtrezza Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter group / group type / nested parameters sounds confusing.

Yes, I struggled myself to find a proper term. A new config parameter only needs to be added to buildConfigDefinition.js if it is a new interface type, otherwise the file doesn't have to be touched. By new interface I mean a parameter that is actually an object that holds sub-parameters, like PagesOptions. What term do you suggest?

I want to add a new type NumberOrObject, which file should I use?

Good question, I think no change required in buildConfigDefinition.js, because it can also be a number, therefore not sure how this would be handled. This may not be a guide that covers all cases, but the reason I added this paragraph some months ago was that contributors often did incorrectly implement new parameters, most often leaving out the buildConfigDefinition.js file. I don't think a simple "if you need to add definition types add them to buildConfigDefinition.js" will cut it.

Copy link
Member

@dplewis dplewis Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, when I first documented the definitions, I assumed the buildConfigDefinition.js would rarely get updated (4 people have touched it in 4 years, I being the second).

@davimacedo Since you haven't touched the buildConfigDefinition.js do you have any suggestions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can automate the 2 things that sometimes need to get updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

Copy link
Member Author

@mtrezza mtrezza Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dplewis I reworded this with an example of an existing parameter. That should make it easier to follow. If you have any wording suggestions, please let know, otherwise we just go ahead and leave this up for improvement in the future. It's an improvement over status quo anyway.

4. Add parameter value validation in [/src/Config.js](https://github.com/parse-community/parse-server/blob/master/src/Config.js).
5. Add test cases to ensure the correct parameter value validation. Parse Server throws an error at launch if an invalid value is set for any configuration parameter.
6. Execute `npm run docs` to generate the documentation in the `/out` directory. Take a look at the documentation whether the description and formatting of the newly introduced parameters is satisfactory.

## Code of Conduct

Expand Down
54 changes: 35 additions & 19 deletions resources/buildConfigDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@
*/
const parsers = require('../src/Options/parsers');

/** The types of nested options. */
const nestedOptionTypes = [
'CustomPagesOptions',
'DatabaseOptions',
'FileUploadOptions',
'IdempotencyOptions',
'Object',
'PagesCustomUrlsOptions',
'PagesOptions',
'PagesRoute',
'PasswordPolicyOptions',
'SecurityOptions',
];

/** The prefix of environment variables for nested options. */
const nestedOptionEnvPrefix = {
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
'DatabaseOptions': 'PARSE_SERVER_DATABASE_',
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
'PagesCustomUrlsOptions' : 'PARSE_SERVER_PAGES_CUSTOM_URL_',
'PagesOptions' : 'PARSE_SERVER_PAGES_',
'PagesRoute': 'PARSE_SERVER_PAGES_ROUTE_',
'ParseServerOptions' : 'PARSE_SERVER_',
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
};

function last(array) {
return array[array.length - 1];
}
Expand Down Expand Up @@ -40,23 +71,8 @@ function getCommentValue(comment) {
}

function getENVPrefix(iface) {
const options = {
'ParseServerOptions' : 'PARSE_SERVER_',
'PagesOptions' : 'PARSE_SERVER_PAGES_',
'PagesRoute': 'PARSE_SERVER_PAGES_ROUTE_',
'PagesCustomUrlsOptions' : 'PARSE_SERVER_PAGES_CUSTOM_URL_',
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
'DatabaseOptions': 'PARSE_SERVER_DATABASE_'
}
if (options[iface.id.name]) {
return options[iface.id.name]
if (nestedOptionEnvPrefix[iface.id.name]) {
return nestedOptionEnvPrefix[iface.id.name]
}
}

Expand Down Expand Up @@ -169,8 +185,8 @@ function parseDefaultValue(elt, value, t) {
if (type == 'NumberOrBoolean') {
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
}
const literalTypes = ['Object', 'SecurityOptions', 'PagesRoute', 'IdempotencyOptions','FileUploadOptions','CustomPagesOptions', 'PagesCustomUrlsOptions', 'PagesOptions', 'DatabaseOptions'];
if (literalTypes.includes(type)) {

if (nestedOptionTypes.includes(type)) {
const object = parsers.objectParser(value);
const props = Object.keys(object).map((key) => {
return t.objectProperty(key, object[value]);
Expand Down