@hbtgmbh/dmn-eval-js
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -103,3 +103,3 @@ /* | ||
if (!doNotWarnIfUndefined) { | ||
logger.warn(`'${fullResult.expression}' resolved to undefined`); | ||
logger.info(`'${fullResult.expression}' resolved to undefined`); | ||
} | ||
@@ -111,3 +111,3 @@ } | ||
if (!doNotWarnIfUndefined) { | ||
logger.warn(`'${first.nameChars}' resolved to undefined`); | ||
logger.info(`'${first.nameChars}' resolved to undefined`); | ||
} | ||
@@ -114,0 +114,0 @@ } |
{ | ||
"name": "@hbtgmbh/dmn-eval-js", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Evaluation of DMN 1.1 decision tables, limited to S-FEEL (Simple Friendly Enough Expression Language)", | ||
@@ -26,10 +26,9 @@ "license": "MIT", | ||
"keywords": [ | ||
"DMN 1.1", | ||
"FEEL", | ||
"DMN 1.1", | ||
"Expression", | ||
"Language", | ||
"PEG", | ||
"PEGjs", | ||
"Decision Table", | ||
"Rule Engine" | ||
"S-FEEL", | ||
"Rule", | ||
"Rule Engine", | ||
"Decision", | ||
"Decision Table" | ||
], | ||
@@ -36,0 +35,0 @@ "author": "Andre Hegerath <andre.hegerath@hbt.de>", |
@@ -59,2 +59,3 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
// it is an array for hit policy COLLECT and RULE ORDER, and an object else | ||
// it is undefined if no rule matched | ||
@@ -61,0 +62,0 @@ ... // do something with the data |
@@ -54,22 +54,25 @@ /* | ||
let dt; | ||
let result; | ||
if (args.length === 1) { | ||
const arg = args[0]; | ||
let str; | ||
if (arg instanceof Date) { | ||
str = arg.toISOString(); | ||
} else if (arg.isDateTime || moment.isMoment(arg)) { | ||
str = arg.toISOString(); | ||
} else if (typeof arg === 'string') { | ||
str = arg; | ||
} else { | ||
throw new Error(`Invalid argument for date_and_time function: ${arg}`); | ||
if (arg !== null && arg !== undefined) { | ||
let str; | ||
if (arg instanceof Date) { | ||
str = arg.toISOString(); | ||
} else if (arg.isDateTime || moment.isMoment(arg)) { | ||
str = arg.toISOString(); | ||
} else if (typeof arg === 'string') { | ||
str = arg; | ||
} else { | ||
throw new Error(`Invalid argument for date_and_time function: ${arg}`); | ||
} | ||
try { | ||
dt = str === '' ? moment() : parseIANATz(str) || moment.parseZone(str); | ||
} catch (err) { | ||
throw err; | ||
} | ||
if (!dt || !dt.isValid()) { | ||
throw new Error('Invalid date_and_time. This is usually caused by an invalid format. Please check the input format'); | ||
} | ||
} | ||
try { | ||
dt = str === '' ? moment() : parseIANATz(str) || moment.parseZone(str); | ||
} catch (err) { | ||
throw err; | ||
} | ||
if (!dt || !dt.isValid()) { | ||
throw new Error('Invalid date_and_time. This is usually caused by an invalid format. Please check the input format'); | ||
} | ||
} else if (args.length === 2) { | ||
@@ -91,5 +94,8 @@ const [date, time] = args; | ||
return addProperties(dt, props); | ||
if (dt !== undefined) { | ||
result = addProperties(dt, props); | ||
} | ||
return result; | ||
}; | ||
module.exports = { 'date and time': dateAndTime }; |
@@ -54,26 +54,29 @@ /* | ||
let d; | ||
let result; | ||
if (args.length === 1) { | ||
const arg = args[0]; | ||
if (typeof arg === 'string') { | ||
try { | ||
d = arg === '' ? moment.parseZone(UTCTimePart, time_ISO_8601) : parseDate(arg); | ||
} catch (err) { | ||
throw err; | ||
if (arg !== null && arg !== undefined) { | ||
if (typeof arg === 'string') { | ||
try { | ||
d = arg === '' ? moment.parseZone(UTCTimePart, time_ISO_8601) : parseDate(arg); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} else if (typeof arg === 'object') { | ||
if (arg instanceof Date) { | ||
const ISO = arg.toISOString(); | ||
const dateTime = moment.parseZone(ISO); | ||
const datePart = dateTime.format(date_ISO_8601); | ||
d = moment.parseZone(`${datePart}${UTCTimePart}`); | ||
} else if (arg.isDateTime || moment.isMoment(arg)) { | ||
const dateTime = moment.tz(arg.format(), UTC); | ||
const datePart = dateTime.format(date_ISO_8601); | ||
d = moment.parseZone(`${datePart}${UTCTimePart}`); | ||
} | ||
if (!d || !d.isValid()) { | ||
throw new Error(`Invalid date. Parsing error while attempting to create date from ${arg}`); | ||
} | ||
} else { | ||
throw new Error('Invalid format encountered. Please specify date in one of these formats :\n- "date("2012-12-25")"\n- date_and_time object'); | ||
} | ||
} else if (typeof arg === 'object') { | ||
if (arg instanceof Date) { | ||
const ISO = arg.toISOString(); | ||
const dateTime = moment.parseZone(ISO); | ||
const datePart = dateTime.format(date_ISO_8601); | ||
d = moment.parseZone(`${datePart}${UTCTimePart}`); | ||
} else if (arg.isDateTime || moment.isMoment(arg)) { | ||
const dateTime = moment.tz(arg.format(), UTC); | ||
const datePart = dateTime.format(date_ISO_8601); | ||
d = moment.parseZone(`${datePart}${UTCTimePart}`); | ||
} | ||
if (!d || !d.isValid()) { | ||
throw new Error(`Invalid date. Parsing error while attempting to create date from ${arg}`); | ||
} | ||
} else { | ||
throw new Error('Invalid format encountered. Please specify date in one of these formats :\n- "date("2012-12-25")"\n- date_and_time object'); | ||
} | ||
@@ -90,3 +93,6 @@ } else if (args.length === 3 && isNumber(args)) { | ||
return addProperties(d, props); | ||
if (d !== undefined) { | ||
result = addProperties(d, props); | ||
} | ||
return result; | ||
}; | ||
@@ -93,0 +99,0 @@ |
@@ -79,19 +79,26 @@ /* | ||
const duration = (arg) => { | ||
if (typeof arg === 'string') { | ||
if (patternMatch(arg, ymd_ISO_8601)) { | ||
try { | ||
return yearsAndMonthsDuration(arg); | ||
} catch (err) { | ||
throw err; | ||
let result; | ||
if (arg !== null && arg !== undefined) { | ||
if (typeof arg === 'string') { | ||
if (patternMatch(arg, ymd_ISO_8601)) { | ||
try { | ||
result = yearsAndMonthsDuration(arg); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} else if (patternMatch(arg, dtd_ISO_8601)) { | ||
try { | ||
result = daysAndTimeDuration(arg); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
} else if (patternMatch(arg, dtd_ISO_8601)) { | ||
try { | ||
return daysAndTimeDuration(arg); | ||
} catch (err) { | ||
throw err; | ||
if (result === undefined) { | ||
throw new Error('Invalid Format : "duration" built-in function. Please check the input format'); | ||
} | ||
} else { | ||
throw new Error(`Type Error : "duration" built-in function expects a string but "${typeof arg}" encountered`); | ||
} | ||
throw new Error('Invalid Format : "duration" built-in function. Please check the input format'); | ||
} | ||
throw new Error(`Type Error : "duration" built-in function expects a string but "${typeof arg}" encountered`); | ||
return result; | ||
}; | ||
@@ -98,0 +105,0 @@ |
@@ -97,22 +97,25 @@ /* | ||
let t; | ||
let result; | ||
if (args.length === 1) { | ||
const arg = args[0]; | ||
if (typeof arg === 'string') { | ||
try { | ||
t = arg === '' ? moment() : parseIANATz(arg) || parseTime(arg); | ||
} catch (err) { | ||
throw err; | ||
if (arg !== null && arg !== undefined) { | ||
if (typeof arg === 'string') { | ||
try { | ||
t = arg === '' ? moment() : parseIANATz(arg) || parseTime(arg); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} else if (typeof arg === 'object') { | ||
if (arg instanceof Date) { | ||
t = moment.parseZone(arg.toISOString); | ||
} else if (arg.isDateTime) { | ||
const str = arg.format(time_ISO_8601); | ||
t = moment.parseZone(str, time_ISO_8601); | ||
} | ||
if (!t.isValid()) { | ||
throw new Error('Invalid time. Parsing error while attempting to extract time from date and time.'); | ||
} | ||
} else { | ||
throw new Error('Invalid format encountered. Please specify time in one of these formats :\n- "23:59:00z"\n- "00:01:00@Etc/UTC"\n- date_and_time object'); | ||
} | ||
} else if (typeof arg === 'object') { | ||
if (arg instanceof Date) { | ||
t = moment.parseZone(arg.toISOString); | ||
} else if (arg.isDateTime) { | ||
const str = arg.format(time_ISO_8601); | ||
t = moment.parseZone(str, time_ISO_8601); | ||
} | ||
if (!t.isValid()) { | ||
throw new Error('Invalid time. Parsing error while attempting to extract time from date and time.'); | ||
} | ||
} else { | ||
throw new Error('Invalid format encountered. Please specify time in one of these formats :\n- "23:59:00z"\n- "00:01:00@Etc/UTC"\n- date_and_time object'); | ||
} | ||
@@ -139,5 +142,8 @@ } else if (args.length >= 3 && isNumber(args.slice(0, 3))) { | ||
return addProperties(t, props); | ||
if (t !== undefined) { | ||
result = addProperties(t, props); | ||
} | ||
return result; | ||
}; | ||
module.exports = { time }; |
@@ -247,3 +247,3 @@ /* | ||
if ((decisionTable.hitPolicy === 'FIRST') || (decisionTable.hitPolicy === 'UNIQUE')) { | ||
setOrAddValue(outputName, decisionResult, null); | ||
setOrAddValue(outputName, decisionResult, undefined); | ||
} else { | ||
@@ -284,2 +284,5 @@ setOrAddValue(outputName, decisionResult, []); | ||
} | ||
if (!hasMatch) { | ||
logger.warn(`No rule matched for decision "${decisionId}".`); | ||
} | ||
return decisionResult; | ||
@@ -286,0 +289,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266415
6053
288