@qrvey/formula-lang 0.11.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/dist/cjs/constants/interfaces.d.ts +4 -1
- package/dist/cjs/errors/dictionary.d.ts +2 -2
- package/dist/cjs/errors/dictionary.js +5 -5
- package/dist/cjs/errors/dictionary.js.map +1 -1
- package/dist/cjs/functions/and.d.ts +5 -0
- package/dist/cjs/functions/and.js +52 -0
- package/dist/cjs/functions/and.js.map +1 -0
- package/dist/cjs/functions/concatenate.d.ts +5 -0
- package/dist/cjs/functions/concatenate.js +53 -0
- package/dist/cjs/functions/concatenate.js.map +1 -0
- package/dist/cjs/functions/dateadd.d.ts +5 -0
- package/dist/cjs/functions/dateadd.js +89 -0
- package/dist/cjs/functions/dateadd.js.map +1 -0
- package/dist/cjs/functions/datedif.js +2 -13
- package/dist/cjs/functions/datedif.js.map +1 -1
- package/dist/cjs/functions/dayofweek.d.ts +5 -0
- package/dist/cjs/functions/dayofweek.js +88 -0
- package/dist/cjs/functions/dayofweek.js.map +1 -0
- package/dist/cjs/functions/if.js +5 -5
- package/dist/cjs/functions/if.js.map +1 -1
- package/dist/cjs/functions/index.js +22 -0
- package/dist/cjs/functions/index.js.map +1 -1
- package/dist/cjs/functions/isNull.js +5 -9
- package/dist/cjs/functions/isNull.js.map +1 -1
- package/dist/cjs/functions/left.d.ts +5 -0
- package/dist/cjs/functions/left.js +54 -0
- package/dist/cjs/functions/left.js.map +1 -0
- package/dist/cjs/functions/lower.d.ts +5 -0
- package/dist/cjs/functions/lower.js +41 -0
- package/dist/cjs/functions/lower.js.map +1 -0
- package/dist/cjs/functions/mid.js +19 -40
- package/dist/cjs/functions/mid.js.map +1 -1
- package/dist/cjs/functions/or.d.ts +5 -0
- package/dist/cjs/functions/or.js +52 -0
- package/dist/cjs/functions/or.js.map +1 -0
- package/dist/cjs/functions/proper.d.ts +5 -0
- package/dist/cjs/functions/proper.js +38 -0
- package/dist/cjs/functions/proper.js.map +1 -0
- package/dist/cjs/functions/right.d.ts +5 -0
- package/dist/cjs/functions/right.js +55 -0
- package/dist/cjs/functions/right.js.map +1 -0
- package/dist/cjs/functions/trim.d.ts +5 -0
- package/dist/cjs/functions/trim.js +41 -0
- package/dist/cjs/functions/trim.js.map +1 -0
- package/dist/cjs/functions/upper.d.ts +5 -0
- package/dist/cjs/functions/upper.js +41 -0
- package/dist/cjs/functions/upper.js.map +1 -0
- package/dist/cjs/transpiler/index.js +4 -2
- package/dist/cjs/transpiler/index.js.map +1 -1
- package/dist/cjs/utils/elasticsearch/index.js +4 -0
- package/dist/cjs/utils/elasticsearch/index.js.map +1 -1
- package/dist/cjs/utils/elasticsearch/scripts.d.ts +1 -0
- package/dist/cjs/utils/elasticsearch/scripts.js +31 -7
- package/dist/cjs/utils/elasticsearch/scripts.js.map +1 -1
- package/dist/cjs/utils/escapeCharacters.d.ts +2 -0
- package/dist/cjs/utils/escapeCharacters.js +39 -0
- package/dist/cjs/utils/escapeCharacters.js.map +1 -0
- package/dist/cjs/utils/greaterThanZero.d.ts +3 -0
- package/dist/cjs/utils/greaterThanZero.js +38 -0
- package/dist/cjs/utils/greaterThanZero.js.map +1 -0
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/isAnAllowedValue.d.ts +2 -0
- package/dist/cjs/utils/isAnAllowedValue.js +20 -0
- package/dist/cjs/utils/isAnAllowedValue.js.map +1 -0
- package/dist/module/constants/interfaces.d.ts +4 -1
- package/dist/module/errors/dictionary.d.ts +2 -2
- package/dist/module/errors/dictionary.js +5 -5
- package/dist/module/errors/dictionary.js.map +1 -1
- package/dist/module/functions/and.d.ts +5 -0
- package/dist/module/functions/and.js +49 -0
- package/dist/module/functions/and.js.map +1 -0
- package/dist/module/functions/concatenate.d.ts +5 -0
- package/dist/module/functions/concatenate.js +50 -0
- package/dist/module/functions/concatenate.js.map +1 -0
- package/dist/module/functions/dateadd.d.ts +5 -0
- package/dist/module/functions/dateadd.js +86 -0
- package/dist/module/functions/dateadd.js.map +1 -0
- package/dist/module/functions/datedif.js +2 -13
- package/dist/module/functions/datedif.js.map +1 -1
- package/dist/module/functions/dayofweek.d.ts +5 -0
- package/dist/module/functions/dayofweek.js +85 -0
- package/dist/module/functions/dayofweek.js.map +1 -0
- package/dist/module/functions/if.js +5 -5
- package/dist/module/functions/if.js.map +1 -1
- package/dist/module/functions/index.js +22 -0
- package/dist/module/functions/index.js.map +1 -1
- package/dist/module/functions/isNull.js +5 -9
- package/dist/module/functions/isNull.js.map +1 -1
- package/dist/module/functions/left.d.ts +5 -0
- package/dist/module/functions/left.js +51 -0
- package/dist/module/functions/left.js.map +1 -0
- package/dist/module/functions/lower.d.ts +5 -0
- package/dist/module/functions/lower.js +38 -0
- package/dist/module/functions/lower.js.map +1 -0
- package/dist/module/functions/mid.js +19 -40
- package/dist/module/functions/mid.js.map +1 -1
- package/dist/module/functions/or.d.ts +5 -0
- package/dist/module/functions/or.js +49 -0
- package/dist/module/functions/or.js.map +1 -0
- package/dist/module/functions/proper.d.ts +5 -0
- package/dist/module/functions/proper.js +35 -0
- package/dist/module/functions/proper.js.map +1 -0
- package/dist/module/functions/right.d.ts +5 -0
- package/dist/module/functions/right.js +52 -0
- package/dist/module/functions/right.js.map +1 -0
- package/dist/module/functions/trim.d.ts +5 -0
- package/dist/module/functions/trim.js +38 -0
- package/dist/module/functions/trim.js.map +1 -0
- package/dist/module/functions/upper.d.ts +5 -0
- package/dist/module/functions/upper.js +38 -0
- package/dist/module/functions/upper.js.map +1 -0
- package/dist/module/transpiler/index.js +4 -2
- package/dist/module/transpiler/index.js.map +1 -1
- package/dist/module/utils/elasticsearch/index.js +5 -1
- package/dist/module/utils/elasticsearch/index.js.map +1 -1
- package/dist/module/utils/elasticsearch/scripts.d.ts +1 -0
- package/dist/module/utils/elasticsearch/scripts.js +30 -6
- package/dist/module/utils/elasticsearch/scripts.js.map +1 -1
- package/dist/module/utils/escapeCharacters.d.ts +2 -0
- package/dist/module/utils/escapeCharacters.js +35 -0
- package/dist/module/utils/escapeCharacters.js.map +1 -0
- package/dist/module/utils/greaterThanZero.d.ts +3 -0
- package/dist/module/utils/greaterThanZero.js +34 -0
- package/dist/module/utils/greaterThanZero.js.map +1 -0
- package/dist/module/utils/index.js +1 -1
- package/dist/module/utils/index.js.map +1 -1
- package/dist/module/utils/isAnAllowedValue.d.ts +2 -0
- package/dist/module/utils/isAnAllowedValue.js +16 -0
- package/dist/module/utils/isAnAllowedValue.js.map +1 -0
- package/package.json +1 -1
|
@@ -12,3 +12,4 @@ export declare const secondScript: (value: any) => string;
|
|
|
12
12
|
export declare function dateDif(start: any, end: any, unit: DateDifUnitParam): string;
|
|
13
13
|
export declare const getValueScript = "def GET_VALUE(def c){return (c.empty ? null : c.value)}";
|
|
14
14
|
export declare const isNullScript = "def IS_NULL_SCRIPT(def value, def replacement) { return value ?: replacement; }";
|
|
15
|
+
export declare const properScript = "String PROPER_STRING(String input) {\n if (input == null) return null;\n def str = input.toLowerCase();\n def builder = new StringBuilder(str);\n \n def chartLists = [\" \", \"!\", \"\\\"\", \"#\", \"$\", \"%\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \"-\", \".\", \"/\", \":\", \";\", \"<\", \"=\", \">\", \"?\", \"@\", \"[\", \"\\\\\", \"]\", \"^\", \"_\", \"`\", \"{\", \"|\", \"}\", \"~\"];\n \n boolean flag = true;\n \n for(int i = 0; i < builder.length(); i++) {\n String ch = builder.charAt(i).toString();\n if (flag) { \n builder.replace(i, i + 1, ch.toUpperCase());\n flag = false;\n }\n flag = chartLists.contains(ch);\n }\n return builder.toString();\n }";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNullScript = exports.getValueScript = exports.dateDif = exports.secondScript = exports.minuteScript = exports.hourScript = exports.yearScript = exports.monthScript = exports.dayScript = exports.subStringScript = exports.dateFormatScript = exports.setTimezoneToColumnDate = exports.toDate = void 0;
|
|
3
|
+
exports.properScript = exports.isNullScript = exports.getValueScript = exports.dateDif = exports.secondScript = exports.minuteScript = exports.hourScript = exports.yearScript = exports.monthScript = exports.dayScript = exports.subStringScript = exports.dateFormatScript = exports.setTimezoneToColumnDate = exports.toDate = void 0;
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
function toDate(value) {
|
|
6
6
|
return `ZonedDateTime.parse("${value}")`;
|
|
@@ -30,13 +30,18 @@ String ${constants_1.ELASTICSEARCH_SCRIPT_NAMES.dateFormat}(def date_value, Stri
|
|
|
30
30
|
}
|
|
31
31
|
`;
|
|
32
32
|
exports.subStringScript = `
|
|
33
|
-
String ${constants_1.ELASTICSEARCH_SCRIPT_NAMES.subString}(String text, int start) {
|
|
34
|
-
return ${constants_1.ELASTICSEARCH_SCRIPT_NAMES.subString}(text, start, text.length());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
33
|
String ${constants_1.ELASTICSEARCH_SCRIPT_NAMES.subString}(String text, int start, int end) {
|
|
38
|
-
int first =
|
|
39
|
-
|
|
34
|
+
int first = 0;
|
|
35
|
+
if (end < 0 || (start * -1 > text.length())) return "";
|
|
36
|
+
if (start < 0) {
|
|
37
|
+
first = (int) Math.max(text.length() + start, 0);
|
|
38
|
+
} else if (start == 0) {
|
|
39
|
+
first = 0;
|
|
40
|
+
} else {
|
|
41
|
+
first = (int) Math.min(start - 1, text.length())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
int last = (int) Math.min(first + end, text.length());
|
|
40
45
|
return text.substring(first, last);
|
|
41
46
|
}
|
|
42
47
|
`;
|
|
@@ -67,4 +72,23 @@ function dateDif(start, end, unit) {
|
|
|
67
72
|
exports.dateDif = dateDif;
|
|
68
73
|
exports.getValueScript = `def GET_VALUE(def c){return (c.empty ? null : c.value)}`;
|
|
69
74
|
exports.isNullScript = `def IS_NULL_SCRIPT(def value, def replacement) { return value ?: replacement; }`;
|
|
75
|
+
exports.properScript = `String PROPER_STRING(String input) {
|
|
76
|
+
if (input == null) return null;
|
|
77
|
+
def str = input.toLowerCase();
|
|
78
|
+
def builder = new StringBuilder(str);
|
|
79
|
+
|
|
80
|
+
def chartLists = [" ", "!", "\\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\\\", "]", "^", "_", "\`", "{", "|", "}", "~"];
|
|
81
|
+
|
|
82
|
+
boolean flag = true;
|
|
83
|
+
|
|
84
|
+
for(int i = 0; i < builder.length(); i++) {
|
|
85
|
+
String ch = builder.charAt(i).toString();
|
|
86
|
+
if (flag) {
|
|
87
|
+
builder.replace(i, i + 1, ch.toUpperCase());
|
|
88
|
+
flag = false;
|
|
89
|
+
}
|
|
90
|
+
flag = chartLists.contains(ch);
|
|
91
|
+
}
|
|
92
|
+
return builder.toString();
|
|
93
|
+
}`;
|
|
70
94
|
//# sourceMappingURL=scripts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../src/utils/elasticsearch/scripts.ts"],"names":[],"mappings":";;;AACA,+CAA6E;AAE7E,SAAgB,MAAM,CAAC,KAAa;IAChC,OAAO,wBAAwB,KAAK,IAAI,CAAC;AAC7C,CAAC;AAFD,wBAEC;AAEY,QAAA,uBAAuB,GAAG;MACjC,sCAAY,CAAC,WAAW;;;;;;;;;;;CAW7B,CAAC;AAEW,QAAA,gBAAgB,GAAG;SACvB,sCAAY,CAAC,UAAU;;;;;;;;CAQ/B,CAAC;AAEW,QAAA,eAAe,GAAG;SACtB,sCAAY,CAAC,SAAS
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../src/utils/elasticsearch/scripts.ts"],"names":[],"mappings":";;;AACA,+CAA6E;AAE7E,SAAgB,MAAM,CAAC,KAAa;IAChC,OAAO,wBAAwB,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ACV,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,QAAQ;QACX,CAAC,EAAE,MAAM;KACZ,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,cAAc,WAAW,YAAY,KAAK,KAAK,GAAG,GAAG,CAAC;AACjE,CAAC;AARD,0BAQC;AAEY,QAAA,cAAc,GAAG,yDAAyD,CAAC;AAE3E,QAAA,YAAY,GAAG,iFAAiF,CAAC;AACjG,QAAA,YAAY,GAAG;;;;;;;;;;;;;;;;;;IAkBxB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeCharacters = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const escapeCharacters = (inputString, engine) => {
|
|
6
|
+
let value = inputString.replace(
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
/[\0\x08\x09\x1a\n\r"'\\%]/g, (char) => {
|
|
9
|
+
switch (char) {
|
|
10
|
+
case '\0':
|
|
11
|
+
return '\\\\0';
|
|
12
|
+
case '\x08':
|
|
13
|
+
return '\\\\b';
|
|
14
|
+
case '\x09':
|
|
15
|
+
return '\\\\t';
|
|
16
|
+
case '\x1a':
|
|
17
|
+
return '\\\\z';
|
|
18
|
+
case '\n':
|
|
19
|
+
return '\\\\n';
|
|
20
|
+
case '\r':
|
|
21
|
+
return '\\\\r';
|
|
22
|
+
case '"':
|
|
23
|
+
case "'":
|
|
24
|
+
case '\\':
|
|
25
|
+
case '%':
|
|
26
|
+
// prepends a backslash to backslash, percent, and double/single quotes
|
|
27
|
+
return '\\' + char;
|
|
28
|
+
default:
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
value = `'${value}'`;
|
|
33
|
+
if (engine === constants_1.ENGINES.POSTGRESQL) {
|
|
34
|
+
return `E${value}`;
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
exports.escapeCharacters = escapeCharacters;
|
|
39
|
+
//# sourceMappingURL=escapeCharacters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeCharacters.js","sourceRoot":"","sources":["../../../src/utils/escapeCharacters.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AAEhC,MAAM,gBAAgB,GAAG,CAC5B,WAAmB,EACnB,MAAe,EACT,EAAE;IACR,IAAI,KAAK,GAAW,WAAW,CAAC,OAAO;IACnC,4CAA4C;IAC5C,4BAA4B,EAC5B,CAAC,IAAY,EAAE,EAAE;QACb,QAAQ,IAAI,EAAE;YACV,KAAK,IAAI;gBACL,OAAO,OAAO,CAAC;YACnB,KAAK,MAAM;gBACP,OAAO,OAAO,CAAC;YACnB,KAAK,MAAM;gBACP,OAAO,OAAO,CAAC;YACnB,KAAK,MAAM;gBACP,OAAO,OAAO,CAAC;YACnB,KAAK,IAAI;gBACL,OAAO,OAAO,CAAC;YACnB,KAAK,IAAI;gBACL,OAAO,OAAO,CAAC;YACnB,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC;YACT,KAAK,IAAI,CAAC;YACV,KAAK,GAAG;gBACJ,uEAAuE;gBACvE,OAAO,IAAI,GAAG,IAAI,CAAC;YACvB;gBACI,OAAO,EAAE,CAAC;SACjB;IACL,CAAC,CACJ,CAAC;IACF,KAAK,GAAG,IAAI,KAAK,GAAG,CAAC;IACrB,IAAI,MAAM,KAAK,mBAAO,CAAC,UAAU,EAAE;QAC/B,OAAO,IAAI,KAAK,EAAE,CAAC;KACtB;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAtCW,QAAA,gBAAgB,oBAsC3B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.greaterThanZero = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const dictionary_1 = require("../errors/dictionary");
|
|
6
|
+
function greaterThanZero(param, _dataType, context) {
|
|
7
|
+
return greaterThanReference(param, context.argument, 0);
|
|
8
|
+
}
|
|
9
|
+
exports.greaterThanZero = greaterThanZero;
|
|
10
|
+
function greaterThanReference(param, arg, compareReference) {
|
|
11
|
+
const numericValue = getNumericValueFromArgument(param, arg);
|
|
12
|
+
const valid = typeof numericValue !== 'number' ||
|
|
13
|
+
compareValueWithReference(numericValue, compareReference);
|
|
14
|
+
if (!valid)
|
|
15
|
+
return Object.assign(Object.assign({ valid }, dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.greaterThan]), { info: {
|
|
16
|
+
greaterThan: compareReference,
|
|
17
|
+
} });
|
|
18
|
+
return { valid };
|
|
19
|
+
}
|
|
20
|
+
function getNumericValueFromArgument(param, argument) {
|
|
21
|
+
if (typeof param === 'number')
|
|
22
|
+
return param;
|
|
23
|
+
const isUnaryExpression = argument.type === constants_1.AST_TYPES.unaryExpression; // Negative numbers arrive as unary expression
|
|
24
|
+
if (isUnaryExpression) {
|
|
25
|
+
const unaryExp = argument.node;
|
|
26
|
+
const isNegative = unaryExp.operator === '-';
|
|
27
|
+
const isNumber = unaryExp.right.type === constants_1.AST_TYPES.literal &&
|
|
28
|
+
unaryExp.right.dataType === constants_1.AST_PRIMITIVES.NUMBER;
|
|
29
|
+
if (isNumber)
|
|
30
|
+
return (unaryExp.right.value *
|
|
31
|
+
(isNegative ? -1 : 1));
|
|
32
|
+
}
|
|
33
|
+
return param;
|
|
34
|
+
}
|
|
35
|
+
function compareValueWithReference(value, reference) {
|
|
36
|
+
return value >= reference;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=greaterThanZero.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greaterThanZero.js","sourceRoot":"","sources":["../../../src/utils/greaterThanZero.ts"],"names":[],"mappings":";;;AAAA,4CAAoE;AAQpE,qDAAoE;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ACxB,CAAC;KACT;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAa,EAAE,SAAiB;IAC/D,OAAO,KAAK,IAAI,SAAS,CAAC;AAC9B,CAAC"}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -24,6 +24,6 @@ __exportStar(require("./getMonthMaxDayAllowed"), exports);
|
|
|
24
24
|
__exportStar(require("./getNodeValue"), exports);
|
|
25
25
|
__exportStar(require("./getVariableType"), exports);
|
|
26
26
|
__exportStar(require("./isLongLiteralNumber"), exports);
|
|
27
|
-
const removeQuotes = (str) => str.replace(
|
|
27
|
+
const removeQuotes = (str) => str.replace(/^E?'|'$/g, '');
|
|
28
28
|
exports.removeQuotes = removeQuotes;
|
|
29
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC;AAChC,kDAAgC;AAChC,gDAA8B;AAC9B,gDAA8B;AAC9B,0DAAwC;AACxC,iDAA+B;AAC/B,oDAAkC;AAClC,wDAAsC;AAE/B,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC;AAChC,kDAAgC;AAChC,gDAA8B;AAC9B,gDAA8B;AAC9B,0DAAwC;AACxC,iDAA+B;AAC/B,oDAAkC;AAClC,wDAAsC;AAE/B,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAA5D,QAAA,YAAY,gBAAgD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAnAllowedValue = void 0;
|
|
4
|
+
const dictionary_1 = require("../errors/dictionary");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
function isAnAllowedValue(allowValues) {
|
|
7
|
+
return (param) => {
|
|
8
|
+
param = (0, utils_1.removeQuotes)(param);
|
|
9
|
+
const valid = allowValues.includes(param);
|
|
10
|
+
if (!valid) {
|
|
11
|
+
const msgError = dictionary_1.ERROR_DICTIONARY[dictionary_1.ERROR_LIST.invalidAllowValue];
|
|
12
|
+
return Object.assign(Object.assign({ valid }, msgError), { message: `${msgError.message} "${allowValues.join('", "')}"`, info: {
|
|
13
|
+
allowedValues: allowValues,
|
|
14
|
+
} });
|
|
15
|
+
}
|
|
16
|
+
return { valid };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.isAnAllowedValue = isAnAllowedValue;
|
|
20
|
+
//# sourceMappingURL=isAnAllowedValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAnAllowedValue.js","sourceRoot":"","sources":["../../../src/utils/isAnAllowedValue.ts"],"names":[],"mappings":";;;AACA,qDAAoE;AACpE,oCAAwC;AAExC,SAAgB,gBAAgB,CAAC,WAAqB;IAClD,OAAO,CAAC,KAAU,EAAqB,EAAE;QACrC,KAAK,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,EAAE;YACR,MAAM,QAAQ,GAAG,6BAAgB,CAAC,uBAAU,CAAC,iBAAiB,CAAC,CAAC;YAChE,qCACI,KAAK,IACF,QAAQ,KACX,OAAO,EAAE,GAAG,QAAQ,CAAC,OAAO,KAAK,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAC5D,IAAI,EAAE;oBACF,aAAa,EAAE,WAAW;iBAC7B,IACH;SACL;QACD,OAAO,EAAE,KAAK,EAAE,CAAC;IACrB,CAAC,CAAC;AACN,CAAC;AAjBD,4CAiBC"}
|
|
@@ -130,5 +130,8 @@ interface TimezoneDefinition {
|
|
|
130
130
|
offset: string;
|
|
131
131
|
}
|
|
132
132
|
export type VariableASTType = AST_TYPES.variable | AST_TYPES.column | AST_TYPES.token;
|
|
133
|
-
export type
|
|
133
|
+
export type DateUnit = 'Y' | 'M' | 'D';
|
|
134
|
+
export type DateDifUnitParam = DateUnit;
|
|
135
|
+
export type DateTimeUnit = DateUnit | 'H' | 'MI' | 'S';
|
|
136
|
+
export type DayOfWeekFormat = 'Day' | 'D';
|
|
134
137
|
export {};
|
|
@@ -10,7 +10,6 @@ export declare enum ERROR_LIST {
|
|
|
10
10
|
missingParenthesis = "missingParenthesis",
|
|
11
11
|
unknownFunction = "unknownFunction",
|
|
12
12
|
unknown = "unknown",
|
|
13
|
-
customDateDifParams = "customDateDifParams",
|
|
14
13
|
tooManyArguments = "tooManyArguments",
|
|
15
14
|
unknownToken = "unknownToken",
|
|
16
15
|
notAllowedOperation = "notAllowedOperation",
|
|
@@ -20,7 +19,8 @@ export declare enum ERROR_LIST {
|
|
|
20
19
|
booleanExpression = "booleanExpression",
|
|
21
20
|
missingColumnExpression = "missingColumnExpression",
|
|
22
21
|
noColumnExpression = "noColumnExpression",
|
|
23
|
-
functionArgumentsMismatch = "functionArgumentsMismatch"
|
|
22
|
+
functionArgumentsMismatch = "functionArgumentsMismatch",
|
|
23
|
+
invalidAllowValue = "invalidAllowValue"
|
|
24
24
|
}
|
|
25
25
|
type ErrorsType = {
|
|
26
26
|
[key in ERROR_LIST]: ErrorDictionary;
|
|
@@ -11,7 +11,6 @@ export var ERROR_LIST;
|
|
|
11
11
|
ERROR_LIST["missingParenthesis"] = "missingParenthesis";
|
|
12
12
|
ERROR_LIST["unknownFunction"] = "unknownFunction";
|
|
13
13
|
ERROR_LIST["unknown"] = "unknown";
|
|
14
|
-
ERROR_LIST["customDateDifParams"] = "customDateDifParams";
|
|
15
14
|
ERROR_LIST["tooManyArguments"] = "tooManyArguments";
|
|
16
15
|
ERROR_LIST["unknownToken"] = "unknownToken";
|
|
17
16
|
ERROR_LIST["notAllowedOperation"] = "notAllowedOperation";
|
|
@@ -22,6 +21,7 @@ export var ERROR_LIST;
|
|
|
22
21
|
ERROR_LIST["missingColumnExpression"] = "missingColumnExpression";
|
|
23
22
|
ERROR_LIST["noColumnExpression"] = "noColumnExpression";
|
|
24
23
|
ERROR_LIST["functionArgumentsMismatch"] = "functionArgumentsMismatch";
|
|
24
|
+
ERROR_LIST["invalidAllowValue"] = "invalidAllowValue";
|
|
25
25
|
})(ERROR_LIST || (ERROR_LIST = {}));
|
|
26
26
|
export const ERROR_DICTIONARY = {
|
|
27
27
|
[ERROR_LIST.arguments]: {
|
|
@@ -76,10 +76,6 @@ export const ERROR_DICTIONARY = {
|
|
|
76
76
|
message: 'Too many arguments',
|
|
77
77
|
code: 'TOO_MANY_ARGUMENTS',
|
|
78
78
|
},
|
|
79
|
-
[ERROR_LIST.customDateDifParams]: {
|
|
80
|
-
message: 'Unit param have to be equal to: "Y", "M", "D"',
|
|
81
|
-
code: 'DATE_DIF_UNIT_PARAM',
|
|
82
|
-
},
|
|
83
79
|
[ERROR_LIST.notAllowedOperation]: {
|
|
84
80
|
message: 'Operation not allowed',
|
|
85
81
|
code: 'NOT_ALLOWED_OPERATION',
|
|
@@ -112,5 +108,9 @@ export const ERROR_DICTIONARY = {
|
|
|
112
108
|
message: 'Function arguments mismatch.',
|
|
113
109
|
code: 'FUNCTION_ARGUMENTS_MISMATCH',
|
|
114
110
|
},
|
|
111
|
+
[ERROR_LIST.invalidAllowValue]: {
|
|
112
|
+
message: 'Argument have to be equal to:',
|
|
113
|
+
code: 'INVALID_ALLOW_VALUE',
|
|
114
|
+
},
|
|
115
115
|
};
|
|
116
116
|
//# sourceMappingURL=dictionary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../../src/errors/dictionary.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAuBX;AAvBD,WAAY,UAAU;IAClB,qCAAuB,CAAA;IACvB,6BAAe,CAAA;IACf,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,yCAA2B,CAAA;IAC3B,yCAA2B,CAAA;IAC3B,uCAAyB,CAAA;IACzB,uDAAyC,CAAA;IACzC,iDAAmC,CAAA;IACnC,iCAAmB,CAAA;IACnB,
|
|
1
|
+
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../../src/errors/dictionary.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAuBX;AAvBD,WAAY,UAAU;IAClB,qCAAuB,CAAA;IACvB,6BAAe,CAAA;IACf,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,yCAA2B,CAAA;IAC3B,yCAA2B,CAAA;IAC3B,uCAAyB,CAAA;IACzB,uDAAyC,CAAA;IACzC,iDAAmC,CAAA;IACnC,iCAAmB,CAAA;IACnB,mDAAqC,CAAA;IACrC,2CAA6B,CAAA;IAC7B,yDAA2C,CAAA;IAC3C,uCAAyB,CAAA;IACzB,qDAAuC,CAAA;IACvC,qDAAuC,CAAA;IACvC,qDAAuC,CAAA;IACvC,iEAAmD,CAAA;IACnD,uDAAyC,CAAA;IACzC,qEAAuD,CAAA;IACvD,qDAAuC,CAAA;AAC3C,CAAC,EAvBW,UAAU,KAAV,UAAU,QAuBrB;AAWD,MAAM,CAAC,MAAM,gBAAgB,GAAe;IACxC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QACpB,OAAO,EAAE,yCAAyC;QAClD,IAAI,EAAE,aAAa;KACtB;IACD,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAChB,OAAO,EAAE,yCAAyC;QAClD,IAAI,EAAE,aAAa;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AAU,CAAC,EAAE;QACrB,OAAO,EAAE,yBAAyB;QAClC,IAAI,EAAE,cAAc;KACvB;IACD,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;QAC5B,OAAO,EAAE,kDAAkD;QAC3D,IAAI,EAAE,qBAAqB;KAC9B;IACD,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;QAC5B,OAAO,EAAE,+CAA+C;QACxD,IAAI,EAAE,oBAAoB;KAC7B;IACD,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;QAC5B,OAAO,EAAE,0BAA0B;QACnC,IAAI,EAAE,0BAA0B;KACnC;IACD,CAAC,UAAU,CAAC,uBAAuB,CAAC,EAAE;QAClC,OAAO,EAAE,8BAA8B;QACvC,IAAI,EAAE,2BAA2B;KACpC;IACD,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;QAC7B,OAAO,EAAE,8BAA8B;QACvC,IAAI,EAAE,sBAAsB;KAC/B;IACD,CAAC,UAAU,CAAC,yBAAyB,CAAC,EAAE;QACpC,OAAO,EAAE,8BAA8B;QACvC,IAAI,EAAE,6BAA6B;KACtC;IACD,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;QAC5B,OAAO,EAAE,+BAA+B;QACxC,IAAI,EAAE,qBAAqB;KAC9B;CACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AST_PRIMITIVES } from '../constants';
|
|
2
|
+
import { isBooleanExpression } from '../utils/isBooleanExpression';
|
|
3
|
+
/**
|
|
4
|
+
* `AND` Returns true if all expressions are truthy; otherwise, it will return false.
|
|
5
|
+
*/
|
|
6
|
+
export const AND = {
|
|
7
|
+
identifier: 'AND',
|
|
8
|
+
recursiveStartIn: 1,
|
|
9
|
+
parameters: [
|
|
10
|
+
{
|
|
11
|
+
identifier: 'LOGICAL_EXPRESSION',
|
|
12
|
+
optional: false,
|
|
13
|
+
validator: [isBooleanExpression],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
identifier: 'LOGICAL_EXPRESSION',
|
|
17
|
+
optional: false,
|
|
18
|
+
validator: [isBooleanExpression],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
identifier: 'LOGICAL_EXPRESSION',
|
|
22
|
+
optional: true,
|
|
23
|
+
validator: [isBooleanExpression],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
transpiler: {
|
|
27
|
+
elasticsearch,
|
|
28
|
+
snowflake,
|
|
29
|
+
redshift,
|
|
30
|
+
postgresql,
|
|
31
|
+
},
|
|
32
|
+
primitiveResult: AST_PRIMITIVES.BOOLEAN,
|
|
33
|
+
};
|
|
34
|
+
function elasticsearch(...args) {
|
|
35
|
+
return `(${args.join(' && ')})`;
|
|
36
|
+
}
|
|
37
|
+
function sql(...args) {
|
|
38
|
+
return `(${args.join(' AND ')})`;
|
|
39
|
+
}
|
|
40
|
+
function snowflake(...args) {
|
|
41
|
+
return sql(...args);
|
|
42
|
+
}
|
|
43
|
+
function redshift(...args) {
|
|
44
|
+
return sql(...args);
|
|
45
|
+
}
|
|
46
|
+
function postgresql(...args) {
|
|
47
|
+
return sql(...args);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=and.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and.js","sourceRoot":"","sources":["../../../src/functions/and.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAuB;IACnC,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE;QACR;YACI,UAAU,EAAE,oBAAoB;YAChC,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,CAAC,mBAAmB,CAAC;SACnC;QACD;YACI,UAAU,EAAE,oBAAoB;YAChC,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,CAAC,mBAAmB,CAAC;SACnC;QACD;YACI,UAAU,EAAE,oBAAoB;YAChC,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,CAAC,mBAAmB,CAAC;SACnC;KACJ;IACD,UAAU,EAAE;QACR,aAAa;QACb,SAAS;QACT,QAAQ;QACR,UAAU;KACb;IACD,eAAe,EAAE,cAAc,CAAC,OAAO;CAC1C,CAAC;AAEF,SAAS,aAAa,CAAC,GAAG,IAAW;IACjC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AACpC,CAAC;AAED,SAAS,GAAG,CAAC,GAAG,IAAW;IACvB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;AACrC,CAAC;AAED,SAAS,SAAS,CAAC,GAAG,IAAW;IAC7B,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,QAAQ,CAAC,GAAG,IAAW;IAC5B,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,GAAG,IAAW;IAC9B,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AST_PRIMITIVES } from '../constants';
|
|
2
|
+
import { isStringParam } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* `CONCATENATE` Joins two or more strings into one string.
|
|
5
|
+
*/
|
|
6
|
+
export const CONCATENATE = {
|
|
7
|
+
identifier: 'CONCATENATE',
|
|
8
|
+
recursiveStartIn: 1,
|
|
9
|
+
parameters: [
|
|
10
|
+
{
|
|
11
|
+
identifier: 'STRING_1',
|
|
12
|
+
optional: false,
|
|
13
|
+
validator: [isStringParam],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
identifier: 'STRING_2',
|
|
17
|
+
optional: false,
|
|
18
|
+
validator: [isStringParam],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
identifier: 'STRING_N',
|
|
22
|
+
optional: true,
|
|
23
|
+
validator: [isStringParam],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
transpiler: {
|
|
27
|
+
elasticsearch,
|
|
28
|
+
snowflake,
|
|
29
|
+
redshift,
|
|
30
|
+
postgresql,
|
|
31
|
+
},
|
|
32
|
+
primitiveResult: AST_PRIMITIVES.BOOLEAN,
|
|
33
|
+
};
|
|
34
|
+
function elasticsearch(...args) {
|
|
35
|
+
return `(${args.join(' + ')})`;
|
|
36
|
+
}
|
|
37
|
+
function sql(...args) {
|
|
38
|
+
return `CONCAT(${args.join(', ')})`;
|
|
39
|
+
}
|
|
40
|
+
function snowflake(...args) {
|
|
41
|
+
return sql(...args);
|
|
42
|
+
}
|
|
43
|
+
// Redshift also support CONCAT function but when the string to concatenate is a space only thrown an error
|
|
44
|
+
function redshift(...args) {
|
|
45
|
+
return `(${args.join(' || ')})`;
|
|
46
|
+
}
|
|
47
|
+
function postgresql(...args) {
|
|
48
|
+
return sql(...args);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=concatenate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concatenate.js","sourceRoot":"","sources":["../../../src/functions/concatenate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAuB;IAC3C,UAAU,EAAE,aAAa;IACzB,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE;QACR;YACI,UAAU,EAAE,UAAU;YACtB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,CAAC,aAAa,CAAC;SAC7B;QACD;YACI,UAAU,EAAE,UAAU;YACtB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,CAAC,aAAa,CAAC;SAC7B;QACD;YACI,UAAU,EAAE,UAAU;YACtB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,CAAC,aAAa,CAAC;SAC7B;KACJ;IACD,UAAU,EAAE;QACR,aAAa;QACb,SAAS;QACT,QAAQ;QACR,UAAU;KACb;IACD,eAAe,EAAE,cAAc,CAAC,OAAO;CAC1C,CAAC;AAEF,SAAS,aAAa,CAAC,GAAG,IAAW;IACjC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;AACnC,CAAC;AAED,SAAS,GAAG,CAAC,GAAG,IAAW;IACvB,OAAO,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACxC,CAAC;AAED,SAAS,SAAS,CAAC,GAAG,IAAW;IAC7B,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,2GAA2G;AAC3G,SAAS,QAAQ,CAAC,GAAG,IAAW;IAC5B,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AACpC,CAAC;AAED,SAAS,UAAU,CAAC,GAAG,IAAW;IAC9B,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AST_PRIMITIVES } from '../constants';
|
|
2
|
+
import { isDateParam, isNumberParam, isStringParam, removeQuotes, } from '../utils';
|
|
3
|
+
import { greaterThanZero } from '../utils/greaterThanZero';
|
|
4
|
+
import { isAnAllowedValue } from '../utils/isAnAllowedValue';
|
|
5
|
+
/**
|
|
6
|
+
* `DATEADD` Adds a specific date part value to a given date.
|
|
7
|
+
*/
|
|
8
|
+
export const DATEADD = {
|
|
9
|
+
identifier: 'DATEADD',
|
|
10
|
+
parameters: [
|
|
11
|
+
{
|
|
12
|
+
identifier: 'DATE',
|
|
13
|
+
optional: false,
|
|
14
|
+
validator: [isDateParam],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
identifier: 'UNIT',
|
|
18
|
+
optional: false,
|
|
19
|
+
validator: [
|
|
20
|
+
isStringParam,
|
|
21
|
+
isAnAllowedValue(['Y', 'M', 'D', 'H', 'MI', 'S']),
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
identifier: 'INTERVAL',
|
|
26
|
+
optional: false,
|
|
27
|
+
validator: [isNumberParam, greaterThanZero],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
transpiler: {
|
|
31
|
+
elasticsearch,
|
|
32
|
+
snowflake,
|
|
33
|
+
redshift,
|
|
34
|
+
postgresql,
|
|
35
|
+
},
|
|
36
|
+
primitiveResult: AST_PRIMITIVES.DATE,
|
|
37
|
+
};
|
|
38
|
+
function elasticsearch(date, unit, interval) {
|
|
39
|
+
unit = removeQuotes(unit);
|
|
40
|
+
switch (unit) {
|
|
41
|
+
case 'Y':
|
|
42
|
+
return `${date}.plusYears(${interval})`;
|
|
43
|
+
case 'M':
|
|
44
|
+
return `${date}.plusMonths(${interval})`;
|
|
45
|
+
case 'D':
|
|
46
|
+
return `${date}.plusDays(${interval})`;
|
|
47
|
+
case 'H':
|
|
48
|
+
return `${date}.plusHours(${interval})`;
|
|
49
|
+
case 'MI':
|
|
50
|
+
return `${date}.plusMinutes(${interval})`;
|
|
51
|
+
case 'S':
|
|
52
|
+
return `${date}.plusSeconds(${interval})`;
|
|
53
|
+
default:
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function SQL(date, unit, interval) {
|
|
58
|
+
unit = removeQuotes(unit);
|
|
59
|
+
const sqlDateAdd = (date, unit) => `${date} + interval '${unit}'`;
|
|
60
|
+
switch (unit) {
|
|
61
|
+
case 'Y':
|
|
62
|
+
return sqlDateAdd(date, `${interval} year`);
|
|
63
|
+
case 'M':
|
|
64
|
+
return sqlDateAdd(date, `${interval} month`);
|
|
65
|
+
case 'D':
|
|
66
|
+
return sqlDateAdd(date, `${interval} day`);
|
|
67
|
+
case 'H':
|
|
68
|
+
return sqlDateAdd(date, `${interval} hour`);
|
|
69
|
+
case 'MI':
|
|
70
|
+
return sqlDateAdd(date, `${interval} minute`);
|
|
71
|
+
case 'S':
|
|
72
|
+
return sqlDateAdd(date, `${interval} second`);
|
|
73
|
+
default:
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function snowflake(date, unit, interval) {
|
|
78
|
+
return SQL(date, unit, interval);
|
|
79
|
+
}
|
|
80
|
+
function redshift(date, unit, interval) {
|
|
81
|
+
return SQL(date, unit, interval);
|
|
82
|
+
}
|
|
83
|
+
function postgresql(date, unit, interval) {
|
|
84
|
+
return SQL(date, unit, interval);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=dateadd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateadd.js","sourceRoot":"","sources":["../../../src/functions/dateadd.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACH,WAAW,EACX,aAAa,EACb,aAAa,EACb,YAAY,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAuB;IACvC,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE;QACR;YACI,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,CAAC,WAAW,CAAC;SAC3B;QACD;YACI,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE;gBACP,aAAa;gBACb,gBAAgB,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;aACpD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AC;QACjD,KAAK,GAAG;YACJ,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,QAAQ,MAAM,CAAC,CAAC;QAC/C,KAAK,GAAG;YACJ,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,QAAQ,OAAO,CAAC,CAAC;QAChD,KAAK,IAAI;YACL,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,QAAQ,SAAS,CAAC,CAAC;QAClD,KAAK,GAAG;YACJ,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,QAAQ,SAAS,CAAC,CAAC;QAClD;YACI,OAAO,EAAE,CAAC;KACjB;AACL,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,IAAkB,EAAE,QAAgB;IACjE,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,IAAkB,EAAE,QAAgB;IAChE,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,UAAU,CACf,IAAY,EACZ,IAAkB,EAClB,QAAgB;IAEhB,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AST_PRIMITIVES } from '../constants';
|
|
2
|
-
import { ERROR_LIST, ERROR_DICTIONARY } from '../errors/dictionary';
|
|
3
2
|
import { dateDif as ESdateDif } from '../utils/elasticsearch/scripts';
|
|
4
3
|
import { dateDif as SQLdateDif, dateDifPostgres } from '../utils/sql/scripts';
|
|
5
4
|
import { isDateParam, isStringParam, removeQuotes } from '../utils';
|
|
5
|
+
import { isAnAllowedValue } from '../utils/isAnAllowedValue';
|
|
6
6
|
/**
|
|
7
7
|
* Returns the number of the DATEDIF in a Date.
|
|
8
8
|
*/
|
|
@@ -22,7 +22,7 @@ export const DATEDIF = {
|
|
|
22
22
|
{
|
|
23
23
|
identifier: 'UNIT',
|
|
24
24
|
optional: false,
|
|
25
|
-
validator: [isStringParam,
|
|
25
|
+
validator: [isStringParam, isAnAllowedValue(['Y', 'M', 'D'])],
|
|
26
26
|
},
|
|
27
27
|
],
|
|
28
28
|
transpiler: {
|
|
@@ -33,17 +33,6 @@ export const DATEDIF = {
|
|
|
33
33
|
},
|
|
34
34
|
primitiveResult: AST_PRIMITIVES.NUMBER,
|
|
35
35
|
};
|
|
36
|
-
const YMD_UNIT_LIST = ['Y', 'M', 'D'];
|
|
37
|
-
function customValidatorYMD(param) {
|
|
38
|
-
param = removeQuotes(param);
|
|
39
|
-
const valid = YMD_UNIT_LIST.includes(param);
|
|
40
|
-
if (!valid) {
|
|
41
|
-
return Object.assign(Object.assign({ valid }, ERROR_DICTIONARY[ERROR_LIST.customDateDifParams]), { info: {
|
|
42
|
-
allowedValues: YMD_UNIT_LIST,
|
|
43
|
-
} });
|
|
44
|
-
}
|
|
45
|
-
return { valid };
|
|
46
|
-
}
|
|
47
36
|
function elasticsearch(start, end, unit) {
|
|
48
37
|
unit = removeQuotes(unit);
|
|
49
38
|
return ESdateDif(start, end, unit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datedif.js","sourceRoot":"","sources":["../../../src/functions/datedif.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datedif.js","sourceRoot":"","sources":["../../../src/functions/datedif.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;GA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