@medmain/core
Advanced tools
Comparing version 0.1.25 to 0.1.26
@@ -46,3 +46,3 @@ import get from 'lodash/get'; | ||
if (fieldSchema.type === 'date') { | ||
if (fieldSchema.type === 'date' && value) { | ||
value = new Date(value); | ||
@@ -121,8 +121,2 @@ } | ||
_proto.findExpression = function findExpression(field) { | ||
return this._expressions.find(function (expression) { | ||
return expression.field === field; | ||
}); | ||
}; | ||
_proto.forEachExpression = function forEachExpression(func) { | ||
@@ -152,8 +146,11 @@ return this._expressions.forEach(func); | ||
_proto.getValue = function getValue(field) { | ||
var expression = this.findExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
_proto.getExpression = function getExpression(field) { | ||
return this._expressions.find(function (expression) { | ||
return expression.field === field; | ||
}); | ||
}; | ||
_proto.setValue = function setValue(field, value) { | ||
_proto.setExpression = function setExpression(field, _ref5) { | ||
var operator = _ref5.operator, | ||
value = _ref5.value; | ||
var fieldSchema = this.constructor.getFieldSchema(field); | ||
@@ -165,8 +162,7 @@ | ||
var expression = this.findExpression(field); | ||
var expression = this.getExpression(field); | ||
if (!expression) { | ||
expression = { | ||
field: field, | ||
operator: 'is' | ||
field: field | ||
}; | ||
@@ -177,5 +173,28 @@ | ||
expression.operator = operator; | ||
expression.value = value; | ||
}; | ||
_proto.deleteExpression = function deleteExpression(field) { | ||
var index = this._expressions.findIndex(function (expression) { | ||
return expression.field === field; | ||
}); | ||
if (index !== -1) { | ||
this._expressions.splice(index, 1); | ||
} | ||
}; | ||
_proto.getValue = function getValue(field) { | ||
var expression = this.getExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
}; | ||
_proto.setValue = function setValue(field, value) { | ||
this.setExpression(field, { | ||
operator: 'is', | ||
value: value | ||
}); | ||
}; | ||
_proto.describe = function describe() { | ||
@@ -185,26 +204,22 @@ var expressions = []; | ||
for (var _iterator3 = this._expressions, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref5; | ||
var _ref6; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref5 = _iterator3[_i3++]; | ||
_ref6 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref5 = _i3.value; | ||
_ref6 = _i3.value; | ||
} | ||
var _ref6 = _ref5, | ||
field = _ref6.field, | ||
operator = _ref6.operator, | ||
value = _ref6.value; | ||
var _ref7 = _ref6, | ||
field = _ref7.field, | ||
operator = _ref7.operator, | ||
value = _ref7.value; | ||
field = kebabCase(field); | ||
if (operator !== 'is') { | ||
throw new Error('UNIMPLEMENTED'); | ||
} | ||
if (value instanceof Date) { | ||
value = value.toISOString().slice(0, 10).replace(/-/g, '/'); | ||
} else { | ||
} else if (value !== undefined) { | ||
value = JSON.stringify(value); | ||
@@ -215,2 +230,3 @@ } | ||
field: field, | ||
operator: operator, | ||
value: value | ||
@@ -217,0 +233,0 @@ }); |
@@ -37,3 +37,3 @@ "use strict"; | ||
if (fieldSchema.type === 'date') { | ||
if (fieldSchema.type === 'date' && value) { | ||
value = new Date(value); | ||
@@ -96,6 +96,2 @@ } | ||
findExpression(field) { | ||
return this._expressions.find(expression => expression.field === field); | ||
} | ||
forEachExpression(func) { | ||
@@ -125,8 +121,10 @@ return this._expressions.forEach(func); | ||
getValue(field) { | ||
const expression = this.findExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
getExpression(field) { | ||
return this._expressions.find(expression => expression.field === field); | ||
} | ||
setValue(field, value) { | ||
setExpression(field, { | ||
operator, | ||
value | ||
}) { | ||
const fieldSchema = this.constructor.getFieldSchema(field); | ||
@@ -138,8 +136,7 @@ | ||
let expression = this.findExpression(field); | ||
let expression = this.getExpression(field); | ||
if (!expression) { | ||
expression = { | ||
field, | ||
operator: 'is' | ||
field | ||
}; | ||
@@ -150,5 +147,26 @@ | ||
expression.operator = operator; | ||
expression.value = value; | ||
} | ||
deleteExpression(field) { | ||
const index = this._expressions.findIndex(expression => expression.field === field); | ||
if (index !== -1) { | ||
this._expressions.splice(index, 1); | ||
} | ||
} | ||
getValue(field) { | ||
const expression = this.getExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
} | ||
setValue(field, value) { | ||
this.setExpression(field, { | ||
operator: 'is', | ||
value | ||
}); | ||
} | ||
describe() { | ||
@@ -165,9 +183,5 @@ const expressions = []; | ||
if (operator !== 'is') { | ||
throw new Error('UNIMPLEMENTED'); | ||
} | ||
if (value instanceof Date) { | ||
value = value.toISOString().slice(0, 10).replace(/-/g, '/'); | ||
} else { | ||
} else if (value !== undefined) { | ||
value = JSON.stringify(value); | ||
@@ -178,2 +192,3 @@ } | ||
field, | ||
operator, | ||
value | ||
@@ -180,0 +195,0 @@ }); |
@@ -26,3 +26,3 @@ import get from 'lodash/get'; | ||
if (fieldSchema.type === 'date') { | ||
if (fieldSchema.type === 'date' && value) { | ||
value = new Date(value); | ||
@@ -85,6 +85,2 @@ } | ||
findExpression(field) { | ||
return this._expressions.find(expression => expression.field === field); | ||
} | ||
forEachExpression(func) { | ||
@@ -114,8 +110,10 @@ return this._expressions.forEach(func); | ||
getValue(field) { | ||
const expression = this.findExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
getExpression(field) { | ||
return this._expressions.find(expression => expression.field === field); | ||
} | ||
setValue(field, value) { | ||
setExpression(field, { | ||
operator, | ||
value | ||
}) { | ||
const fieldSchema = this.constructor.getFieldSchema(field); | ||
@@ -127,8 +125,7 @@ | ||
let expression = this.findExpression(field); | ||
let expression = this.getExpression(field); | ||
if (!expression) { | ||
expression = { | ||
field, | ||
operator: 'is' | ||
field | ||
}; | ||
@@ -139,5 +136,26 @@ | ||
expression.operator = operator; | ||
expression.value = value; | ||
} | ||
deleteExpression(field) { | ||
const index = this._expressions.findIndex(expression => expression.field === field); | ||
if (index !== -1) { | ||
this._expressions.splice(index, 1); | ||
} | ||
} | ||
getValue(field) { | ||
const expression = this.getExpression(field); | ||
return expression === null || expression === void 0 ? void 0 : expression.value; | ||
} | ||
setValue(field, value) { | ||
this.setExpression(field, { | ||
operator: 'is', | ||
value | ||
}); | ||
} | ||
describe() { | ||
@@ -154,9 +172,5 @@ const expressions = []; | ||
if (operator !== 'is') { | ||
throw new Error('UNIMPLEMENTED'); | ||
} | ||
if (value instanceof Date) { | ||
value = value.toISOString().slice(0, 10).replace(/-/g, '/'); | ||
} else { | ||
} else if (value !== undefined) { | ||
value = JSON.stringify(value); | ||
@@ -167,2 +181,3 @@ } | ||
field, | ||
operator, | ||
value | ||
@@ -169,0 +184,0 @@ }); |
{ | ||
"name": "@medmain/core", | ||
"version": "0.1.25", | ||
"version": "0.1.26", | ||
"description": "Medmain's core module, root of everything else", | ||
@@ -5,0 +5,0 @@ "files": [ |
66862
2168