mirror of
https://github.com/parse-community/parse-server
synced 2026-08-09 13:03:18 +00:00
fix: NumberOrBoolean config option (cluster) value not coerced from env/CLI (#10531)
This commit is contained in:
@@ -177,7 +177,7 @@ function mapperFor(elt, t) {
|
|||||||
return wrap(t.identifier('moduleOrObjectParser'));
|
return wrap(t.identifier('moduleOrObjectParser'));
|
||||||
}
|
}
|
||||||
if (type == 'NumberOrBoolean') {
|
if (type == 'NumberOrBoolean') {
|
||||||
return wrap(t.identifier('numberOrBooleanParser'));
|
return t.callExpression(wrap(t.identifier('numberOrBoolParser')), [t.stringLiteral(elt.name)]);
|
||||||
}
|
}
|
||||||
if (type == 'NumberOrString') {
|
if (type == 'NumberOrString') {
|
||||||
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]);
|
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]);
|
||||||
|
|||||||
+10
-2
@@ -178,7 +178,7 @@ describe('definitions', () => {
|
|||||||
if (typeof definition.required !== 'undefined') {
|
if (typeof definition.required !== 'undefined') {
|
||||||
expect(typeof definition.required).toBe('boolean');
|
expect(typeof definition.required).toBe('boolean');
|
||||||
}
|
}
|
||||||
if (typeof definition.action !== 'undefined') {
|
if ('action' in definition) {
|
||||||
expect(typeof definition.action).toBe('function');
|
expect(typeof definition.action).toBe('function');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,6 +189,14 @@ describe('definitions', () => {
|
|||||||
definitions.facebookAppIds.action();
|
definitions.facebookAppIds.action();
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should coerce the NumberOrBoolean cluster option value', () => {
|
||||||
|
const action = definitions.cluster.action;
|
||||||
|
expect(typeof action).toBe('function');
|
||||||
|
expect(action('2')).toBe(2);
|
||||||
|
expect(action('true')).toBe(true);
|
||||||
|
expect(action('false')).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('LiveQuery definitions', () => {
|
describe('LiveQuery definitions', () => {
|
||||||
@@ -203,7 +211,7 @@ describe('LiveQuery definitions', () => {
|
|||||||
if (typeof definition.required !== 'undefined') {
|
if (typeof definition.required !== 'undefined') {
|
||||||
expect(typeof definition.required).toBe('boolean');
|
expect(typeof definition.required).toBe('boolean');
|
||||||
}
|
}
|
||||||
if (typeof definition.action !== 'undefined') {
|
if ('action' in definition) {
|
||||||
expect(typeof definition.action).toBe('function');
|
expect(typeof definition.action).toBe('function');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,10 @@ describe('buildConfigDefinitions', () => {
|
|||||||
expect(result.property.name).toBe('moduleOrObjectParser');
|
expect(result.property.name).toBe('moduleOrObjectParser');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return numberOrBooleanParser for NumberOrBoolean GenericTypeAnnotation', () => {
|
it('should return numberOrBoolParser call expression for NumberOrBoolean GenericTypeAnnotation', () => {
|
||||||
const mockElement = {
|
const mockElement = {
|
||||||
type: 'GenericTypeAnnotation',
|
type: 'GenericTypeAnnotation',
|
||||||
|
name: 'cluster',
|
||||||
typeAnnotation: {
|
typeAnnotation: {
|
||||||
id: {
|
id: {
|
||||||
name: 'NumberOrBoolean',
|
name: 'NumberOrBoolean',
|
||||||
@@ -93,9 +94,9 @@ describe('buildConfigDefinitions', () => {
|
|||||||
|
|
||||||
const result = mapperFor(mockElement, t);
|
const result = mapperFor(mockElement, t);
|
||||||
|
|
||||||
expect(t.isMemberExpression(result)).toBe(true);
|
expect(t.isCallExpression(result)).toBe(true);
|
||||||
expect(result.object.name).toBe('parsers');
|
expect(result.callee.property.name).toBe('numberOrBoolParser');
|
||||||
expect(result.property.name).toBe('numberOrBooleanParser');
|
expect(result.arguments[0].value).toBe('cluster');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return numberOrStringParser call expression for NumberOrString GenericTypeAnnotation', () => {
|
it('should return numberOrStringParser call expression for NumberOrString GenericTypeAnnotation', () => {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ module.exports.ParseServerOptions = {
|
|||||||
cluster: {
|
cluster: {
|
||||||
env: 'PARSE_SERVER_CLUSTER',
|
env: 'PARSE_SERVER_CLUSTER',
|
||||||
help: 'Run with cluster, optionally set the number of processes default to os.cpus().length',
|
help: 'Run with cluster, optionally set the number of processes default to os.cpus().length',
|
||||||
action: parsers.numberOrBooleanParser,
|
action: parsers.numberOrBoolParser('cluster'),
|
||||||
},
|
},
|
||||||
collectionPrefix: {
|
collectionPrefix: {
|
||||||
env: 'PARSE_SERVER_COLLECTION_PREFIX',
|
env: 'PARSE_SERVER_COLLECTION_PREFIX',
|
||||||
|
|||||||
Reference in New Issue
Block a user