xpressions 0.27.0 → 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/README.md +1 -1
- package/dist/src/evaluate.d.ts +1 -1
- package/dist/src/evaluate.d.ts.map +1 -1
- package/dist/src/evaluate.js +9 -14
- package/dist/src/evaluate.js.map +1 -1
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces.js +5 -11
- package/dist/src/interfaces.js.map +1 -1
- package/dist/src/parse.d.ts +1 -1
- package/dist/src/parse.d.ts.map +1 -1
- package/dist/src/parse.js +8 -13
- package/dist/src/parse.js.map +1 -1
- package/dist/src/transform.d.ts +1 -1
- package/dist/src/transform.d.ts.map +1 -1
- package/dist/src/transform.js +10 -14
- package/dist/src/transform.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
> Variable expressions with date-math support
|
|
6
6
|
|
|
7
|
-
This a package within the [Teraslice](https://github.com/terascope/teraslice) monorepo. See our [documentation](https://terascope.github.io/teraslice/docs/packages/xpressions/overview) for more information or the [issues](https://github.com/terascope/teraslice/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%2Fxpressions) associated with this package
|
|
7
|
+
This is a package within the [Teraslice](https://github.com/terascope/teraslice) monorepo. See our [documentation](https://terascope.github.io/teraslice/docs/packages/xpressions/overview) for more information or the [issues](https://github.com/terascope/teraslice/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%2Fxpressions) associated with this package
|
|
8
8
|
|
|
9
9
|
## Contributing
|
|
10
10
|
|
package/dist/src/evaluate.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,EACH,cAAc,EAAkB,OAAO,
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,EACH,cAAc,EAAkB,OAAO,EACvC,YAAY,EACf,MAAM,iBAAiB,CAAC;AAGzB;;;;EAIE;AACF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAC,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAW/E;AAED;;;;EAIE;AACF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,GAAG,MAAM,CAQvF"}
|
package/dist/src/evaluate.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_1 = require("@terascope/utils");
|
|
5
|
-
const interfaces_1 = require("./interfaces");
|
|
6
|
-
const parse_1 = require("./parse");
|
|
1
|
+
import { hasOwn, TSError } from '@terascope/utils';
|
|
2
|
+
import { isVariableNode } from './interfaces.js';
|
|
3
|
+
import { parseExpression } from './parse.js';
|
|
7
4
|
/**
|
|
8
5
|
* Evaluate a single expression
|
|
9
6
|
*
|
|
10
7
|
* @returns the translated expression
|
|
11
8
|
*/
|
|
12
|
-
function evaluate(input, options) {
|
|
13
|
-
const expr = typeof input === 'string' ?
|
|
9
|
+
export function evaluate(input, options) {
|
|
10
|
+
const expr = typeof input === 'string' ? parseExpression(input) : input;
|
|
14
11
|
let output = '';
|
|
15
12
|
for (const node of expr.nodes) {
|
|
16
|
-
if (
|
|
13
|
+
if (isVariableNode(node)) {
|
|
17
14
|
output += evaluateVariableNode(node, options);
|
|
18
15
|
}
|
|
19
16
|
else {
|
|
@@ -22,20 +19,18 @@ function evaluate(input, options) {
|
|
|
22
19
|
}
|
|
23
20
|
return output;
|
|
24
21
|
}
|
|
25
|
-
exports.evaluate = evaluate;
|
|
26
22
|
/**
|
|
27
23
|
* Evaluate a single expression
|
|
28
24
|
*
|
|
29
25
|
* @returns the translated expression
|
|
30
26
|
*/
|
|
31
|
-
function evaluateVariableNode(node, { variables }) {
|
|
32
|
-
if (
|
|
27
|
+
export function evaluateVariableNode(node, { variables }) {
|
|
28
|
+
if (hasOwn(variables, node.value)) {
|
|
33
29
|
return variables[node.value];
|
|
34
30
|
}
|
|
35
|
-
throw new
|
|
31
|
+
throw new TSError(`Missing variable "${node.value}" in expression`, {
|
|
36
32
|
statusCode: 400,
|
|
37
33
|
context: { safe: true }
|
|
38
34
|
});
|
|
39
35
|
}
|
|
40
|
-
exports.evaluateVariableNode = evaluateVariableNode;
|
|
41
36
|
//# sourceMappingURL=evaluate.js.map
|
package/dist/src/evaluate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACa,cAAc,EAEjC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;EAIE;AACF,MAAM,UAAU,QAAQ,CAAC,KAA4B,EAAE,OAAgB;IACnE,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACxE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE;QAC3B,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;YACtB,MAAM,IAAI,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SACjD;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,CAAC,IAAI,SAAS,CAAC,CAAC;SAClE;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;EAIE;AACF,MAAM,UAAU,oBAAoB,CAAC,IAAkB,EAAE,EAAE,SAAS,EAAW;IAC3E,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;QAC/B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAChC;IACD,MAAM,IAAI,OAAO,CAAC,qBAAqB,IAAI,CAAC,KAAK,iBAAiB,EAAE;QAChE,UAAU,EAAE,GAAG;QACf,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;KAC1B,CAAC,CAAC;AACP,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './evaluate';
|
|
2
|
-
export * from './interfaces';
|
|
3
|
-
export * from './transform';
|
|
4
|
-
export * from './parse';
|
|
1
|
+
export * from './evaluate.js';
|
|
2
|
+
export * from './interfaces.js';
|
|
3
|
+
export * from './transform.js';
|
|
4
|
+
export * from './parse.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./evaluate"), exports);
|
|
18
|
-
__exportStar(require("./interfaces"), exports);
|
|
19
|
-
__exportStar(require("./transform"), exports);
|
|
20
|
-
__exportStar(require("./parse"), exports);
|
|
1
|
+
export * from './evaluate.js';
|
|
2
|
+
export * from './interfaces.js';
|
|
3
|
+
export * from './transform.js';
|
|
4
|
+
export * from './parse.js';
|
|
21
5
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/dist/src/interfaces.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isVariableNode = exports.isExpressionNode = exports.isLiteralNode = exports.NodeType = void 0;
|
|
4
|
-
var NodeType;
|
|
1
|
+
export var NodeType;
|
|
5
2
|
(function (NodeType) {
|
|
6
3
|
NodeType["LITERAL"] = "LITERAL";
|
|
7
4
|
NodeType["EXPRESSION"] = "EXPRESSION";
|
|
8
5
|
NodeType["VARIABLE"] = "VARIABLE";
|
|
9
|
-
})(NodeType || (
|
|
10
|
-
function isLiteralNode(node) {
|
|
6
|
+
})(NodeType || (NodeType = {}));
|
|
7
|
+
export function isLiteralNode(node) {
|
|
11
8
|
return node.type === NodeType.LITERAL;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
function isExpressionNode(node) {
|
|
10
|
+
export function isExpressionNode(node) {
|
|
15
11
|
return node.type === NodeType.EXPRESSION;
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
function isVariableNode(node) {
|
|
13
|
+
export function isVariableNode(node) {
|
|
19
14
|
return node.type === NodeType.VARIABLE;
|
|
20
15
|
}
|
|
21
|
-
exports.isVariableNode = isVariableNode;
|
|
22
16
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,+BAAmB,CAAA;IACnB,qCAAyB,CAAA;IACzB,iCAAqB,CAAA;AACzB,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAeD,MAAM,UAAU,aAAa,CAAC,IAAU;IACpC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,CAAC;AAC1C,CAAC;AAQD,MAAM,UAAU,gBAAgB,CAAC,IAAU;IACvC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,UAAU,CAAC;AAC7C,CAAC;AAQD,MAAM,UAAU,cAAc,CAAC,IAAU;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,CAAC;AAC3C,CAAC"}
|
package/dist/src/parse.d.ts
CHANGED
package/dist/src/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EAAE,cAAc,EAExB,MAAM,iBAAiB,CAAC;AAEzB;;;;EAIE;AACF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAmC1C;AAED;;;;EAIE;AACF,wBAAgB,eAAe,CAC3B,KAAK,EAAE,MAAM,EAAE,aAAa,SAAI,EAAE,YAAY,UAAQ,GACvD,cAAc,CAoChB"}
|
package/dist/src/parse.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseExpression = exports.parse = void 0;
|
|
4
|
-
const utils_1 = require("@terascope/utils");
|
|
5
|
-
const interfaces_1 = require("./interfaces");
|
|
1
|
+
import { TSError } from '@terascope/utils';
|
|
2
|
+
import { NodeType } from './interfaces.js';
|
|
6
3
|
/**
|
|
7
4
|
* Parse and validate an templated expression string
|
|
8
5
|
*
|
|
9
6
|
* @returns the parsed ast
|
|
10
7
|
*/
|
|
11
|
-
function parse(input) {
|
|
8
|
+
export function parse(input) {
|
|
12
9
|
const len = input.length;
|
|
13
10
|
const ast = [];
|
|
14
11
|
let chunkStart = 0;
|
|
@@ -17,7 +14,7 @@ function parse(input) {
|
|
|
17
14
|
if (!chunk)
|
|
18
15
|
return;
|
|
19
16
|
ast.push({
|
|
20
|
-
type:
|
|
17
|
+
type: NodeType.LITERAL,
|
|
21
18
|
value: chunk,
|
|
22
19
|
loc: {
|
|
23
20
|
start: chunkStart,
|
|
@@ -44,13 +41,12 @@ function parse(input) {
|
|
|
44
41
|
finishChunk(input.length);
|
|
45
42
|
return ast.slice();
|
|
46
43
|
}
|
|
47
|
-
exports.parse = parse;
|
|
48
44
|
/**
|
|
49
45
|
* Parse and validate an expression
|
|
50
46
|
*
|
|
51
47
|
* @returns return the parsed expression
|
|
52
48
|
*/
|
|
53
|
-
function parseExpression(input, startPosition = 0, isInTemplate = false) {
|
|
49
|
+
export function parseExpression(input, startPosition = 0, isInTemplate = false) {
|
|
54
50
|
let expression = '';
|
|
55
51
|
let terminated = false;
|
|
56
52
|
for (let j = startPosition; j < input.length; j++) {
|
|
@@ -66,10 +62,10 @@ function parseExpression(input, startPosition = 0, isInTemplate = false) {
|
|
|
66
62
|
const variable = expression.trim();
|
|
67
63
|
const scoped = variable.startsWith('@');
|
|
68
64
|
return {
|
|
69
|
-
type:
|
|
65
|
+
type: NodeType.EXPRESSION,
|
|
70
66
|
value: expression,
|
|
71
67
|
nodes: [{
|
|
72
|
-
type:
|
|
68
|
+
type: NodeType.VARIABLE,
|
|
73
69
|
scoped,
|
|
74
70
|
value: scoped ? variable : variable.replace(/^\$/, ''),
|
|
75
71
|
loc: {
|
|
@@ -83,12 +79,11 @@ function parseExpression(input, startPosition = 0, isInTemplate = false) {
|
|
|
83
79
|
}
|
|
84
80
|
};
|
|
85
81
|
}
|
|
86
|
-
throw new
|
|
82
|
+
throw new TSError('Expected } for end of expression, found EOL', {
|
|
87
83
|
statusCode: 400,
|
|
88
84
|
context: { safe: true }
|
|
89
85
|
});
|
|
90
86
|
}
|
|
91
|
-
exports.parseExpression = parseExpression;
|
|
92
87
|
function isEscaped(input, pos) {
|
|
93
88
|
if (pos === 0)
|
|
94
89
|
return false;
|
package/dist/src/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAEH,QAAQ,EACX,MAAM,iBAAiB,CAAC;AAEzB;;;;EAIE;A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A6C,EAAE;QAC7D,UAAU,EAAE,GAAG;QACf,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;KAC1B,CAAC,CAAC;AACP,CAAC;AAED,SAAS,SAAS,CAAC,KAAa,EAAE,GAAW;IACzC,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,IAAI,CAAC,GAAG,GAAG,CAAC;IACZ,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,OAAO,CAAC,EAAE,EAAE;QACR,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,IAAI,EAAE;YACf,eAAe,GAAG,CAAC,eAAe,CAAC;SACtC;aAAM;YACH,OAAO,eAAe,CAAC;SAC1B;KACJ;IACD,OAAO,eAAe,CAAC;AAC3B,CAAC"}
|
package/dist/src/transform.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EACL,OAAO,EACV,MAAM,iBAAiB,CAAC;AAGzB;;;;EAIE;AACF,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAQvE"}
|
package/dist/src/transform.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const evaluate_1 = require("./evaluate");
|
|
5
|
-
const interfaces_1 = require("./interfaces");
|
|
6
|
-
const parse_1 = require("./parse");
|
|
1
|
+
import { evaluate, evaluateVariableNode } from './evaluate.js';
|
|
2
|
+
import { isExpressionNode, isLiteralNode, isVariableNode } from './interfaces.js';
|
|
3
|
+
import { parse } from './parse.js';
|
|
7
4
|
/**
|
|
8
5
|
* Evaluate all of the templated variables in a xpression string
|
|
9
6
|
*
|
|
10
7
|
* @returns the input with the translated values
|
|
11
8
|
*/
|
|
12
|
-
function transform(input, options) {
|
|
13
|
-
const ast = typeof input === 'string' ?
|
|
9
|
+
export function transform(input, options) {
|
|
10
|
+
const ast = typeof input === 'string' ? parse(input) : input;
|
|
14
11
|
return ast.map((node) => {
|
|
15
|
-
if (
|
|
12
|
+
if (isLiteralNode(node))
|
|
16
13
|
return node.value;
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
14
|
+
if (isExpressionNode(node))
|
|
15
|
+
return evaluate(node, options);
|
|
16
|
+
if (isVariableNode(node))
|
|
17
|
+
return evaluateVariableNode(node, options);
|
|
21
18
|
throw new Error(`Unexpected expression node type ${node.type}`);
|
|
22
19
|
}).join('');
|
|
23
20
|
}
|
|
24
|
-
exports.transform = transform;
|
|
25
21
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACI,gBAAgB,EAAE,aAAa,EAC7B,cAAc,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;EAIE;AACF,MAAM,UAAU,SAAS,CAAC,KAAmB,EAAE,OAAgB;IAC3D,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAU,EAAE;QAC5B,IAAI,aAAa,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,gBAAgB,CAAC,IAAI,CAAC;YAAE,OAAO,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3D,IAAI,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xpressions",
|
|
3
3
|
"displayName": "Xpressions",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "Variable expressions with date-math support",
|
|
6
6
|
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/xpressions#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"repository": "git@github.com:terascope/teraslice.git",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "Terascope, LLC <info@terascope.io>",
|
|
13
|
+
"type": "module",
|
|
13
14
|
"main": "dist/src/index.js",
|
|
14
15
|
"typings": "dist/src/index.d.ts",
|
|
15
16
|
"files": [
|
|
@@ -23,10 +24,10 @@
|
|
|
23
24
|
"test:watch": "ts-scripts test --watch . --"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@terascope/utils": "^0.
|
|
27
|
+
"@terascope/utils": "^1.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@terascope/types": "^0.
|
|
30
|
+
"@terascope/types": "^1.0.0"
|
|
30
31
|
},
|
|
31
32
|
"engines": {
|
|
32
33
|
"node": ">=14.17.0",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
},
|
|
39
40
|
"srcMain": "src/index.ts",
|
|
40
41
|
"terascope": {
|
|
41
|
-
"testSuite": "unit",
|
|
42
|
+
"testSuite": "unit-esm",
|
|
42
43
|
"enableTypedoc": true
|
|
43
44
|
}
|
|
44
45
|
}
|