Skip to content

Commit 0319cee

Browse files
authored
fix: Parse Server option maxLogFiles doesn't recognize day duration literals such as 1d to mean 1 day (#9215)
1 parent 901cff5 commit 0319cee

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Diff for: resources/buildConfigDefinitions.js

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ function mapperFor(elt, t) {
161161
if (type == 'NumberOrBoolean') {
162162
return wrap(t.identifier('numberOrBooleanParser'));
163163
}
164+
if (type == 'NumberOrString') {
165+
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]);
166+
}
164167
if (type === 'StringOrStringArray') {
165168
return wrap(t.identifier('arrayParser'));
166169
}
@@ -212,6 +215,9 @@ function parseDefaultValue(elt, value, t) {
212215
if (type == 'NumberOrBoolean') {
213216
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
214217
}
218+
if (type == 'NumberOrString') {
219+
literalValue = t.numericLiteral(parsers.numberOrStringParser('')(value));
220+
}
215221

216222
if (nestedOptionTypes.includes(type)) {
217223
const object = parsers.objectParser(value);

Diff for: spec/parsers.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const {
22
numberParser,
33
numberOrBoolParser,
4+
numberOrStringParser,
45
booleanParser,
56
objectParser,
67
arrayParser,
@@ -18,6 +19,15 @@ describe('parsers', () => {
1819
}).toThrow();
1920
});
2021

22+
it('parses correctly with numberOrStringParser', () => {
23+
const parser = numberOrStringParser('key');
24+
expect(parser('100d')).toEqual('100d');
25+
expect(parser(100)).toEqual(100);
26+
expect(() => {
27+
parser(undefined);
28+
}).toThrow();
29+
});
30+
2131
it('parses correctly with numberOrBoolParser', () => {
2232
const parser = numberOrBoolParser('key');
2333
expect(parser(true)).toEqual(true);

Diff for: src/Options/Definitions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ module.exports.ParseServerOptions = {
378378
env: 'PARSE_SERVER_MAX_LOG_FILES',
379379
help:
380380
"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)",
381-
action: parsers.objectParser,
381+
action: parsers.numberOrStringParser('maxLogFiles'),
382382
},
383383
maxUploadSize: {
384384
env: 'PARSE_SERVER_MAX_UPLOAD_SIZE',

Diff for: src/Options/parsers.js

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function numberOrBoolParser(key) {
2323
};
2424
}
2525

26+
function numberOrStringParser(key) {
27+
return function (opt) {
28+
if (typeof opt === 'string') {
29+
return opt;
30+
}
31+
return numberParser(key)(opt);
32+
};
33+
}
34+
2635
function objectParser(opt) {
2736
if (typeof opt == 'object') {
2837
return opt;
@@ -69,6 +78,7 @@ function nullParser(opt) {
6978
module.exports = {
7079
numberParser,
7180
numberOrBoolParser,
81+
numberOrStringParser,
7282
nullParser,
7383
booleanParser,
7484
moduleOrObjectParser,

0 commit comments

Comments
 (0)