flowquery 1.0.35 → 1.0.37
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/dist/flowquery.min.js +1 -1
- package/dist/parsing/data_structures/lookup.d.ts.map +1 -1
- package/dist/parsing/data_structures/lookup.js +5 -1
- package/dist/parsing/data_structures/lookup.js.map +1 -1
- package/dist/parsing/functions/coalesce.d.ts +16 -0
- package/dist/parsing/functions/coalesce.d.ts.map +1 -0
- package/dist/parsing/functions/coalesce.js +60 -0
- package/dist/parsing/functions/coalesce.js.map +1 -0
- package/dist/parsing/functions/date.d.ts +20 -0
- package/dist/parsing/functions/date.d.ts.map +1 -0
- package/dist/parsing/functions/date.js +69 -0
- package/dist/parsing/functions/date.js.map +1 -0
- package/dist/parsing/functions/datetime.d.ts +20 -0
- package/dist/parsing/functions/datetime.d.ts.map +1 -0
- package/dist/parsing/functions/datetime.js +69 -0
- package/dist/parsing/functions/datetime.js.map +1 -0
- package/dist/parsing/functions/duration.d.ts +7 -0
- package/dist/parsing/functions/duration.d.ts.map +1 -0
- package/dist/parsing/functions/duration.js +145 -0
- package/dist/parsing/functions/duration.js.map +1 -0
- package/dist/parsing/functions/element_id.d.ts +7 -0
- package/dist/parsing/functions/element_id.d.ts.map +1 -0
- package/dist/parsing/functions/element_id.js +58 -0
- package/dist/parsing/functions/element_id.js.map +1 -0
- package/dist/parsing/functions/function_factory.d.ts +20 -0
- package/dist/parsing/functions/function_factory.d.ts.map +1 -1
- package/dist/parsing/functions/function_factory.js +20 -0
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/functions/head.d.ts +7 -0
- package/dist/parsing/functions/head.d.ts.map +1 -0
- package/dist/parsing/functions/head.js +53 -0
- package/dist/parsing/functions/head.js.map +1 -0
- package/dist/parsing/functions/id.d.ts +7 -0
- package/dist/parsing/functions/id.d.ts.map +1 -0
- package/dist/parsing/functions/id.js +58 -0
- package/dist/parsing/functions/id.js.map +1 -0
- package/dist/parsing/functions/last.d.ts +7 -0
- package/dist/parsing/functions/last.d.ts.map +1 -0
- package/dist/parsing/functions/last.js +53 -0
- package/dist/parsing/functions/last.js.map +1 -0
- package/dist/parsing/functions/localdatetime.d.ts +19 -0
- package/dist/parsing/functions/localdatetime.d.ts.map +1 -0
- package/dist/parsing/functions/localdatetime.js +69 -0
- package/dist/parsing/functions/localdatetime.js.map +1 -0
- package/dist/parsing/functions/localtime.d.ts +18 -0
- package/dist/parsing/functions/localtime.d.ts.map +1 -0
- package/dist/parsing/functions/localtime.js +65 -0
- package/dist/parsing/functions/localtime.js.map +1 -0
- package/dist/parsing/functions/max.d.ts +14 -0
- package/dist/parsing/functions/max.d.ts.map +1 -0
- package/dist/parsing/functions/max.js +51 -0
- package/dist/parsing/functions/max.js.map +1 -0
- package/dist/parsing/functions/min.d.ts +14 -0
- package/dist/parsing/functions/min.d.ts.map +1 -0
- package/dist/parsing/functions/min.js +51 -0
- package/dist/parsing/functions/min.js.map +1 -0
- package/dist/parsing/functions/nodes.d.ts +7 -0
- package/dist/parsing/functions/nodes.d.ts.map +1 -0
- package/dist/parsing/functions/nodes.js +63 -0
- package/dist/parsing/functions/nodes.js.map +1 -0
- package/dist/parsing/functions/properties.d.ts +7 -0
- package/dist/parsing/functions/properties.d.ts.map +1 -0
- package/dist/parsing/functions/properties.js +74 -0
- package/dist/parsing/functions/properties.js.map +1 -0
- package/dist/parsing/functions/relationships.d.ts +7 -0
- package/dist/parsing/functions/relationships.d.ts.map +1 -0
- package/dist/parsing/functions/relationships.js +61 -0
- package/dist/parsing/functions/relationships.js.map +1 -0
- package/dist/parsing/functions/tail.d.ts +7 -0
- package/dist/parsing/functions/tail.d.ts.map +1 -0
- package/dist/parsing/functions/tail.js +50 -0
- package/dist/parsing/functions/tail.js.map +1 -0
- package/dist/parsing/functions/temporal_utils.d.ts +39 -0
- package/dist/parsing/functions/temporal_utils.d.ts.map +1 -0
- package/dist/parsing/functions/temporal_utils.js +168 -0
- package/dist/parsing/functions/temporal_utils.js.map +1 -0
- package/dist/parsing/functions/time.d.ts +18 -0
- package/dist/parsing/functions/time.d.ts.map +1 -0
- package/dist/parsing/functions/time.js +65 -0
- package/dist/parsing/functions/time.js.map +1 -0
- package/dist/parsing/functions/timestamp.d.ts +15 -0
- package/dist/parsing/functions/timestamp.d.ts.map +1 -0
- package/dist/parsing/functions/timestamp.js +48 -0
- package/dist/parsing/functions/timestamp.js.map +1 -0
- package/dist/parsing/functions/to_float.d.ts +7 -0
- package/dist/parsing/functions/to_float.d.ts.map +1 -0
- package/dist/parsing/functions/to_float.js +61 -0
- package/dist/parsing/functions/to_float.js.map +1 -0
- package/dist/parsing/functions/to_integer.d.ts +7 -0
- package/dist/parsing/functions/to_integer.d.ts.map +1 -0
- package/dist/parsing/functions/to_integer.js +61 -0
- package/dist/parsing/functions/to_integer.js.map +1 -0
- package/docs/flowquery.min.js +1 -1
- package/flowquery-py/pyproject.toml +1 -1
- package/flowquery-py/src/parsing/data_structures/lookup.py +2 -0
- package/flowquery-py/src/parsing/functions/__init__.py +40 -2
- package/flowquery-py/src/parsing/functions/coalesce.py +43 -0
- package/flowquery-py/src/parsing/functions/date_.py +61 -0
- package/flowquery-py/src/parsing/functions/datetime_.py +62 -0
- package/flowquery-py/src/parsing/functions/duration.py +159 -0
- package/flowquery-py/src/parsing/functions/element_id.py +50 -0
- package/flowquery-py/src/parsing/functions/head.py +39 -0
- package/flowquery-py/src/parsing/functions/id_.py +49 -0
- package/flowquery-py/src/parsing/functions/last.py +39 -0
- package/flowquery-py/src/parsing/functions/localdatetime.py +60 -0
- package/flowquery-py/src/parsing/functions/localtime.py +57 -0
- package/flowquery-py/src/parsing/functions/max_.py +49 -0
- package/flowquery-py/src/parsing/functions/min_.py +49 -0
- package/flowquery-py/src/parsing/functions/nodes.py +48 -0
- package/flowquery-py/src/parsing/functions/properties.py +50 -0
- package/flowquery-py/src/parsing/functions/relationships.py +46 -0
- package/flowquery-py/src/parsing/functions/tail.py +37 -0
- package/flowquery-py/src/parsing/functions/temporal_utils.py +186 -0
- package/flowquery-py/src/parsing/functions/time_.py +57 -0
- package/flowquery-py/src/parsing/functions/timestamp.py +37 -0
- package/flowquery-py/src/parsing/functions/to_float.py +46 -0
- package/flowquery-py/src/parsing/functions/to_integer.py +46 -0
- package/flowquery-py/tests/compute/test_runner.py +834 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/package.json +1 -1
- package/src/parsing/data_structures/lookup.ts +8 -4
- package/src/parsing/functions/coalesce.ts +49 -0
- package/src/parsing/functions/date.ts +63 -0
- package/src/parsing/functions/datetime.ts +63 -0
- package/src/parsing/functions/duration.ts +143 -0
- package/src/parsing/functions/element_id.ts +51 -0
- package/src/parsing/functions/function_factory.ts +20 -0
- package/src/parsing/functions/head.ts +42 -0
- package/src/parsing/functions/id.ts +51 -0
- package/src/parsing/functions/last.ts +42 -0
- package/src/parsing/functions/localdatetime.ts +63 -0
- package/src/parsing/functions/localtime.ts +58 -0
- package/src/parsing/functions/max.ts +37 -0
- package/src/parsing/functions/min.ts +37 -0
- package/src/parsing/functions/nodes.ts +54 -0
- package/src/parsing/functions/properties.ts +56 -0
- package/src/parsing/functions/relationships.ts +52 -0
- package/src/parsing/functions/tail.ts +39 -0
- package/src/parsing/functions/temporal_utils.ts +180 -0
- package/src/parsing/functions/time.ts +58 -0
- package/src/parsing/functions/timestamp.ts +37 -0
- package/src/parsing/functions/to_float.ts +50 -0
- package/src/parsing/functions/to_integer.ts +50 -0
- package/tests/compute/runner.test.ts +726 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
import { buildTimeObject, parseTemporalArg } from "./temporal_utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns a local time value (no timezone offset).
|
|
7
|
+
* When called with no arguments, returns the current local time.
|
|
8
|
+
* When called with a string argument, parses it.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* RETURN localtime() AS now
|
|
13
|
+
* RETURN localtime('14:30:00') AS t
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
@FunctionDef({
|
|
17
|
+
description:
|
|
18
|
+
"Returns a local time value (no timezone). With no arguments returns the current local time. " +
|
|
19
|
+
"Accepts an ISO 8601 time string or a map of components.",
|
|
20
|
+
category: "scalar",
|
|
21
|
+
parameters: [
|
|
22
|
+
{
|
|
23
|
+
name: "input",
|
|
24
|
+
description: "Optional. An ISO 8601 time string (HH:MM:SS) or a map of components.",
|
|
25
|
+
type: "string",
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
output: {
|
|
30
|
+
description: "A time object with properties: hour, minute, second, millisecond, formatted",
|
|
31
|
+
type: "object",
|
|
32
|
+
},
|
|
33
|
+
examples: [
|
|
34
|
+
"RETURN localtime() AS now",
|
|
35
|
+
"RETURN localtime('14:30:00') AS t",
|
|
36
|
+
"WITH localtime() AS t RETURN t.hour, t.minute",
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
class LocalTime extends Function {
|
|
40
|
+
constructor() {
|
|
41
|
+
super("localtime");
|
|
42
|
+
this._expectedParameterCount = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public value(): any {
|
|
46
|
+
const children = this.getChildren();
|
|
47
|
+
if (children.length > 1) {
|
|
48
|
+
throw new Error("localtime() accepts at most one argument");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const d: Date =
|
|
52
|
+
children.length === 1 ? parseTemporalArg(children[0].value(), "localtime") : new Date();
|
|
53
|
+
|
|
54
|
+
return buildTimeObject(d, false);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default LocalTime;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import AggregateFunction from "./aggregate_function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
import ReducerElement from "./reducer_element";
|
|
4
|
+
|
|
5
|
+
class MaxReducerElement extends ReducerElement {
|
|
6
|
+
private _value: any = null;
|
|
7
|
+
public get value(): any {
|
|
8
|
+
return this._value;
|
|
9
|
+
}
|
|
10
|
+
public set value(value: any) {
|
|
11
|
+
if (this._value === null || value > this._value) {
|
|
12
|
+
this._value = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@FunctionDef({
|
|
18
|
+
description: "Returns the maximum value across grouped rows",
|
|
19
|
+
category: "aggregate",
|
|
20
|
+
parameters: [{ name: "value", description: "Value to compare", type: "number" }],
|
|
21
|
+
output: { description: "Maximum value", type: "number", example: 10 },
|
|
22
|
+
examples: ["WITH [3, 1, 2] AS nums UNWIND nums AS n RETURN max(n)"],
|
|
23
|
+
})
|
|
24
|
+
class Max extends AggregateFunction {
|
|
25
|
+
constructor() {
|
|
26
|
+
super("max");
|
|
27
|
+
this._expectedParameterCount = 1;
|
|
28
|
+
}
|
|
29
|
+
public reduce(element: MaxReducerElement): void {
|
|
30
|
+
element.value = this.firstChild().value();
|
|
31
|
+
}
|
|
32
|
+
public element(): MaxReducerElement {
|
|
33
|
+
return new MaxReducerElement();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Max;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import AggregateFunction from "./aggregate_function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
import ReducerElement from "./reducer_element";
|
|
4
|
+
|
|
5
|
+
class MinReducerElement extends ReducerElement {
|
|
6
|
+
private _value: any = null;
|
|
7
|
+
public get value(): any {
|
|
8
|
+
return this._value;
|
|
9
|
+
}
|
|
10
|
+
public set value(value: any) {
|
|
11
|
+
if (this._value === null || value < this._value) {
|
|
12
|
+
this._value = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@FunctionDef({
|
|
18
|
+
description: "Returns the minimum value across grouped rows",
|
|
19
|
+
category: "aggregate",
|
|
20
|
+
parameters: [{ name: "value", description: "Value to compare", type: "number" }],
|
|
21
|
+
output: { description: "Minimum value", type: "number", example: 1 },
|
|
22
|
+
examples: ["WITH [3, 1, 2] AS nums UNWIND nums AS n RETURN min(n)"],
|
|
23
|
+
})
|
|
24
|
+
class Min extends AggregateFunction {
|
|
25
|
+
constructor() {
|
|
26
|
+
super("min");
|
|
27
|
+
this._expectedParameterCount = 1;
|
|
28
|
+
}
|
|
29
|
+
public reduce(element: MinReducerElement): void {
|
|
30
|
+
element.value = this.firstChild().value();
|
|
31
|
+
}
|
|
32
|
+
public element(): MinReducerElement {
|
|
33
|
+
return new MinReducerElement();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Min;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Returns all nodes in a path as an array",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{
|
|
9
|
+
name: "path",
|
|
10
|
+
description: "A path value returned from a graph pattern match",
|
|
11
|
+
type: "array",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
output: {
|
|
15
|
+
description: "Array of node records",
|
|
16
|
+
type: "array",
|
|
17
|
+
example: "[{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]",
|
|
18
|
+
},
|
|
19
|
+
examples: ["MATCH p=(:Person)-[:KNOWS]-(:Person) RETURN nodes(p)"],
|
|
20
|
+
})
|
|
21
|
+
class Nodes extends Function {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("nodes");
|
|
24
|
+
this._expectedParameterCount = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public value(): any {
|
|
28
|
+
const path = this.getChildren()[0].value();
|
|
29
|
+
if (path === null || path === undefined) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(path)) {
|
|
33
|
+
throw new Error("nodes() expects a path (array)");
|
|
34
|
+
}
|
|
35
|
+
// A path is an array of alternating node and relationship objects:
|
|
36
|
+
// [node, rel, node, rel, node, ...]
|
|
37
|
+
// Nodes are plain NodeRecords (have 'id' but not 'type'/'startNode'/'endNode')
|
|
38
|
+
// Relationships are RelationshipMatchRecords (have 'type', 'startNode', 'endNode', 'properties')
|
|
39
|
+
return path.filter((element: any) => {
|
|
40
|
+
if (element === null || element === undefined || typeof element !== "object") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// A RelationshipMatchRecord has type, startNode, endNode, properties
|
|
44
|
+
return !(
|
|
45
|
+
"type" in element &&
|
|
46
|
+
"startNode" in element &&
|
|
47
|
+
"endNode" in element &&
|
|
48
|
+
"properties" in element
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default Nodes;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description:
|
|
6
|
+
"Returns a map containing all the properties of a node, relationship, or map. For nodes and relationships, internal identifiers are excluded.",
|
|
7
|
+
category: "scalar",
|
|
8
|
+
parameters: [
|
|
9
|
+
{
|
|
10
|
+
name: "entity",
|
|
11
|
+
description: "A node, relationship, or map to extract properties from",
|
|
12
|
+
type: "object",
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
output: {
|
|
16
|
+
description: "Map of properties",
|
|
17
|
+
type: "object",
|
|
18
|
+
example: "{ name: 'Alice', age: 30 }",
|
|
19
|
+
},
|
|
20
|
+
examples: [
|
|
21
|
+
"MATCH (n:Person) RETURN properties(n)",
|
|
22
|
+
"WITH { name: 'Alice', age: 30 } AS obj RETURN properties(obj)",
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
class Properties extends Function {
|
|
26
|
+
constructor() {
|
|
27
|
+
super("properties");
|
|
28
|
+
this._expectedParameterCount = 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public value(): any {
|
|
32
|
+
const obj = this.getChildren()[0].value();
|
|
33
|
+
if (obj === null || obj === undefined) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (typeof obj !== "object" || Array.isArray(obj)) {
|
|
37
|
+
throw new Error("properties() expects a node, relationship, or map");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// If it's a RelationshipMatchRecord (has type, startNode, endNode, properties)
|
|
41
|
+
if ("type" in obj && "startNode" in obj && "endNode" in obj && "properties" in obj) {
|
|
42
|
+
return obj.properties;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If it's a node record (has id field), exclude id
|
|
46
|
+
if ("id" in obj) {
|
|
47
|
+
const { id, ...props } = obj;
|
|
48
|
+
return props;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Otherwise, treat as a plain map and return a copy
|
|
52
|
+
return { ...obj };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default Properties;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Returns all relationships in a path as an array",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{
|
|
9
|
+
name: "path",
|
|
10
|
+
description: "A path value returned from a graph pattern match",
|
|
11
|
+
type: "array",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
output: {
|
|
15
|
+
description: "Array of relationship records",
|
|
16
|
+
type: "array",
|
|
17
|
+
example: "[{ type: 'KNOWS', properties: { since: '2020' } }]",
|
|
18
|
+
},
|
|
19
|
+
examples: ["MATCH p=(:Person)-[:KNOWS]-(:Person) RETURN relationships(p)"],
|
|
20
|
+
})
|
|
21
|
+
class Relationships extends Function {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("relationships");
|
|
24
|
+
this._expectedParameterCount = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public value(): any {
|
|
28
|
+
const path = this.getChildren()[0].value();
|
|
29
|
+
if (path === null || path === undefined) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(path)) {
|
|
33
|
+
throw new Error("relationships() expects a path (array)");
|
|
34
|
+
}
|
|
35
|
+
// A path is an array of alternating node and relationship objects:
|
|
36
|
+
// [node, rel, node, rel, node, ...]
|
|
37
|
+
// Relationships are RelationshipMatchRecords (have 'type', 'startNode', 'endNode', 'properties')
|
|
38
|
+
return path.filter((element: any) => {
|
|
39
|
+
if (element === null || element === undefined || typeof element !== "object") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return (
|
|
43
|
+
"type" in element &&
|
|
44
|
+
"startNode" in element &&
|
|
45
|
+
"endNode" in element &&
|
|
46
|
+
"properties" in element
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default Relationships;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Returns all elements of a list except the first",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{
|
|
9
|
+
name: "list",
|
|
10
|
+
description: "The list to get all but the first element from",
|
|
11
|
+
type: "array",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
output: {
|
|
15
|
+
description: "All elements except the first",
|
|
16
|
+
type: "array",
|
|
17
|
+
example: "[2, 3]",
|
|
18
|
+
},
|
|
19
|
+
examples: ["RETURN tail([1, 2, 3])", "WITH ['a', 'b', 'c'] AS items RETURN tail(items)"],
|
|
20
|
+
})
|
|
21
|
+
class Tail extends Function {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("tail");
|
|
24
|
+
this._expectedParameterCount = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public value(): any {
|
|
28
|
+
const val = this.getChildren()[0].value();
|
|
29
|
+
if (val === null || val === undefined) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(val)) {
|
|
33
|
+
throw new Error("tail() expects a list");
|
|
34
|
+
}
|
|
35
|
+
return val.slice(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default Tail;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions for temporal (date/time) operations.
|
|
3
|
+
*
|
|
4
|
+
* These helpers are used by the datetime, date, time, localdatetime,
|
|
5
|
+
* localtime, and timestamp functions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Computes the ISO day of the week (1 = Monday, 7 = Sunday).
|
|
10
|
+
*/
|
|
11
|
+
function isoDayOfWeek(d: Date): number {
|
|
12
|
+
const jsDay = d.getDay(); // 0 = Sunday, 6 = Saturday
|
|
13
|
+
return jsDay === 0 ? 7 : jsDay;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Computes the day of the year (1-based).
|
|
18
|
+
*/
|
|
19
|
+
function dayOfYear(d: Date): number {
|
|
20
|
+
const start = new Date(d.getFullYear(), 0, 0);
|
|
21
|
+
const diff = d.getTime() - start.getTime();
|
|
22
|
+
const oneDay = 1000 * 60 * 60 * 24;
|
|
23
|
+
return Math.floor(diff / oneDay);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Computes the quarter (1-4) from a month (0-11).
|
|
28
|
+
*/
|
|
29
|
+
function quarter(month: number): number {
|
|
30
|
+
return Math.floor(month / 3) + 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pads a number to a given width with leading zeros.
|
|
35
|
+
*/
|
|
36
|
+
function pad(n: number, width: number = 2): string {
|
|
37
|
+
return String(n).padStart(width, "0");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Formats a timezone offset in ±HH:MM format.
|
|
42
|
+
*/
|
|
43
|
+
function formatTimezoneOffset(d: Date): string {
|
|
44
|
+
const offset = -d.getTimezoneOffset();
|
|
45
|
+
if (offset === 0) return "Z";
|
|
46
|
+
const sign = offset > 0 ? "+" : "-";
|
|
47
|
+
const absOffset = Math.abs(offset);
|
|
48
|
+
const hours = Math.floor(absOffset / 60);
|
|
49
|
+
const minutes = absOffset % 60;
|
|
50
|
+
return `${sign}${pad(hours)}:${pad(minutes)}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Parses a temporal argument (string or map) into a Date object.
|
|
55
|
+
*
|
|
56
|
+
* @param arg - The argument to parse (string or object with year/month/day/hour/minute/second/millisecond)
|
|
57
|
+
* @param fnName - The calling function name for error messages
|
|
58
|
+
* @returns A Date object
|
|
59
|
+
*/
|
|
60
|
+
export function parseTemporalArg(arg: any, fnName: string): Date {
|
|
61
|
+
if (typeof arg === "string") {
|
|
62
|
+
const d = new Date(arg);
|
|
63
|
+
if (isNaN(d.getTime())) {
|
|
64
|
+
throw new Error(`${fnName}(): Invalid temporal string: '${arg}'`);
|
|
65
|
+
}
|
|
66
|
+
return d;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof arg === "number") {
|
|
70
|
+
// Treat as epoch milliseconds
|
|
71
|
+
return new Date(arg);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
|
|
75
|
+
// Map-style construction: {year, month, day, hour, minute, second, millisecond}
|
|
76
|
+
const year = arg.year ?? new Date().getFullYear();
|
|
77
|
+
const month = (arg.month ?? 1) - 1; // JS months are 0-based
|
|
78
|
+
const day = arg.day ?? 1;
|
|
79
|
+
const hour = arg.hour ?? 0;
|
|
80
|
+
const minute = arg.minute ?? 0;
|
|
81
|
+
const second = arg.second ?? 0;
|
|
82
|
+
const millisecond = arg.millisecond ?? 0;
|
|
83
|
+
return new Date(year, month, day, hour, minute, second, millisecond);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw new Error(
|
|
87
|
+
`${fnName}(): Expected a string, number (epoch millis), or map argument, got ${typeof arg}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Builds a datetime result object with full temporal properties.
|
|
93
|
+
*
|
|
94
|
+
* @param d - The Date object
|
|
95
|
+
* @param utc - If true, use UTC values; if false, use local values
|
|
96
|
+
* @returns An object with year, month, day, hour, minute, second, millisecond,
|
|
97
|
+
* epochMillis, epochSeconds, dayOfWeek, dayOfYear, quarter, formatted
|
|
98
|
+
*/
|
|
99
|
+
export function buildDatetimeObject(d: Date, utc: boolean): Record<string, any> {
|
|
100
|
+
const year = utc ? d.getUTCFullYear() : d.getFullYear();
|
|
101
|
+
const month = utc ? d.getUTCMonth() + 1 : d.getMonth() + 1;
|
|
102
|
+
const day = utc ? d.getUTCDate() : d.getDate();
|
|
103
|
+
const hour = utc ? d.getUTCHours() : d.getHours();
|
|
104
|
+
const minute = utc ? d.getUTCMinutes() : d.getMinutes();
|
|
105
|
+
const second = utc ? d.getUTCSeconds() : d.getSeconds();
|
|
106
|
+
const millisecond = utc ? d.getUTCMilliseconds() : d.getMilliseconds();
|
|
107
|
+
|
|
108
|
+
const datePart = new Date(year, month - 1, day);
|
|
109
|
+
|
|
110
|
+
const formatted = utc
|
|
111
|
+
? d.toISOString()
|
|
112
|
+
: `${year}-${pad(month)}-${pad(day)}T${pad(hour)}:${pad(minute)}:${pad(second)}.${pad(millisecond, 3)}`;
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
year,
|
|
116
|
+
month,
|
|
117
|
+
day,
|
|
118
|
+
hour,
|
|
119
|
+
minute,
|
|
120
|
+
second,
|
|
121
|
+
millisecond,
|
|
122
|
+
epochMillis: d.getTime(),
|
|
123
|
+
epochSeconds: Math.floor(d.getTime() / 1000),
|
|
124
|
+
dayOfWeek: isoDayOfWeek(datePart),
|
|
125
|
+
dayOfYear: dayOfYear(datePart),
|
|
126
|
+
quarter: quarter(month - 1),
|
|
127
|
+
formatted,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Builds a date result object (no time component).
|
|
133
|
+
*
|
|
134
|
+
* @param d - The Date object
|
|
135
|
+
* @returns An object with year, month, day, epochMillis, dayOfWeek, dayOfYear, quarter, formatted
|
|
136
|
+
*/
|
|
137
|
+
export function buildDateObject(d: Date): Record<string, any> {
|
|
138
|
+
const year = d.getFullYear();
|
|
139
|
+
const month = d.getMonth() + 1;
|
|
140
|
+
const day = d.getDate();
|
|
141
|
+
|
|
142
|
+
// Strip time component for epoch calculation
|
|
143
|
+
const dateOnly = new Date(year, month - 1, day);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
year,
|
|
147
|
+
month,
|
|
148
|
+
day,
|
|
149
|
+
epochMillis: dateOnly.getTime(),
|
|
150
|
+
dayOfWeek: isoDayOfWeek(dateOnly),
|
|
151
|
+
dayOfYear: dayOfYear(dateOnly),
|
|
152
|
+
quarter: quarter(month - 1),
|
|
153
|
+
formatted: `${year}-${pad(month)}-${pad(day)}`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Builds a time result object (no date component).
|
|
159
|
+
*
|
|
160
|
+
* @param d - The Date object
|
|
161
|
+
* @param utc - If true, use UTC values; if false, use local values
|
|
162
|
+
* @returns An object with hour, minute, second, millisecond, formatted
|
|
163
|
+
*/
|
|
164
|
+
export function buildTimeObject(d: Date, utc: boolean): Record<string, any> {
|
|
165
|
+
const hour = utc ? d.getUTCHours() : d.getHours();
|
|
166
|
+
const minute = utc ? d.getUTCMinutes() : d.getMinutes();
|
|
167
|
+
const second = utc ? d.getUTCSeconds() : d.getSeconds();
|
|
168
|
+
const millisecond = utc ? d.getUTCMilliseconds() : d.getMilliseconds();
|
|
169
|
+
|
|
170
|
+
const timePart = `${pad(hour)}:${pad(minute)}:${pad(second)}.${pad(millisecond, 3)}`;
|
|
171
|
+
const formatted = utc ? `${timePart}Z` : timePart;
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
hour,
|
|
175
|
+
minute,
|
|
176
|
+
second,
|
|
177
|
+
millisecond,
|
|
178
|
+
formatted,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
import { buildTimeObject, parseTemporalArg } from "./temporal_utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns a time value (with timezone offset awareness).
|
|
7
|
+
* When called with no arguments, returns the current UTC time.
|
|
8
|
+
* When called with a string argument, parses it as an ISO 8601 time.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* RETURN time() AS now
|
|
13
|
+
* RETURN time('12:30:00') AS t
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
@FunctionDef({
|
|
17
|
+
description:
|
|
18
|
+
"Returns a time value. With no arguments returns the current UTC time. " +
|
|
19
|
+
"Accepts an ISO 8601 time string or a map of components (hour, minute, second, millisecond).",
|
|
20
|
+
category: "scalar",
|
|
21
|
+
parameters: [
|
|
22
|
+
{
|
|
23
|
+
name: "input",
|
|
24
|
+
description: "Optional. An ISO 8601 time string (HH:MM:SS) or a map of components.",
|
|
25
|
+
type: "string",
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
output: {
|
|
30
|
+
description: "A time object with properties: hour, minute, second, millisecond, formatted",
|
|
31
|
+
type: "object",
|
|
32
|
+
},
|
|
33
|
+
examples: [
|
|
34
|
+
"RETURN time() AS now",
|
|
35
|
+
"RETURN time('12:30:00') AS t",
|
|
36
|
+
"WITH time() AS t RETURN t.hour, t.minute",
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
class Time extends Function {
|
|
40
|
+
constructor() {
|
|
41
|
+
super("time");
|
|
42
|
+
this._expectedParameterCount = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public value(): any {
|
|
46
|
+
const children = this.getChildren();
|
|
47
|
+
if (children.length > 1) {
|
|
48
|
+
throw new Error("time() accepts at most one argument");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const d: Date =
|
|
52
|
+
children.length === 1 ? parseTemporalArg(children[0].value(), "time") : new Date();
|
|
53
|
+
|
|
54
|
+
return buildTimeObject(d, true);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default Time;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the number of milliseconds since the Unix epoch (1970-01-01T00:00:00Z).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* RETURN timestamp() AS ts
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
@FunctionDef({
|
|
13
|
+
description: "Returns the number of milliseconds since the Unix epoch (1970-01-01T00:00:00Z).",
|
|
14
|
+
category: "scalar",
|
|
15
|
+
parameters: [],
|
|
16
|
+
output: {
|
|
17
|
+
description: "Milliseconds since Unix epoch",
|
|
18
|
+
type: "number",
|
|
19
|
+
example: 1718450000000,
|
|
20
|
+
},
|
|
21
|
+
examples: [
|
|
22
|
+
"RETURN timestamp() AS ts",
|
|
23
|
+
"WITH timestamp() AS before, timestamp() AS after RETURN after - before",
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
class Timestamp extends Function {
|
|
27
|
+
constructor() {
|
|
28
|
+
super("timestamp");
|
|
29
|
+
this._expectedParameterCount = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public value(): any {
|
|
33
|
+
return Date.now();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Timestamp;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
|
+
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Converts a value to a floating point number",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{
|
|
9
|
+
name: "value",
|
|
10
|
+
description: "The value to convert to a float",
|
|
11
|
+
type: "any",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
output: {
|
|
15
|
+
description: "The floating point representation of the value",
|
|
16
|
+
type: "number",
|
|
17
|
+
example: "3.14",
|
|
18
|
+
},
|
|
19
|
+
examples: ['RETURN toFloat("3.14")', "RETURN toFloat(42)", "RETURN toFloat(true)"],
|
|
20
|
+
})
|
|
21
|
+
class ToFloat extends Function {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("tofloat");
|
|
24
|
+
this._expectedParameterCount = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public value(): any {
|
|
28
|
+
const val = this.getChildren()[0].value();
|
|
29
|
+
if (val === null || val === undefined) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (typeof val === "boolean") {
|
|
33
|
+
return val ? 1.0 : 0.0;
|
|
34
|
+
}
|
|
35
|
+
if (typeof val === "number") {
|
|
36
|
+
return val;
|
|
37
|
+
}
|
|
38
|
+
if (typeof val === "string") {
|
|
39
|
+
const trimmed = val.trim();
|
|
40
|
+
const parsed = Number(trimmed);
|
|
41
|
+
if (isNaN(parsed)) {
|
|
42
|
+
throw new Error(`Cannot convert string "${val}" to float`);
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("toFloat() expects a number, string, or boolean");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default ToFloat;
|