fix: Parse Server option maxLogFiles doesn't recognize day duration literals such as 1d to mean 1 day (#9215)
This commit is contained in:
@@ -161,6 +161,9 @@ function mapperFor(elt, t) {
|
|||||||
if (type == 'NumberOrBoolean') {
|
if (type == 'NumberOrBoolean') {
|
||||||
return wrap(t.identifier('numberOrBooleanParser'));
|
return wrap(t.identifier('numberOrBooleanParser'));
|
||||||
}
|
}
|
||||||
|
if (type == 'NumberOrString') {
|
||||||
|
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]);
|
||||||
|
}
|
||||||
if (type === 'StringOrStringArray') {
|
if (type === 'StringOrStringArray') {
|
||||||
return wrap(t.identifier('arrayParser'));
|
return wrap(t.identifier('arrayParser'));
|
||||||
}
|
}
|
||||||
@@ -212,6 +215,9 @@ function parseDefaultValue(elt, value, t) {
|
|||||||
if (type == 'NumberOrBoolean') {
|
if (type == 'NumberOrBoolean') {
|
||||||
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
|
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
|
||||||
}
|
}
|
||||||
|
if (type == 'NumberOrString') {
|
||||||
|
literalValue = t.numericLiteral(parsers.numberOrStringParser('')(value));
|
||||||
|
}
|
||||||
|
|
||||||
if (nestedOptionTypes.includes(type)) {
|
if (nestedOptionTypes.includes(type)) {
|
||||||
const object = parsers.objectParser(value);
|
const object = parsers.objectParser(value);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const {
|
const {
|
||||||
numberParser,
|
numberParser,
|
||||||
numberOrBoolParser,
|
numberOrBoolParser,
|
||||||
|
numberOrStringParser,
|
||||||
booleanParser,
|
booleanParser,
|
||||||
objectParser,
|
objectParser,
|
||||||
arrayParser,
|
arrayParser,
|
||||||
@@ -18,6 +19,15 @@ describe('parsers', () => {
|
|||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses correctly with numberOrStringParser', () => {
|
||||||
|
const parser = numberOrStringParser('key');
|
||||||
|
expect(parser('100d')).toEqual('100d');
|
||||||
|
expect(parser(100)).toEqual(100);
|
||||||
|
expect(() => {
|
||||||
|
parser(undefined);
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
it('parses correctly with numberOrBoolParser', () => {
|
it('parses correctly with numberOrBoolParser', () => {
|
||||||
const parser = numberOrBoolParser('key');
|
const parser = numberOrBoolParser('key');
|
||||||
expect(parser(true)).toEqual(true);
|
expect(parser(true)).toEqual(true);
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ module.exports.ParseServerOptions = {
|
|||||||
env: 'PARSE_SERVER_MAX_LOG_FILES',
|
env: 'PARSE_SERVER_MAX_LOG_FILES',
|
||||||
help:
|
help:
|
||||||
"Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)",
|
"Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)",
|
||||||
action: parsers.objectParser,
|
action: parsers.numberOrStringParser('maxLogFiles'),
|
||||||
},
|
},
|
||||||
maxUploadSize: {
|
maxUploadSize: {
|
||||||
env: 'PARSE_SERVER_MAX_UPLOAD_SIZE',
|
env: 'PARSE_SERVER_MAX_UPLOAD_SIZE',
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ function numberOrBoolParser(key) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function numberOrStringParser(key) {
|
||||||
|
return function (opt) {
|
||||||
|
if (typeof opt === 'string') {
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
return numberParser(key)(opt);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function objectParser(opt) {
|
function objectParser(opt) {
|
||||||
if (typeof opt == 'object') {
|
if (typeof opt == 'object') {
|
||||||
return opt;
|
return opt;
|
||||||
@@ -69,6 +78,7 @@ function nullParser(opt) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
numberParser,
|
numberParser,
|
||||||
numberOrBoolParser,
|
numberOrBoolParser,
|
||||||
|
numberOrStringParser,
|
||||||
nullParser,
|
nullParser,
|
||||||
booleanParser,
|
booleanParser,
|
||||||
moduleOrObjectParser,
|
moduleOrObjectParser,
|
||||||
|
|||||||
Reference in New Issue
Block a user