Skip to content

Commit 2b0957c

Browse files
authored
refactor: add missing schema definitions (#7917)
1 parent d74b6a3 commit 2b0957c

File tree

5 files changed

+116
-69
lines changed

5 files changed

+116
-69
lines changed

Diff for: resources/buildConfigDefinitions.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ const nestedOptionTypes = [
2323
'PagesRoute',
2424
'PasswordPolicyOptions',
2525
'SecurityOptions',
26+
'SchemaOptions',
2627
];
2728

2829
/** The prefix of environment variables for nested options. */
2930
const nestedOptionEnvPrefix = {
30-
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
31-
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
31+
'AccountLockoutOptions': 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
32+
'CustomPagesOptions': 'PARSE_SERVER_CUSTOM_PAGES_',
3233
'DatabaseOptions': 'PARSE_SERVER_DATABASE_',
33-
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
34-
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
35-
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
36-
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
37-
'PagesCustomUrlsOptions' : 'PARSE_SERVER_PAGES_CUSTOM_URL_',
38-
'PagesOptions' : 'PARSE_SERVER_PAGES_',
34+
'FileUploadOptions': 'PARSE_SERVER_FILE_UPLOAD_',
35+
'IdempotencyOptions': 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
36+
'LiveQueryOptions': 'PARSE_SERVER_LIVEQUERY_',
37+
'LiveQueryServerOptions': 'PARSE_LIVE_QUERY_SERVER_',
38+
'PagesCustomUrlsOptions': 'PARSE_SERVER_PAGES_CUSTOM_URL_',
39+
'PagesOptions': 'PARSE_SERVER_PAGES_',
3940
'PagesRoute': 'PARSE_SERVER_PAGES_ROUTE_',
40-
'ParseServerOptions' : 'PARSE_SERVER_',
41-
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
41+
'ParseServerOptions': 'PARSE_SERVER_',
42+
'PasswordPolicyOptions': 'PARSE_SERVER_PASSWORD_POLICY_',
4243
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
44+
'SchemaOptions': 'PARSE_SERVER_SCHEMA_',
4345
};
4446

4547
function last(array) {
@@ -50,7 +52,7 @@ const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5052
function toENV(key) {
5153
let str = '';
5254
let previousIsUpper = false;
53-
for(let i = 0; i < key.length; i++) {
55+
for (let i = 0; i < key.length; i++) {
5456
const char = key[i];
5557
if (letters.indexOf(char) >= 0) {
5658
if (!previousIsUpper) {
@@ -273,8 +275,8 @@ function inject(t, list) {
273275
return { results, comments };
274276
}
275277

276-
const makeRequire = function(variableName, module, t) {
277-
const decl = t.variableDeclarator(t.identifier(variableName), t.callExpression(t.identifier('require'), [t.stringLiteral(module)]));
278+
const makeRequire = function (variableName, module, t) {
279+
const decl = t.variableDeclarator(t.identifier(variableName), t.callExpression(t.identifier('require'), [t.stringLiteral(module)]));
278280
return t.variableDeclaration('var', [decl])
279281
}
280282
let docs = ``;
@@ -283,14 +285,14 @@ const plugin = function (babel) {
283285
const moduleExports = t.memberExpression(t.identifier('module'), t.identifier('exports'));
284286
return {
285287
visitor: {
286-
ImportDeclaration: function(path) {
288+
ImportDeclaration: function (path) {
287289
path.remove();
288290
},
289-
Program: function(path) {
291+
Program: function (path) {
290292
// Inject the parser's loader
291293
path.unshiftContainer('body', makeRequire('parsers', './parsers', t));
292294
},
293-
ExportDeclaration: function(path) {
295+
ExportDeclaration: function (path) {
294296
// Export declaration on an interface
295297
if (path.node && path.node.declaration && path.node.declaration.type == 'InterfaceDeclaration') {
296298
const { results, comments } = inject(t, doInterface(path.node.declaration));
@@ -313,6 +315,6 @@ Do not edit manually, but update Options/index.js
313315
`
314316

315317
const babel = require("@babel/core");
316-
const res = babel.transformFileSync('./src/Options/index.js', { plugins: [ plugin, '@babel/transform-flow-strip-types' ], babelrc: false, auxiliaryCommentBefore, sourceMaps: false });
318+
const res = babel.transformFileSync('./src/Options/index.js', { plugins: [plugin, '@babel/transform-flow-strip-types'], babelrc: false, auxiliaryCommentBefore, sourceMaps: false });
317319
require('fs').writeFileSync('./src/Options/Definitions.js', res.code + '\n');
318320
require('fs').writeFileSync('./src/Options/docs.js', docs);

Diff for: src/Options/Definitions.js

+50-39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,51 @@ Do not edit manually, but update Options/index.js
55
*/
66
var parsers = require('./parsers');
77

8+
module.exports.SchemaOptions = {
9+
afterMigration: {
10+
env: 'PARSE_SERVER_SCHEMA_AFTER_MIGRATION',
11+
help: 'Execute a callback after running schema migrations.',
12+
},
13+
beforeMigration: {
14+
env: 'PARSE_SERVER_SCHEMA_BEFORE_MIGRATION',
15+
help: 'Execute a callback before running schema migrations.',
16+
},
17+
definitions: {
18+
env: 'PARSE_SERVER_SCHEMA_DEFINITIONS',
19+
help:
20+
'Rest representation on Parse.Schema https://docs.parseplatform.org/rest/guide/#adding-a-schema',
21+
required: true,
22+
action: parsers.objectParser,
23+
default: [],
24+
},
25+
deleteExtraFields: {
26+
env: 'PARSE_SERVER_SCHEMA_DELETE_EXTRA_FIELDS',
27+
help:
28+
'Is true if Parse Server should delete any fields not defined in a schema definition. This should only be used during development.',
29+
action: parsers.booleanParser,
30+
default: false,
31+
},
32+
lockSchemas: {
33+
env: 'PARSE_SERVER_SCHEMA_LOCK_SCHEMAS',
34+
help:
35+
'Is true if Parse Server will reject any attempts to modify the schema while the server is running.',
36+
action: parsers.booleanParser,
37+
default: false,
38+
},
39+
recreateModifiedFields: {
40+
env: 'PARSE_SERVER_SCHEMA_RECREATE_MODIFIED_FIELDS',
41+
help:
42+
'Is true if Parse Server should recreate any fields that are different between the current database schema and theschema definition. This should only be used during development.',
43+
action: parsers.booleanParser,
44+
default: false,
45+
},
46+
strict: {
47+
env: 'PARSE_SERVER_SCHEMA_STRICT',
48+
help: 'Is true if Parse Server should exit if schema update fail.',
49+
action: parsers.booleanParser,
50+
default: false,
51+
},
52+
};
853
module.exports.ParseServerOptions = {
954
accountLockout: {
1055
env: 'PARSE_SERVER_ACCOUNT_LOCKOUT',
@@ -385,6 +430,11 @@ module.exports.ParseServerOptions = {
385430
action: parsers.booleanParser,
386431
default: false,
387432
},
433+
schema: {
434+
env: 'PARSE_SERVER_SCHEMA',
435+
help: 'Defined schema',
436+
action: parsers.objectParser,
437+
},
388438
security: {
389439
env: 'PARSE_SERVER_SECURITY',
390440
help: 'The security options to identify and report weak security settings.',
@@ -464,45 +514,6 @@ module.exports.SecurityOptions = {
464514
default: false,
465515
},
466516
};
467-
module.exports.SchemaOptions = {
468-
definitions: {
469-
help: 'The schema definitions.',
470-
default: [],
471-
},
472-
strict: {
473-
env: 'PARSE_SERVER_SCHEMA_STRICT',
474-
help: 'Is true if Parse Server should exit if schema update fail.',
475-
action: parsers.booleanParser,
476-
default: true,
477-
},
478-
deleteExtraFields: {
479-
env: 'PARSE_SERVER_SCHEMA_DELETE_EXTRA_FIELDS',
480-
help:
481-
'Is true if Parse Server should delete any fields not defined in a schema definition. This should only be used during development.',
482-
action: parsers.booleanParser,
483-
default: false,
484-
},
485-
recreateModifiedFields: {
486-
env: 'PARSE_SERVER_SCHEMA_RECREATE_MODIFIED_FIELDS',
487-
help:
488-
'Is true if Parse Server should recreate any fields that are different between the current database schema and theschema definition. This should only be used during development.',
489-
action: parsers.booleanParser,
490-
default: false,
491-
},
492-
lockSchemas: {
493-
env: 'PARSE_SERVER_SCHEMA_LOCK',
494-
help:
495-
'Is true if Parse Server will reject any attempts to modify the schema while the server is running.',
496-
action: parsers.booleanParser,
497-
default: false,
498-
},
499-
beforeMigration: {
500-
help: 'Execute a callback before running schema migrations.',
501-
},
502-
afterMigration: {
503-
help: 'Execute a callback after running schema migrations.',
504-
},
505-
};
506517
module.exports.PagesOptions = {
507518
customRoutes: {
508519
env: 'PARSE_SERVER_PAGES_CUSTOM_ROUTES',

Diff for: src/Options/docs.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* @interface SchemaOptions
3+
* @property {Function} afterMigration Execute a callback after running schema migrations.
4+
* @property {Function} beforeMigration Execute a callback before running schema migrations.
5+
* @property {Any} definitions Rest representation on Parse.Schema https://docs.parseplatform.org/rest/guide/#adding-a-schema
6+
* @property {Boolean} deleteExtraFields Is true if Parse Server should delete any fields not defined in a schema definition. This should only be used during development.
7+
* @property {Boolean} lockSchemas Is true if Parse Server will reject any attempts to modify the schema while the server is running.
8+
* @property {Boolean} recreateModifiedFields Is true if Parse Server should recreate any fields that are different between the current database schema and theschema definition. This should only be used during development.
9+
* @property {Boolean} strict Is true if Parse Server should exit if schema update fail.
10+
*/
11+
112
/**
213
* @interface ParseServerOptions
314
* @property {AccountLockoutOptions} accountLockout The account lockout policy for failed login attempts.
@@ -68,6 +79,7 @@
6879
* @property {String} restAPIKey Key for REST calls
6980
* @property {Boolean} revokeSessionOnPasswordReset When a user changes their password, either through the reset password email or while logged in, all sessions are revoked if this is true. Set to false if you don't want to revoke sessions.
7081
* @property {Boolean} scheduledPush Configuration for push scheduling, defaults to false.
82+
* @property {SchemaOptions} schema Defined schema
7183
* @property {SecurityOptions} security The security options to identify and report weak security settings.
7284
* @property {Function} serverCloseComplete Callback when server has closed
7385
* @property {Function} serverStartComplete Callback when server has started

Diff for: src/Options/index.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,28 @@ import { MailAdapter } from '../Adapters/Email/MailAdapter';
88
import { PubSubAdapter } from '../Adapters/PubSub/PubSubAdapter';
99
import { WSSAdapter } from '../Adapters/WebSocketServer/WSSAdapter';
1010
import { CheckGroup } from '../Security/CheckGroup';
11-
import type { SchemaOptions } from '../SchemaMigrations/Migrations';
11+
12+
export interface SchemaOptions {
13+
/* Rest representation on Parse.Schema https://docs.parseplatform.org/rest/guide/#adding-a-schema
14+
:DEFAULT: [] */
15+
definitions: any;
16+
/* Is true if Parse Server should exit if schema update fail.
17+
:DEFAULT: false */
18+
strict: ?boolean;
19+
/* Is true if Parse Server should delete any fields not defined in a schema definition. This should only be used during development.
20+
:DEFAULT: false */
21+
deleteExtraFields: ?boolean;
22+
/* Is true if Parse Server should recreate any fields that are different between the current database schema and theschema definition. This should only be used during development.
23+
:DEFAULT: false */
24+
recreateModifiedFields: ?boolean;
25+
/* Is true if Parse Server will reject any attempts to modify the schema while the server is running.
26+
:DEFAULT: false */
27+
lockSchemas: ?boolean;
28+
/* Execute a callback before running schema migrations. */
29+
beforeMigration: ?() => void | Promise<void>;
30+
/* Execute a callback after running schema migrations. */
31+
afterMigration: ?() => void | Promise<void>;
32+
}
1233

1334
type Adapter<T> = string | any | T;
1435
type NumberOrBoolean = number | boolean;
@@ -246,7 +267,9 @@ export interface ParseServerOptions {
246267
playgroundPath: ?string;
247268
/* Callback when server has started */
248269
serverStartComplete: ?(error: ?Error) => void;
249-
/* Rest representation on Parse.Schema https://docs.parseplatform.org/rest/guide/#adding-a-schema */
270+
/* Defined schema
271+
:ENV: PARSE_SERVER_SCHEMA
272+
*/
250273
schema: ?SchemaOptions;
251274
/* Callback when server has closed */
252275
serverCloseComplete: ?() => void;

Diff for: src/SchemaMigrations/Migrations.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @flow
22

3+
export interface SchemaOptions {
4+
definitions: JSONSchema[];
5+
strict: ?boolean;
6+
deleteExtraFields: ?boolean;
7+
recreateModifiedFields: ?boolean;
8+
lockSchemas: ?boolean;
9+
beforeMigration: ?() => void | Promise<void>;
10+
afterMigration: ?() => void | Promise<void>;
11+
}
12+
313
export type FieldValueType =
414
| 'String'
515
| 'Boolean'
@@ -35,17 +45,6 @@ export interface IndexesInterface {
3545
[key: string]: IndexInterface;
3646
}
3747

38-
export interface SchemaOptions {
39-
definitions: JSONSchema[];
40-
strict: ?boolean;
41-
deleteExtraFields: ?boolean;
42-
recreateModifiedFields: ?boolean;
43-
lockSchemas: ?boolean;
44-
/* Callback when server has started and before running schemas migration operations if schemas key provided */
45-
beforeMigration: ?() => void | Promise<void>;
46-
afterMigration: ?() => void | Promise<void>;
47-
}
48-
4948
export type CLPOperation = 'find' | 'count' | 'get' | 'update' | 'create' | 'delete';
5049
// @Typescript 4.1+ // type CLPPermission = 'requiresAuthentication' | '*' | `user:${string}` | `role:${string}`
5150

0 commit comments

Comments
 (0)