Skip to content

Commit 3f1c5b8

Browse files
chore(remap): docs for the Remap type functions (#6446)
Co-authored-by: binarylogic <bjohnson@binarylogic.com>
1 parent d21631c commit 3f1c5b8

33 files changed

+347
-75
lines changed

docs/reference/remap.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ package metadata
3535
warnings?: [string, ...string]
3636
}
3737

38-
#Type: "any" | "array" | "boolean" | "float" | "integer" | "map" | "null" | "path" | "string" | "regex" | "timestamp"
38+
#Type: "any" | "array" | "boolean" | "float" | "integer" | "object" | "null" | "path" | "string" | "regex" | "timestamp"
3939

4040
concepts: _
4141
description: string

docs/reference/remap/expressions/assignment.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ remap: expressions: assignment: {
5454
description: """
5555
If the `target` is a variable, the `expression` can be any expression.
5656
57-
If the `target` is a path, the `expression` can be any expression that returns a supported map
57+
If the `target` is a path, the `expression` can be any expression that returns a supported object
5858
value type (i.e. not a regular expression).
5959
"""
6060
}

docs/reference/remap/expressions/block.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ remap: expressions: block: {
55
description: """
66
A _block_ expression is a sequence of one or more expressions within matching brace brackets.
77
8-
Blocks can't be empty. Instead, empty blocks (`{}`) are treated as blank maps.
8+
Blocks can't be empty. Instead, empty blocks (`{}`) are treated as blank objects.
99
"""
1010
return: """
1111
Returns the result of the last evaluated expression within the block.

docs/reference/remap/expressions/function_call.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ remap: expressions: function_call: {
1010
be [handled](\(urls.vrl_errors_reference)) and null is returned.
1111
1212
Functions can _only_ return a single value. If multiple values are relevant, you should wrap them in a data
13-
structure fit to hold them, such as an array or map (note that VRL doesn't support tuples).
13+
structure fit to hold them, such as an array or object (note that VRL doesn't support tuples).
1414
"""
1515

1616
grammar: {

docs/reference/remap/expressions/path.cue

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ remap: expressions: path: {
44
title: "Path"
55
description: """
66
A _path_ expression is a sequence of period-delimited segments that represent the location of a value
7-
within a map.
7+
within an object.
88
"""
99
return: """
1010
Returns the value of the path location.
@@ -57,10 +57,10 @@ remap: expressions: path: {
5757
Dynamic paths are currently not supported.
5858
"""
5959
}
60-
nested_maps: {
61-
title: "Nested map paths"
60+
nested_objects: {
61+
title: "Nested object paths"
6262
description: """
63-
Nested map values are accessed by delimiting each ancestor path with `.`:
63+
Nested object values are accessed by delimiting each ancestor path with `.`:
6464
6565
```vrl
6666
.parent.child

docs/reference/remap/functions.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ remap: {
2727
examples?: [remap.#Example, ...remap.#Example]
2828
}
2929

30-
#FunctionCategory: "Array" | "Codec" | "Coerce" | "Debug" | "Enumerate" | "Event" | "Hash" | "IP" | "Map" | "Number" | "Parse" | "Random" | "String" | "System" | "Timestamp" | "Type"
30+
#FunctionCategory: "Array" | "Codec" | "Coerce" | "Debug" | "Enumerate" | "Event" | "Hash" | "IP" | "Number" | "Object" | "Parse" | "Random" | "String" | "System" | "Timestamp" | "Type"
3131

3232
functions: [Name=string]: #Function & {
3333
name: Name
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package metadata
2+
3+
remap: functions: array: {
4+
category: "Type"
5+
description: """
6+
Errors if `value` is not an array, if `value` is an array it is returned.
7+
8+
This allows the type checker to guarantee that the returned value is an array and can be used in any function
9+
that expects this type.
10+
"""
11+
12+
arguments: [
13+
{
14+
name: "value"
15+
description: "The value to ensure is an array."
16+
required: true
17+
type: ["any"]
18+
},
19+
]
20+
internal_failure_reasons: [
21+
"`value` is not an array.",
22+
]
23+
return: types: ["array"]
24+
examples: [
25+
{
26+
title: "Declare an array type"
27+
input: log: value: [1, 2, 3]
28+
source: #"""
29+
array(.value)
30+
"""#
31+
return: input.log.value
32+
},
33+
]
34+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package metadata
2+
3+
remap: functions: bool: {
4+
category: "Type"
5+
description: """
6+
Errors if `value` is not a boolean, if `value` is a boolean it is returned.
7+
8+
This allows the type checker to guarantee that the returned value is a boolean and can be used in any function
9+
that expects this type.
10+
"""
11+
12+
arguments: [
13+
{
14+
name: "value"
15+
description: "The value to ensure is a boolean."
16+
required: true
17+
type: ["any"]
18+
},
19+
]
20+
internal_failure_reasons: [
21+
"`value` is not a boolean.",
22+
]
23+
return: {
24+
types: ["boolean"]
25+
rules: [
26+
#"If `value` is a boolean then it is returned."#,
27+
#"Otherwise an error is raised."#,
28+
]
29+
}
30+
examples: [
31+
{
32+
title: "Declare a boolean type"
33+
input: log: value: false
34+
source: #"""
35+
bool(.value)
36+
"""#
37+
return: input.log.value
38+
},
39+
]
40+
}

docs/reference/remap/functions/compact.cue

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ remap: functions: compact: {
1111
arguments: [
1212
{
1313
name: "value"
14-
description: "The map or array to compact."
14+
description: "The object or array to compact."
1515
required: true
16-
type: ["array", "map"]
16+
type: ["array", "object"]
1717
},
1818
{
1919
name: "recursive"
@@ -37,8 +37,8 @@ remap: functions: compact: {
3737
type: ["boolean"]
3838
},
3939
{
40-
name: "map"
41-
description: "Should an empty map be treated as an empty value."
40+
name: "object"
41+
description: "Should an empty object be treated as an empty value."
4242
required: false
4343
default: true
4444
type: ["boolean"]
@@ -60,7 +60,7 @@ remap: functions: compact: {
6060
]
6161
internal_failure_reasons: []
6262
return: {
63-
types: ["array", "map"]
63+
types: ["array", "object"]
6464
rules: [
6565
"The return type will match the `value` type.",
6666
]
@@ -74,7 +74,7 @@ remap: functions: compact: {
7474
return: ["foo", "bar", "buzz"]
7575
},
7676
{
77-
title: "Compact a map"
77+
title: "Compact an object"
7878
source: #"""
7979
compact({"field1": 1, "field2": "", "field3": [], "field4": null}, string: true, array: true, null: true)
8080
"""#

docs/reference/remap/functions/flatten.cue

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ remap: functions: flatten: {
99
arguments: [
1010
{
1111
name: "value"
12-
description: "The array or map to flatten."
12+
description: "The array or object to flatten."
1313
required: true
14-
type: ["array", "map"]
14+
type: ["array", "object"]
1515
},
1616
]
1717
internal_failure_reasons: []
1818
return: {
19-
types: ["array", "map"]
19+
types: ["array", "object"]
2020
rules: [
2121
"The return type will match the `value` type.",
2222
]
@@ -31,7 +31,7 @@ remap: functions: flatten: {
3131
return: [1, 2, 3, 4, 5, 6, 7, 8, 9]
3232
},
3333
{
34-
title: "Flatten map"
34+
title: "Flatten object"
3535
source: #"""
3636
flatten({
3737
"parent1": {
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package metadata
2+
3+
remap: functions: float: {
4+
category: "Type"
5+
description: """
6+
Errors if `value` is not a float, if `value` is a float it is returned.
7+
8+
This allows the type checker to guarantee that the returned value is a float and can be used in any function
9+
that expects this type.
10+
"""
11+
12+
arguments: [
13+
{
14+
name: "value"
15+
description: "The value to ensure is a float."
16+
required: true
17+
type: ["any"]
18+
},
19+
]
20+
internal_failure_reasons: [
21+
"`value` is not a float.",
22+
]
23+
return: {
24+
types: ["float"]
25+
rules: [
26+
#"If `value` is an float then it is returned."#,
27+
#"Otherwise an error is raised."#,
28+
]
29+
}
30+
examples: [
31+
{
32+
title: "Delcare a float type"
33+
input: log: value: 42
34+
source: #"""
35+
float(.radius)
36+
"""#
37+
return: input.log.value
38+
},
39+
]
40+
}

docs/reference/remap/functions/get_hostname.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ remap: functions: get_hostname: {
1515
title: "Get hostname"
1616
input: log: {}
1717
source: #"""
18-
.hostname = get_hostname!()
18+
.hostname = get_hostname()
1919
"""#
2020
output: log: hostname: "localhost.localdomain"
2121
},
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package metadata
2+
3+
remap: functions: int: {
4+
category: "Type"
5+
description: """
6+
Errors if `value` is not an integer, if `value` is an integer it is returned.
7+
8+
This allows the type checker to guarantee that the returned value is an integer and can be used in any function
9+
that expects this type.
10+
"""
11+
12+
arguments: [
13+
{
14+
name: "value"
15+
description: "The value to ensure is an integer."
16+
required: true
17+
type: ["any"]
18+
},
19+
]
20+
internal_failure_reasons: [
21+
"`value` is not an integer.",
22+
]
23+
return: types: ["integer"]
24+
examples: [
25+
{
26+
title: "Declare an integer type"
27+
input: log: value: 42
28+
source: #"""
29+
int(.value)
30+
"""#
31+
return: input.log.value
32+
},
33+
]
34+
}

docs/reference/remap/functions/length.cue

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ remap: functions: length: {
99
arguments: [
1010
{
1111
name: "value"
12-
description: "The array or map"
12+
description: "The array or object"
1313
required: true
14-
type: ["array", "map", "string"]
14+
type: ["array", "object", "string"]
1515
},
1616
]
1717
internal_failure_reasons: []
@@ -26,7 +26,7 @@ remap: functions: length: {
2626

2727
examples: [
2828
{
29-
title: "Length (map)"
29+
title: "Length (object)"
3030
source: """
3131
length({
3232
"portland": "Trail Blazers"
@@ -36,7 +36,7 @@ remap: functions: length: {
3636
return: 2
3737
},
3838
{
39-
title: "Length (nested map)"
39+
title: "Length (nested object)"
4040
source: """
4141
length({
4242
"home": {

docs/reference/remap/functions/merge.cue

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package metadata
22

33
remap: functions: merge: {
4-
category: "Map"
4+
category: "Object"
55
description: """
6-
Merges the `from` map into the `to` map.
6+
Merges the `from` object into the `to` object.
77
"""
88

99
arguments: [
@@ -17,7 +17,7 @@ remap: functions: merge: {
1717
name: "from"
1818
description: "The object to merge from."
1919
required: true
20-
type: ["map"]
20+
type: ["object"]
2121
},
2222
{
2323
name: "deep"
@@ -29,10 +29,10 @@ remap: functions: merge: {
2929
]
3030
internal_failure_reasons: []
3131
return: {
32-
types: ["map"]
32+
types: ["object"]
3333
rules: [
34-
#"If a key exists in both maps, the field from the `from` map is chosen."#,
35-
#"If `deep` is specified, and a key exists in both maps, and both these fields are also maps, then those maps will merge recursively as well."#,
34+
#"If a key exists in both objects, the field from the `from` object is chosen."#,
35+
#"If `deep` is specified, and a key exists in both objects, and both these fields are also objects, then those objects will merge recursively as well."#,
3636
]
3737
}
3838

0 commit comments

Comments
 (0)