feat: Add option schemaCacheTtl for schema cache pulling as alternative to enableSchemaHooks (#8436)
This commit is contained in:
@@ -9,6 +9,7 @@ import DatabaseController from './Controllers/DatabaseController';
|
||||
import { logLevels as validLogLevels } from './Controllers/LoggerController';
|
||||
import {
|
||||
AccountLockoutOptions,
|
||||
DatabaseOptions,
|
||||
FileUploadOptions,
|
||||
IdempotencyOptions,
|
||||
LogLevels,
|
||||
@@ -52,23 +53,20 @@ export class Config {
|
||||
}
|
||||
|
||||
static put(serverConfiguration) {
|
||||
Config.validate(serverConfiguration);
|
||||
Config.validateOptions(serverConfiguration);
|
||||
Config.validateControllers(serverConfiguration);
|
||||
AppCache.put(serverConfiguration.appId, serverConfiguration);
|
||||
Config.setupPasswordValidator(serverConfiguration.passwordPolicy);
|
||||
return serverConfiguration;
|
||||
}
|
||||
|
||||
static validate({
|
||||
verifyUserEmails,
|
||||
userController,
|
||||
appName,
|
||||
static validateOptions({
|
||||
publicServerURL,
|
||||
revokeSessionOnPasswordReset,
|
||||
expireInactiveSessions,
|
||||
sessionLength,
|
||||
defaultLimit,
|
||||
maxLimit,
|
||||
emailVerifyTokenValidityDuration,
|
||||
accountLockout,
|
||||
passwordPolicy,
|
||||
masterKeyIps,
|
||||
@@ -78,7 +76,6 @@ export class Config {
|
||||
readOnlyMasterKey,
|
||||
allowHeaders,
|
||||
idempotencyOptions,
|
||||
emailVerifyTokenReuseIfValid,
|
||||
fileUpload,
|
||||
pages,
|
||||
security,
|
||||
@@ -88,6 +85,7 @@ export class Config {
|
||||
allowExpiredAuthDataToken,
|
||||
logLevels,
|
||||
rateLimit,
|
||||
databaseOptions,
|
||||
}) {
|
||||
if (masterKey === readOnlyMasterKey) {
|
||||
throw new Error('masterKey and readOnlyMasterKey should be different');
|
||||
@@ -97,17 +95,6 @@ export class Config {
|
||||
throw new Error('masterKey and maintenanceKey should be different');
|
||||
}
|
||||
|
||||
const emailAdapter = userController.adapter;
|
||||
if (verifyUserEmails) {
|
||||
this.validateEmailConfiguration({
|
||||
emailAdapter,
|
||||
appName,
|
||||
publicServerURL,
|
||||
emailVerifyTokenValidityDuration,
|
||||
emailVerifyTokenReuseIfValid,
|
||||
});
|
||||
}
|
||||
|
||||
this.validateAccountLockoutPolicy(accountLockout);
|
||||
this.validatePasswordPolicy(passwordPolicy);
|
||||
this.validateFileUploadOptions(fileUpload);
|
||||
@@ -136,6 +123,27 @@ export class Config {
|
||||
this.validateRequestKeywordDenylist(requestKeywordDenylist);
|
||||
this.validateRateLimit(rateLimit);
|
||||
this.validateLogLevels(logLevels);
|
||||
this.validateDatabaseOptions(databaseOptions);
|
||||
}
|
||||
|
||||
static validateControllers({
|
||||
verifyUserEmails,
|
||||
userController,
|
||||
appName,
|
||||
publicServerURL,
|
||||
emailVerifyTokenValidityDuration,
|
||||
emailVerifyTokenReuseIfValid,
|
||||
}) {
|
||||
const emailAdapter = userController.adapter;
|
||||
if (verifyUserEmails) {
|
||||
this.validateEmailConfiguration({
|
||||
emailAdapter,
|
||||
appName,
|
||||
publicServerURL,
|
||||
emailVerifyTokenValidityDuration,
|
||||
emailVerifyTokenReuseIfValid,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static validateRequestKeywordDenylist(requestKeywordDenylist) {
|
||||
@@ -533,6 +541,25 @@ export class Config {
|
||||
}
|
||||
}
|
||||
|
||||
static validateDatabaseOptions(databaseOptions) {
|
||||
if (databaseOptions == undefined) {
|
||||
return;
|
||||
}
|
||||
if (Object.prototype.toString.call(databaseOptions) !== '[object Object]') {
|
||||
throw `databaseOptions must be an object`;
|
||||
}
|
||||
if (databaseOptions.enableSchemaHooks === undefined) {
|
||||
databaseOptions.enableSchemaHooks = DatabaseOptions.enableSchemaHooks.default;
|
||||
} else if (typeof databaseOptions.enableSchemaHooks !== 'boolean') {
|
||||
throw `databaseOptions.enableSchemaHooks must be a boolean`;
|
||||
}
|
||||
if (databaseOptions.schemaCacheTtl === undefined) {
|
||||
databaseOptions.schemaCacheTtl = DatabaseOptions.schemaCacheTtl.default;
|
||||
} else if (typeof databaseOptions.schemaCacheTtl !== 'number') {
|
||||
throw `databaseOptions.schemaCacheTtl must be a number`;
|
||||
}
|
||||
}
|
||||
|
||||
static validateRateLimit(rateLimit) {
|
||||
if (!rateLimit) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user