MCPcopy Index your code
hub / github.com/parse-community/parse-server / injectDefaults

Function injectDefaults

src/ParseServer.ts:593–675  ·  view source on GitHub ↗
(options: ParseServerOptions)

Source from the content-addressed store, hash-verified

591}
592
593function injectDefaults(options: ParseServerOptions) {
594 Object.keys(defaults).forEach(key => {
595 if (!Object.prototype.hasOwnProperty.call(options, key)) {
596 options[key] = defaults[key];
597 }
598 });
599
600 // Inject defaults for database options; only when no explicit database adapter is set,
601 // because an explicit adapter manages its own options and passing databaseOptions alongside
602 // it would cause a conflict error in getDatabaseController.
603 if (!options.databaseAdapter) {
604 if (options.databaseOptions == null) {
605 options.databaseOptions = {};
606 }
607 if (typeof options.databaseOptions === 'object' && !Array.isArray(options.databaseOptions)) {
608 Object.keys(DatabaseOptionDefaults).forEach(key => {
609 if (!Object.prototype.hasOwnProperty.call(options.databaseOptions, key)) {
610 options.databaseOptions[key] = DatabaseOptionDefaults[key];
611 }
612 });
613 }
614 }
615
616 if (!Object.prototype.hasOwnProperty.call(options, 'serverURL')) {
617 options.serverURL = `http://localhost:${options.port}${options.mountPath}`;
618 }
619
620 // Reserved Characters
621 if (options.appId) {
622 const regex = /[!#$%'()*+&/:;=?@[\]{}^,|<>]/g;
623 if (options.appId.match(regex)) {
624 // eslint-disable-next-line no-console
625 console.warn(
626 `\nWARNING, appId that contains special characters can cause issues while using with urls.\n`
627 );
628 }
629 }
630
631 // Backwards compatibility
632 if (options.userSensitiveFields) {
633 /* eslint-disable no-console */
634 !process.env.TESTING &&
635 console.warn(
636 `\nDEPRECATED: userSensitiveFields has been replaced by protectedFields allowing the ability to protect fields in all classes with CLP. \n`
637 );
638 /* eslint-enable no-console */
639
640 const userSensitiveFields = Array.from(
641 new Set([...(defaults.userSensitiveFields || []), ...(options.userSensitiveFields || [])])
642 );
643
644 // If the options.protectedFields is unset,
645 // it'll be assigned the default above.
646 // Here, protect against the case where protectedFields
647 // is set, but doesn't have _User.
648 if (!('_User' in options.protectedFields)) {
649 options.protectedFields = Object.assign({ _User: [] }, options.protectedFields);
650 }

Callers 1

constructorMethod · 0.85

Calls 2

matchMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected