From 4dc011d9164881061a176752f7e65b2f7822d9dc Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 25 Aug 2026 19:29:08 +0200 Subject: [PATCH 1/9] Add new collection utilities and update documentation --- CONTRIBUTING.md | 2 +- .../syntaxes/keywords.json | 9 +- .../syntaxes/keywords.txt | 9 +- .../syntaxes/nebs.tmLanguage.json | 2 +- Resources/Rml/actionWindow.rml | 2 +- Resources/Rml/example.rml | 2 +- Resources/Rml/playerStack.rml | 2 +- .../{bundleToArray.nebs => bundle.nebs} | 4 +- .../Transformations/Collection/enumerate.nebs | 0 .../JSON/Transformations/Collection.json | 2 +- doc/Commands.md | 84 +++++++++++++++++-- .../Nebulite/Module/Transformation/Array.hpp | 10 +-- .../Module/Transformation/Collection.hpp | 28 ++++++- src/Nebulite/Module/Transformation/Array.cpp | 17 +--- .../Module/Transformation/Collection.cpp | 51 ++++++++++- 15 files changed, 178 insertions(+), 46 deletions(-) rename TaskFiles/Tests/JSON/Transformations/Collection/{bundleToArray.nebs => bundle.nebs} (82%) create mode 100644 TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a8d9b641..b81c426e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,7 +74,7 @@ set workspace.objectMember.value1 1 set workspace.objectMember.value2 2 # Bundle the members into an array and store the result in the workspace -assign global:workspace.result = {global:|bundleToArray workspace.valueMember workspace.arrayMember workspace.objectMember} +assign global:workspace.result = {global:|bundle workspace.valueMember workspace.arrayMember workspace.objectMember} # Confirm the result is correct eval nop {global:workspace.result[0]|typeAsString|assert equals string value:string:5} diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json index 48c5e04d4..809efa7e5 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json @@ -14,9 +14,12 @@ "at", "average", "basicValue", + "batch", + "batchPadded", "beep", + "bind", "broadcast", - "bundleToArray", + "bundle", "cam", "capitalize", "capture", @@ -156,6 +159,7 @@ "open", "or", "other", + "pad", "parse", "play-sound", "pop-back", @@ -184,6 +188,7 @@ "require", "reverse", "rmlui", + "rng", "rng2Arg", "rng2ArgInt16", "rng3Arg", @@ -210,6 +215,7 @@ "settings", "sgn", "show-fps", + "slide", "snapshot", "sort", "spawn", @@ -224,6 +230,7 @@ "strCompare", "strCountAppearance", "strLen", + "stride", "string", "strip", "sub", diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt index 2a1dd3997..4e36e82be 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt @@ -13,9 +13,12 @@ assign at average basicValue +batch +batchPadded beep +bind broadcast -bundleToArray +bundle cam capitalize capture @@ -155,6 +158,7 @@ once open or other +pad parse play-sound pop-back @@ -183,6 +187,7 @@ replace require reverse rmlui +rng rng2Arg rng2ArgInt16 rng3Arg @@ -209,6 +214,7 @@ setString settings sgn show-fps +slide snapshot sort spawn @@ -223,6 +229,7 @@ store strCompare strCountAppearance strLen +stride string strip sub diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json b/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json index bf8f1a56b..50ae2f1b0 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json @@ -23,7 +23,7 @@ }, { "name": "keyword.control.nebs", - "match": "\\b(formatComplexNumberString|numericOrNumericString|listMembersAndValues|context-evaluation|strCountAppearance|typeAsSimpleString|case-insensitive|collision-detect|filterRegexValue|complexToString|expression-help|fetch-container|filterGlobValue|find-parent-key|key-combination|numberToComplex|selected-object|applyTfDomainF|case-sensitive|categoryLevel1|categoryLevel2|lPadNonNumeric|rPadNonNumeric|save-standards|bundleToArray|input-mapping|master-unlock|render-object|standard-file|always-clear|ensure-array|feature-test|filterCustom|for-progress|formatNumber|injectScript|removeMember|rng2ArgInt16|rng3ArgInt16|set-fixed-dt|toBoolString|typeAsNumber|typeAsString|deserialize|ensureArray|filterNulls|filterRegex|lPadNumeric|listMembers|numerically|rPadNumeric|set-integer|unreachable|--headless|basicValue|capitalize|complexAbs|complexArg|fetch-name|filterGlob|imgui-view|input-wait|must-throw|play-sound|push-front|pushNumber|set-string|startsWith|strCompare|--recover|add-clock|broadcast|constrain|dump-view|enumerate|error-log|halt-once|keyDelete|pop-front|push-back|recursive|roundDown|serialize|setDouble|setString|substring|task-exec|toBipolar|category|contains|document|drawcall|endsWith|evaluate|fetch-id|function|functree|nonEmpty|pop-back|print-id|settings|show-fps|snapshot|toDouble|toString|triangle|variable|average|capture|ceiling|console|default|flatten|forward|members|numeric|product|reparse|replace|require|reverse|rng2Arg|rng3Arg|roundUp|ruleset|set-fps|set-res|setBool|subspan|toLower|toUpper|always|assert|assign|custom|delete|deload|equals|exists|global|invoke|lStrip|length|listen|median|member|mirror|object|rStrip|reload|remove|setInt|square|stddev|strLen|string|toBool|unlock|update|array|clear|close|crash|debug|draft|empty|error|false|fetch|first|floor|match|other|parse|print|query|regex|rmlui|round|spawn|split|state|store|strip|throw|toInt|beep|copy|echo|eval|exit|grid|help|ifft|iota|json|lPad|last|list|load|lock|move|nand|once|open|push|rPad|root|save|sort|sqrt|task|time|true|type|view|wait|warn|xnor|add|all|and|cam|cat|div|env|fft|for|geq|get|int|key|leq|log|map|max|min|mod|mul|neq|nop|nor|not|off|pow|set|sgn|sub|sum|xor|at|eq|gt|if|ls|lt|on|or)\\b" + "match": "\\b(formatComplexNumberString|numericOrNumericString|listMembersAndValues|context-evaluation|strCountAppearance|typeAsSimpleString|case-insensitive|collision-detect|filterRegexValue|complexToString|expression-help|fetch-container|filterGlobValue|find-parent-key|key-combination|numberToComplex|selected-object|applyTfDomainF|case-sensitive|categoryLevel1|categoryLevel2|lPadNonNumeric|rPadNonNumeric|save-standards|input-mapping|master-unlock|render-object|standard-file|always-clear|ensure-array|feature-test|filterCustom|for-progress|formatNumber|injectScript|removeMember|rng2ArgInt16|rng3ArgInt16|set-fixed-dt|toBoolString|typeAsNumber|typeAsString|batchPadded|deserialize|ensureArray|filterNulls|filterRegex|lPadNumeric|listMembers|numerically|rPadNumeric|set-integer|unreachable|--headless|basicValue|capitalize|complexAbs|complexArg|fetch-name|filterGlob|imgui-view|input-wait|must-throw|play-sound|push-front|pushNumber|set-string|startsWith|strCompare|--recover|add-clock|broadcast|constrain|dump-view|enumerate|error-log|halt-once|keyDelete|pop-front|push-back|recursive|roundDown|serialize|setDouble|setString|substring|task-exec|toBipolar|category|contains|document|drawcall|endsWith|evaluate|fetch-id|function|functree|nonEmpty|pop-back|print-id|settings|show-fps|snapshot|toDouble|toString|triangle|variable|average|capture|ceiling|console|default|flatten|forward|members|numeric|product|reparse|replace|require|reverse|rng2Arg|rng3Arg|roundUp|ruleset|set-fps|set-res|setBool|subspan|toLower|toUpper|always|assert|assign|bundle|custom|delete|deload|equals|exists|global|invoke|lStrip|length|listen|median|member|mirror|object|rStrip|reload|remove|setInt|square|stddev|strLen|stride|string|toBool|unlock|update|array|batch|clear|close|crash|debug|draft|empty|error|false|fetch|first|floor|match|other|parse|print|query|regex|rmlui|round|slide|spawn|split|state|store|strip|throw|toInt|beep|bind|copy|echo|eval|exit|grid|help|ifft|iota|json|lPad|last|list|load|lock|move|nand|once|open|push|rPad|root|save|sort|sqrt|task|time|true|type|view|wait|warn|xnor|add|all|and|cam|cat|div|env|fft|for|geq|get|int|key|leq|log|map|max|min|mod|mul|neq|nop|nor|not|off|pad|pow|rng|set|sgn|sub|sum|xor|at|eq|gt|if|ls|lt|on|or)\\b" }, { "name": "markup.underline.link", diff --git a/Resources/Rml/actionWindow.rml b/Resources/Rml/actionWindow.rml index 1994c6116..7a23dd147 100644 --- a/Resources/Rml/actionWindow.rml +++ b/Resources/Rml/actionWindow.rml @@ -29,7 +29,7 @@ -
+
diff --git a/Resources/Rml/example.rml b/Resources/Rml/example.rml index df66a74c1..3ec15c646 100644 --- a/Resources/Rml/example.rml +++ b/Resources/Rml/example.rml @@ -79,7 +79,7 @@ -

+

diff --git a/Resources/Rml/playerStack.rml b/Resources/Rml/playerStack.rml index 73a96ba5e..1af93a3ef 100644 --- a/Resources/Rml/playerStack.rml +++ b/Resources/Rml/playerStack.rml @@ -8,7 +8,7 @@ -

+
diff --git a/TaskFiles/Tests/JSON/Transformations/Collection/bundleToArray.nebs b/TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs similarity index 82% rename from TaskFiles/Tests/JSON/Transformations/Collection/bundleToArray.nebs rename to TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs index b4c6fc8c4..b85c67862 100644 --- a/TaskFiles/Tests/JSON/Transformations/Collection/bundleToArray.nebs +++ b/TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs @@ -11,8 +11,8 @@ set obj.key2 value2 set obj.key3 value3 # Bundle -assign global:result.arr = {global:arr|bundleToArray [0] [1]} -assign global:result.obj = {global:obj|bundleToArray key1 key2} +assign global:result.arr = {global:arr|bundle [0] [1]} +assign global:result.obj = {global:obj|bundle key1 key2} # Verify eval nop {global:result.arr|assert type array} diff --git a/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs b/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs new file mode 100644 index 000000000..e69de29bb diff --git a/Tools/Tests/JSON/Transformations/Collection.json b/Tools/Tests/JSON/Transformations/Collection.json index 67b8f8193..c99da8dd5 100644 --- a/Tools/Tests/JSON/Transformations/Collection.json +++ b/Tools/Tests/JSON/Transformations/Collection.json @@ -16,7 +16,7 @@ "expected": { "cout": [], "cerr": [] } }, { - "command": "task TaskFiles/Tests/JSON/Transformations/Collection/bundleToArray.nebs", + "command": "task TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs", "expected": { "cout": [], "cerr": [] } } ] \ No newline at end of file diff --git a/doc/Commands.md b/doc/Commands.md index 6bacda2f8..37ca9fc28 100644 --- a/doc/Commands.md +++ b/doc/Commands.md @@ -2,7 +2,7 @@ This documentation is automatically generated. -Generated on: Sun Aug 9 11:46:19 CEST 2026 +Generated on: Tue Aug 25 19:16:25 CEST 2026 ## Table of Contents @@ -75,6 +75,7 @@ Available Functions | `query` | Functions to manipulate JSON data via SQL query results | | `reparse` | Commands for forwarding function calls to other contexts (other or global) while switching context. | | `rmlui` | Functions for managing RmlUI elements. | +| `rng` | Random number generation functions. | | `ruleset` | Functions for managing rulesets. | | `selected-object` | Functions to select and interact with a selected RenderObject | | `set` | Set a key to a string value in the JSON document. | @@ -959,6 +960,28 @@ Removes a loaded RmlUI document from the renderer's context by its name. Usage: rmlui document remove ``` +#### `rng` + +Available Functions + +| Function | Description | +|----------|-------------| +| `help` | Show available commands and their descriptions | +| `off` | Disables RNG updates. Useful for TAS scripts to avoid RNG state changes, or benchmarking to avoid RNG state changes. | +| `on` | Re-enables RNG updates. | + +##### `rng off` + +``` +Disables RNG updates. Useful for TAS scripts to avoid RNG state changes, or benchmarking to avoid RNG state changes. +``` + +##### `rng on` + +``` +Re-enables RNG updates. +``` + #### `ruleset` Available Functions @@ -2066,7 +2089,10 @@ Available Functions | `assign` | Assigns a value based on the result of an expression. | | `at` | Gets the element at the specified index from the array in the current JSON value. | | `average` | Calculates the average of the elements of the array in the current JSON value. | -| `bundleToArray` | Gathers all members from the provided keys into an array. | +| `batch` | Batches the array in the current JSON value into subarrays of the specified size. | +| `batchPadded` | Batches the array in the current JSON value into subarrays of the specified size, padding the last batch with empty objects if necessary. | +| `bind` | Binds the elements of an array to the provided keys. | +| `bundle` | Gathers all members from the provided keys into an array. | | `capitalize` | Capitalizes the current JSON string. | | `ceiling` | Rounds the current JSON numeric value down to the nearest integer. | | `complexAbs` | Calculates the absolute value (magnitude) of a complex number. | @@ -2119,6 +2145,7 @@ Available Functions | `neq` | Checks if the current JSON value is not equal to the specified value. | | `not` | Logical NOT operation on the current JSON value. | | `numberToComplex` | Converts a given number to a complex number. | +| `pad` | Pads the array in the current JSON value to the specified length with empty objects. | | `pow` | Raises the current JSON value to the power of a numeric value. | | `print` | Prints the current JSON value to the console. | | `product` | Multiplies the elements of the array in the current JSON value. | @@ -2141,6 +2168,7 @@ Available Functions | `setDouble` | Sets a double value at the specified key in the JSON document. | | `setInt` | Sets an integer value at the specified key in the JSON document. | | `setString` | Sets a string value at the specified key in the JSON document. | +| `slide` | Slides the array in the current JSON value by the specified size, generating overlapping windows. | | `sort` | Sorting transformation functions | | `split` | Splits the current JSON string value into an array of substrings based on a specified character delimiter. | | `sqrt` | Calculates the square root of the current JSON value. | @@ -2149,6 +2177,7 @@ Available Functions | `strCompare` | Functions for comparing string values. | | `strCountAppearance` | Counts the number of occurrences of a specified substring in the current JSON string value. | | `strLen` | Calculates the length of the current JSON string value. | +| `stride` | Strides the array in the current JSON value by the specified size. | | `strip` | Strips whitespace from both ends of the current JSON string value. | | `sub` | Subtracts a numeric value from the current JSON value. | | `subspan` | Gets a subarray from the array in the current JSON value. | @@ -2357,11 +2386,32 @@ Input must be an array of numbers. If any element is not a number, the current v Usage: |average -> {number} ``` -#### `bundleToArray` +#### `batch` + +``` +Batches the array in the current JSON value into subarrays of the specified size. +Usage: |batch -> {array} +``` + +#### `batchPadded` + +``` +Batches the array in the current JSON value into subarrays of the specified size, padding the last batch with empty objects if necessary. +Usage: |batchPadded -> {array} +``` + +#### `bind` + +``` +Binds the elements of an array to the provided keys. +Usage: |bind ... -> {object} +``` + +#### `bundle` ``` Gathers all members from the provided keys into an array. -Usage: |bundleToArray ... -> {array} +Usage: |bundle ... -> {array} ``` #### `capitalize` @@ -2447,7 +2497,9 @@ Usage: |ensureArray -> {array} ``` Enumerates the array in the current JSON value. -Usage: |enumerate -> {array} +Creates another array for each element, where [0] is the index and [1] is the value. +Recommended over enumerateInline if the values stored are not objects. +Usage: |enumerate -> {array} Where indexKey is the key of each array element to populate with the index of the element in the array. ``` @@ -2771,6 +2823,14 @@ Allowed values are: The transformation fails if the current JSON value is not convertible to a complex number. ``` +#### `pad` + +``` +Pads the array in the current JSON value to the specified length with empty objects. +If the current value is larger than the specified length, it is not modified. +Usage: |pad -> {array} +``` + #### `pow` ``` @@ -3096,6 +3156,13 @@ Expects two arguments: and . Usage: |setString -> {json} ``` +#### `slide` + +``` +Slides the array in the current JSON value by the specified size, generating overlapping windows. +Usage: |slide -> {array} +``` + #### `sort` Available Functions @@ -3244,6 +3311,13 @@ Calculates the length of the current JSON string value. Usage: |strLen -> {int} ``` +#### `stride` + +``` +Strides the array in the current JSON value by the specified size. +Usage: |stride -> {array} +``` + #### `strip` ``` diff --git a/include/Nebulite/Module/Transformation/Array.hpp b/include/Nebulite/Module/Transformation/Array.hpp index d18c7cbcd..1dfa3d3d5 100644 --- a/include/Nebulite/Module/Transformation/Array.hpp +++ b/include/Nebulite/Module/Transformation/Array.hpp @@ -68,7 +68,7 @@ class Array final : public Base::TransformationModule { // TODO: dedupe, pick, omit - // Metadata + // Dimensionality static bool flatten(Data::JsonScope& jsonDoc); static auto constexpr flattenName = "flatten"; @@ -80,14 +80,6 @@ class Array final : public Base::TransformationModule { "If the current value is not an array, it is first wrapped into a single-element array.\n" "Usage: |reverse -> {array}\n"; - // TODO: no index name passing. Instead: turn into object with index and value - // even better: a canonical representation of tuples for the Json/JsonScope class - static bool enumerate(std::span args, Data::JsonScope& jsonDoc); - static auto constexpr enumerateName = "enumerate"; - static auto constexpr enumerateDesc = "Enumerates the array in the current JSON value.\n" - "Usage: |enumerate -> {array}\n" - "Where indexKey is the key of each array element to populate with the index of the element in the array.\n"; - static bool batch(std::span args, Data::JsonScope& jsonDoc); static auto constexpr batchName = "batch"; static auto constexpr batchDesc = "Batches the array in the current JSON value into subarrays of the specified size.\n" diff --git a/include/Nebulite/Module/Transformation/Collection.hpp b/include/Nebulite/Module/Transformation/Collection.hpp index 59a26ca48..efa7f0ed9 100644 --- a/include/Nebulite/Module/Transformation/Collection.hpp +++ b/include/Nebulite/Module/Transformation/Collection.hpp @@ -59,10 +59,30 @@ class Collection final : public Base::TransformationModule { "If the current value is an array, it lists the indices as strings.\n" "Usage: |listMembersAndValues -> {array of {key, value} objects}\n"; - static bool bundleToArray(std::span args, Data::JsonScope& jsonDoc); - static auto constexpr bundleToArrayName = "bundleToArray"; - static auto constexpr bundleToArrayDesc = "Gathers all members from the provided keys into an array.\n" - "Usage: |bundleToArray ... -> {array}\n"; + static bool enumerate(std::span args, Data::JsonScope& jsonDoc); + static auto constexpr enumerateName = "enumerate"; + static auto constexpr enumerateDesc = "Enumerates the array in the current JSON value.\n" + "Creates another array for each element, where [0] is the index and [1] is the value.\n" + "Recommended over enumerateInline if the values stored are not objects.\n" + "Usage: |enumerate -> {array}\n" + "Where indexKey is the key of each array element to populate with the index of the element in the array.\n"; + + static bool enumerateInline(std::span args, Data::JsonScope& jsonDoc); + static auto constexpr enumerateInlineName = "enumerateInline"; + static auto constexpr enumerateInlineDesc = "Enumerates the array in the current JSON value using a provided key.\n" + "Recommended over enumerate if the values stored are objects.\n" + "Usage: |enumerateInline -> {array}\n" + "Where indexKey is the key of each array element to populate with the index of the element in the array.\n"; + + static bool bundle(std::span args, Data::JsonScope& jsonDoc); + static auto constexpr bundleName = "bundle"; + static auto constexpr bundleDesc = "Gathers all members from the provided keys into an array.\n" + "Usage: |bundle ... -> {array}\n"; + + static bool bind(std::span args, Data::JsonScope& jsonDoc); + static auto constexpr bindName = "bind"; + static auto constexpr bindDesc = "Binds the elements of an array to the provided keys.\n" + "Usage: |bind ... -> {object}\n"; }; } // namespace Nebulite::Module::Transformation #endif // NEBULITE_MODULE_TRANSFORMATION_COLLECTION_HPP diff --git a/src/Nebulite/Module/Transformation/Array.cpp b/src/Nebulite/Module/Transformation/Array.cpp index 46e610857..294abac60 100644 --- a/src/Nebulite/Module/Transformation/Array.cpp +++ b/src/Nebulite/Module/Transformation/Array.cpp @@ -30,10 +30,9 @@ void Array::bindTransformations() { bindTransformation(&Array::length, lengthName, lengthDesc); bindTransformation(&Array::subspan, subspanName, subspanDesc); - // Metadata + // Dimensionality bindTransformation(&Array::flatten, flattenName, flattenDesc); bindTransformation(&Array::reverse, reverseName, reverseDesc); - bindTransformation(&Array::enumerate, enumerateName, enumerateDesc); bindTransformation(&Array::batch, batchName, batchDesc); bindTransformation(&Array::batchPadded, batchPaddedName, batchPaddedDesc); bindTransformation(&Array::stride, strideName, strideDesc); @@ -230,20 +229,6 @@ bool Array::reverse(Data::JsonScope& jsonDoc) { return true; } -bool Array::enumerate(std::span const args, Data::JsonScope& jsonDoc){ - if (args.size() < 2) return false; - if (jsonDoc.memberType(rootKey) != Data::KeyType::array) return false; - auto const& indexKey = args.at(1); - std::ranges::for_each( - std::views::iota(std::size_t{0}, jsonDoc.memberSize(rootKey)), - [&](std::size_t const i) { - auto const key = rootKey.addIndex(i).addMember(indexKey); - jsonDoc.set(key, i); - } - ); - return true; -} - bool Array::batch(std::span const args, Data::JsonScope& jsonDoc){ // Validate arguments and input if (args.size() < 2) return false; diff --git a/src/Nebulite/Module/Transformation/Collection.cpp b/src/Nebulite/Module/Transformation/Collection.cpp index 9b6748f88..7c54e159d 100644 --- a/src/Nebulite/Module/Transformation/Collection.cpp +++ b/src/Nebulite/Module/Transformation/Collection.cpp @@ -26,7 +26,10 @@ void Collection::bindTransformations() { bindTransformation(&Collection::get, getName, getDesc); bindTransformation(&Collection::listMembers, listMembersName, listMembersDesc); bindTransformation(&Collection::listMembersAndValues, listMembersAndValuesName, listMembersAndValuesDesc); - bindTransformation(&Collection::bundleToArray, bundleToArrayName, bundleToArrayDesc); + bindTransformation(&Collection::enumerate, enumerateName, enumerateDesc); + bindTransformation(&Collection::enumerateInline, enumerateInlineName, enumerateInlineDesc); + bindTransformation(&Collection::bundle, bundleName, bundleDesc); + bindTransformation(&Collection::bind, bindName, bindDesc); } bool Collection::map(std::span const args, Data::JsonScope& jsonDoc) { @@ -111,7 +114,38 @@ bool Collection::listMembersAndValues(Data::JsonScope& jsonDoc){ return true; } -bool Collection::bundleToArray(std::span const args, Data::JsonScope& jsonDoc) { +bool Collection::enumerateInline(std::span const args, Data::JsonScope& jsonDoc){ + if (args.size() < 2) return false; + if (jsonDoc.memberType(rootKey) != Data::KeyType::array) return false; + auto const& indexKey = args.at(1); + std::ranges::for_each( + std::views::iota(std::size_t{0}, jsonDoc.memberSize(rootKey)), + [&](std::size_t const i) { + auto const key = rootKey.addIndex(i).addMember(indexKey); + jsonDoc.set(key, i); + } + ); + return true; +} + +bool Collection::enumerate(std::span args, Data::JsonScope& jsonDoc){ + if (args.size() != 1) return false; + if (jsonDoc.memberType(rootKey) != Data::KeyType::array) return false; + Data::Json tmp; + std::ranges::for_each( + std::views::iota(std::size_t{0}, jsonDoc.memberSize(rootKey)), + [&](std::size_t const i) { + auto const key = rootKey.addIndex(i); + tmp.set(key.addIndex(0).toString(), i); + tmp.setSubDoc(key.addIndex(1).toString(), jsonDoc.getSubDoc(key)); + } + ); + jsonDoc.setSubDoc(rootKey, tmp); + return true; +} + +// Obj->Array: bundle +bool Collection::bundle(std::span const args, Data::JsonScope& jsonDoc) { if (args.size() < 2) { return false; } @@ -123,4 +157,17 @@ bool Collection::bundleToArray(std::span const args, Dat return true; } +// Array->Obj: bind +bool Collection::bind(std::span args, Data::JsonScope& jsonDoc){ + if (args.size() < 2) { + return false; + } + Data::Json tmp; + for (auto [idx, key] : args.subspan(1) | Utility::Ranges::enumerate) { + tmp.setSubDoc(key, jsonDoc.getSubDoc(rootKey.addIndex(idx))); + } + jsonDoc.setSubDoc(rootKey, tmp); + return true; +} + } // namespace Nebulite::Module::Transformation From 3a91f5c1f0006f4384e81b75d88aecc4ab932928 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 26 Aug 2026 06:06:36 +0200 Subject: [PATCH 2/9] Add enumerate functionality tests. --- .../Transformations/Collection/enumerate.nebs | 48 +++++++++++++++++++ .../JSON/Transformations/Collection.json | 4 ++ 2 files changed, 52 insertions(+) diff --git a/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs b/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs index e69de29bb..a086c015b 100644 --- a/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs +++ b/TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs @@ -0,0 +1,48 @@ +# Test enumerate functionality + +set arr[0] a +set arr[1] b +set arr[2] c +set arr[3] d + +set arrObj[0].value a +set arrObj[1].value b +set arrObj[2].value c +set arrObj[3].value d + +# Enumerate: Best option, as it does not overwrite values but moves them +# [0]: index +# [1]: value +assign self:result.enumerate.arr = {self:arr|enumerate} +assign self:result.enumerate.arrObj = {self:arrObj|enumerate} + +# Inline enumerate +# Faster, but can overwrite values if not careful. Use with caution. +assign self:result.inline.arr = {self:arr|enumerateInline idx} # Not recommended, overwrites values +assign self:result.inline.arrObj = {self:arrObj|enumerateInline idx} # Recommended, adds idx to each object + +# Verify: enumerate +for i 0 3 eval nop {self:result.enumerate.arr[{i}][0]|assert equals int {i}} +eval nop {self:result.enumerate.arr[0][1]|assert equals string a} +eval nop {self:result.enumerate.arr[1][1]|assert equals string b} +eval nop {self:result.enumerate.arr[2][1]|assert equals string c} +eval nop {self:result.enumerate.arr[3][1]|assert equals string d} +for i 0 3 eval nop {self:result.enumerate.arrObj[{i}][0]|assert equals int {i}} +eval nop {self:result.enumerate.arrObj[0][1].value|assert equals string a} +eval nop {self:result.enumerate.arrObj[1][1].value|assert equals string b} +eval nop {self:result.enumerate.arrObj[2][1].value|assert equals string c} +eval nop {self:result.enumerate.arrObj[3][1].value|assert equals string d} + +# Verify: enumerateInline +for i 0 3 eval nop {self:result.inline.arr[{i}].idx|assert equals int {i}} +eval nop {self:result.inline.arr[0]|length|assert equals int 1} +eval nop {self:result.inline.arr[1]|length|assert equals int 1} +eval nop {self:result.inline.arr[2]|length|assert equals int 1} +eval nop {self:result.inline.arr[3]|length|assert equals int 1} +for i 0 3 eval nop {self:result.inline.arrObj[{i}].idx|assert equals int {i}} +eval nop {self:result.inline.arrObj[0].value|assert equals string a} +eval nop {self:result.inline.arrObj[1].value|assert equals string b} +eval nop {self:result.inline.arrObj[2].value|assert equals string c} +eval nop {self:result.inline.arrObj[3].value|assert equals string d} + +exit diff --git a/Tools/Tests/JSON/Transformations/Collection.json b/Tools/Tests/JSON/Transformations/Collection.json index c99da8dd5..094626125 100644 --- a/Tools/Tests/JSON/Transformations/Collection.json +++ b/Tools/Tests/JSON/Transformations/Collection.json @@ -15,6 +15,10 @@ "command": "task TaskFiles/Tests/JSON/Transformations/Collection/listMembersAndValues.nebs", "expected": { "cout": [], "cerr": [] } }, + { + "command": "task TaskFiles/Tests/JSON/Transformations/Collection/enumerate.nebs", + "expected": { "cout": [], "cerr": [] } + }, { "command": "task TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs", "expected": { "cout": [], "cerr": [] } From 73972399e1f06f95d247b4561080734f615fe21a Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 26 Aug 2026 06:27:40 +0200 Subject: [PATCH 3/9] Enhance JSON handling in Collection by ensuring non-null elements are set to empty objects --- src/Nebulite/Module/Transformation/Collection.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Nebulite/Module/Transformation/Collection.cpp b/src/Nebulite/Module/Transformation/Collection.cpp index 7c54e159d..c7ec07e88 100644 --- a/src/Nebulite/Module/Transformation/Collection.cpp +++ b/src/Nebulite/Module/Transformation/Collection.cpp @@ -162,9 +162,17 @@ bool Collection::bind(std::span args, Data::JsonScope& j if (args.size() < 2) { return false; } + if (jsonDoc.memberType(rootKey) != Data::KeyType::array) { + return false; + } + Data::Json tmp; for (auto [idx, key] : args.subspan(1) | Utility::Ranges::enumerate) { - tmp.setSubDoc(key, jsonDoc.getSubDoc(rootKey.addIndex(idx))); + auto element = jsonDoc.getSubDoc(rootKey.addIndex(idx)); + if (element.memberType("") == Data::KeyType::null) { // Default to empty object instead of null + element.setEmptyObject(""); + } + tmp.setSubDoc(key, element); } jsonDoc.setSubDoc(rootKey, tmp); return true; From 07ce08c282f142ea9d065568f80e3400d95f720e Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 26 Aug 2026 06:27:57 +0200 Subject: [PATCH 4/9] Add binding functionality tests for array to object transformations --- .../JSON/Transformations/Collection/bind.nebs | 27 +++++++++++++++++++ .../JSON/Transformations/Collection.json | 4 +++ 2 files changed, 31 insertions(+) create mode 100644 TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs diff --git a/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs b/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs new file mode 100644 index 000000000..5def774c5 --- /dev/null +++ b/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs @@ -0,0 +1,27 @@ +# TODO ... + +# Array +set arr[0] 1 +set arr[1] 2 +set arr[2] 3 + +# Bind: Arr->Obj +assign self:result.bind.a = {self:arr|bind key1 key2 key3} +assign self:result.bind.b = {self:arr|bind key1 key2} +assign self:result.bind.c = {self:arr|bind key1} + +# Verify +eval nop {self:result.bind.a|assert type object} +eval nop {self:result.bind.a|listMembers|length|assert equals int 3} +eval nop {self:result.bind.a.key1|assert equals int 1} +eval nop {self:result.bind.a.key2|assert equals int 2} +eval nop {self:result.bind.a.key3|assert equals int 3} +eval nop {self:result.bind.b|assert type object} +eval nop {self:result.bind.b|listMembers|length|assert equals int 2} +eval nop {self:result.bind.b.key1|assert equals int 1} +eval nop {self:result.bind.b.key2|assert equals int 2} +eval nop {self:result.bind.c|assert type object} +eval nop {self:result.bind.c|listMembers|length|assert equals int 1} +eval nop {self:result.bind.c.key1|assert equals int 1} + +exit diff --git a/Tools/Tests/JSON/Transformations/Collection.json b/Tools/Tests/JSON/Transformations/Collection.json index 094626125..357e759ab 100644 --- a/Tools/Tests/JSON/Transformations/Collection.json +++ b/Tools/Tests/JSON/Transformations/Collection.json @@ -22,5 +22,9 @@ { "command": "task TaskFiles/Tests/JSON/Transformations/Collection/bundle.nebs", "expected": { "cout": [], "cerr": [] } + }, + { + "command": "task TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs", + "expected": { "cout": [], "cerr": [] } } ] \ No newline at end of file From 2ea481235db552f07608e514d5a17c316f3388d9 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 26 Aug 2026 06:50:36 +0200 Subject: [PATCH 5/9] Refactor index handling in Collection and Filter to use ScopedKey::addIndex. --- src/Nebulite/Module/Transformation/Collection.cpp | 4 ++-- src/Nebulite/Module/Transformation/Filter.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nebulite/Module/Transformation/Collection.cpp b/src/Nebulite/Module/Transformation/Collection.cpp index c7ec07e88..8a97ab640 100644 --- a/src/Nebulite/Module/Transformation/Collection.cpp +++ b/src/Nebulite/Module/Transformation/Collection.cpp @@ -150,8 +150,8 @@ bool Collection::bundle(std::span const args, Data::Json return false; } Data::Json tmp; - for (auto [idx, key] : args.subspan(1) | std::views::enumerate) { - tmp.setSubDoc("[" + std::to_string(idx) + "]", jsonDoc.getSubDoc(rootKey.addMember(key))); + for (auto [idx, key] : args.subspan(1) | Utility::Ranges::enumerate) { + tmp.setSubDoc(rootKey.addIndex(idx).toString(), jsonDoc.getSubDoc(rootKey.addMember(key))); } jsonDoc.setSubDoc(rootKey, tmp); return true; diff --git a/src/Nebulite/Module/Transformation/Filter.cpp b/src/Nebulite/Module/Transformation/Filter.cpp index 358eb5bdf..9eef323c8 100644 --- a/src/Nebulite/Module/Transformation/Filter.cpp +++ b/src/Nebulite/Module/Transformation/Filter.cpp @@ -169,7 +169,7 @@ bool Filter::filterNulls(Data::JsonScope& jsonDoc) { if (memberType != Data::KeyType::null) { if (rootType == Data::KeyType::array) { // For arrays, we need to reindex the keys - filteredObject.setSubDoc("[" + std::to_string(arrayIndex) + "]", memberValue); + filteredObject.setSubDoc(rootKey.addIndex(arrayIndex).toString(), memberValue); arrayIndex++; } else { filteredObject.setSubDoc(member, memberValue); From 321d66acb9ce587ccdfdeaea7ec62c1e6b9e8e7c Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 27 Aug 2026 08:42:20 +0200 Subject: [PATCH 6/9] Enhance bind/bundle transformation to insert empty objects for missing values in the array, add missing descriptions. --- TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs | 3 ++- include/Nebulite/Module/Transformation/Collection.hpp | 4 ++++ src/Nebulite/Module/Transformation/Collection.cpp | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs b/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs index 5def774c5..03b01c61f 100644 --- a/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs +++ b/TaskFiles/Tests/JSON/Transformations/Collection/bind.nebs @@ -1,4 +1,5 @@ -# TODO ... +# Test bind functionality +# a bind-transformation takes an array and binds its values sequentially to the specified keys # Array set arr[0] 1 diff --git a/include/Nebulite/Module/Transformation/Collection.hpp b/include/Nebulite/Module/Transformation/Collection.hpp index efa7f0ed9..0ea76c97f 100644 --- a/include/Nebulite/Module/Transformation/Collection.hpp +++ b/include/Nebulite/Module/Transformation/Collection.hpp @@ -77,11 +77,15 @@ class Collection final : public Base::TransformationModule { static bool bundle(std::span args, Data::JsonScope& jsonDoc); static auto constexpr bundleName = "bundle"; static auto constexpr bundleDesc = "Gathers all members from the provided keys into an array.\n" + "Inserts empty objects for missing values in the object.\n" "Usage: |bundle ... -> {array}\n"; static bool bind(std::span args, Data::JsonScope& jsonDoc); static auto constexpr bindName = "bind"; static auto constexpr bindDesc = "Binds the elements of an array to the provided keys.\n" + "think of C++ structured bindings: auto [key1, key2, key3] = arr;\n" + "Fails if the given scope is not an array or if no keys are provided.\n" + "Inserts empty objects for missing values in the array.\n" "Usage: |bind ... -> {object}\n"; }; } // namespace Nebulite::Module::Transformation diff --git a/src/Nebulite/Module/Transformation/Collection.cpp b/src/Nebulite/Module/Transformation/Collection.cpp index 8a97ab640..d2cd8e363 100644 --- a/src/Nebulite/Module/Transformation/Collection.cpp +++ b/src/Nebulite/Module/Transformation/Collection.cpp @@ -151,7 +151,11 @@ bool Collection::bundle(std::span const args, Data::Json } Data::Json tmp; for (auto [idx, key] : args.subspan(1) | Utility::Ranges::enumerate) { - tmp.setSubDoc(rootKey.addIndex(idx).toString(), jsonDoc.getSubDoc(rootKey.addMember(key))); + auto element = jsonDoc.getSubDoc(rootKey.addMember(key)); + if (element.memberType("") == Data::KeyType::null) { // Default to empty object instead of null + element.setEmptyObject(""); + } + tmp.setSubDoc(rootKey.addIndex(idx).toString(), element); } jsonDoc.setSubDoc(rootKey, tmp); return true; @@ -165,7 +169,6 @@ bool Collection::bind(std::span args, Data::JsonScope& j if (jsonDoc.memberType(rootKey) != Data::KeyType::array) { return false; } - Data::Json tmp; for (auto [idx, key] : args.subspan(1) | Utility::Ranges::enumerate) { auto element = jsonDoc.getSubDoc(rootKey.addIndex(idx)); From e236d2e96f022162769f6530f3819d2577030f18 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 27 Aug 2026 08:43:50 +0200 Subject: [PATCH 7/9] Update documentation --- .../syntaxes/keywords.json | 1 + .../nebulite-script-vscode/syntaxes/keywords.txt | 1 + .../syntaxes/nebs.tmLanguage.json | 2 +- doc/Commands.md | 16 +++++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json index 809efa7e5..8cbd74ba0 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.json @@ -59,6 +59,7 @@ "ensure-array", "ensureArray", "enumerate", + "enumerateInline", "env", "eq", "equals", diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt index 4e36e82be..4b3eee626 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/keywords.txt @@ -58,6 +58,7 @@ endsWith ensure-array ensureArray enumerate +enumerateInline env eq equals diff --git a/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json b/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json index 50ae2f1b0..5ba33ccff 100644 --- a/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json +++ b/Languages/nebs/nebulite-script-vscode/syntaxes/nebs.tmLanguage.json @@ -23,7 +23,7 @@ }, { "name": "keyword.control.nebs", - "match": "\\b(formatComplexNumberString|numericOrNumericString|listMembersAndValues|context-evaluation|strCountAppearance|typeAsSimpleString|case-insensitive|collision-detect|filterRegexValue|complexToString|expression-help|fetch-container|filterGlobValue|find-parent-key|key-combination|numberToComplex|selected-object|applyTfDomainF|case-sensitive|categoryLevel1|categoryLevel2|lPadNonNumeric|rPadNonNumeric|save-standards|input-mapping|master-unlock|render-object|standard-file|always-clear|ensure-array|feature-test|filterCustom|for-progress|formatNumber|injectScript|removeMember|rng2ArgInt16|rng3ArgInt16|set-fixed-dt|toBoolString|typeAsNumber|typeAsString|batchPadded|deserialize|ensureArray|filterNulls|filterRegex|lPadNumeric|listMembers|numerically|rPadNumeric|set-integer|unreachable|--headless|basicValue|capitalize|complexAbs|complexArg|fetch-name|filterGlob|imgui-view|input-wait|must-throw|play-sound|push-front|pushNumber|set-string|startsWith|strCompare|--recover|add-clock|broadcast|constrain|dump-view|enumerate|error-log|halt-once|keyDelete|pop-front|push-back|recursive|roundDown|serialize|setDouble|setString|substring|task-exec|toBipolar|category|contains|document|drawcall|endsWith|evaluate|fetch-id|function|functree|nonEmpty|pop-back|print-id|settings|show-fps|snapshot|toDouble|toString|triangle|variable|average|capture|ceiling|console|default|flatten|forward|members|numeric|product|reparse|replace|require|reverse|rng2Arg|rng3Arg|roundUp|ruleset|set-fps|set-res|setBool|subspan|toLower|toUpper|always|assert|assign|bundle|custom|delete|deload|equals|exists|global|invoke|lStrip|length|listen|median|member|mirror|object|rStrip|reload|remove|setInt|square|stddev|strLen|stride|string|toBool|unlock|update|array|batch|clear|close|crash|debug|draft|empty|error|false|fetch|first|floor|match|other|parse|print|query|regex|rmlui|round|slide|spawn|split|state|store|strip|throw|toInt|beep|bind|copy|echo|eval|exit|grid|help|ifft|iota|json|lPad|last|list|load|lock|move|nand|once|open|push|rPad|root|save|sort|sqrt|task|time|true|type|view|wait|warn|xnor|add|all|and|cam|cat|div|env|fft|for|geq|get|int|key|leq|log|map|max|min|mod|mul|neq|nop|nor|not|off|pad|pow|rng|set|sgn|sub|sum|xor|at|eq|gt|if|ls|lt|on|or)\\b" + "match": "\\b(formatComplexNumberString|numericOrNumericString|listMembersAndValues|context-evaluation|strCountAppearance|typeAsSimpleString|case-insensitive|collision-detect|filterRegexValue|complexToString|enumerateInline|expression-help|fetch-container|filterGlobValue|find-parent-key|key-combination|numberToComplex|selected-object|applyTfDomainF|case-sensitive|categoryLevel1|categoryLevel2|lPadNonNumeric|rPadNonNumeric|save-standards|input-mapping|master-unlock|render-object|standard-file|always-clear|ensure-array|feature-test|filterCustom|for-progress|formatNumber|injectScript|removeMember|rng2ArgInt16|rng3ArgInt16|set-fixed-dt|toBoolString|typeAsNumber|typeAsString|batchPadded|deserialize|ensureArray|filterNulls|filterRegex|lPadNumeric|listMembers|numerically|rPadNumeric|set-integer|unreachable|--headless|basicValue|capitalize|complexAbs|complexArg|fetch-name|filterGlob|imgui-view|input-wait|must-throw|play-sound|push-front|pushNumber|set-string|startsWith|strCompare|--recover|add-clock|broadcast|constrain|dump-view|enumerate|error-log|halt-once|keyDelete|pop-front|push-back|recursive|roundDown|serialize|setDouble|setString|substring|task-exec|toBipolar|category|contains|document|drawcall|endsWith|evaluate|fetch-id|function|functree|nonEmpty|pop-back|print-id|settings|show-fps|snapshot|toDouble|toString|triangle|variable|average|capture|ceiling|console|default|flatten|forward|members|numeric|product|reparse|replace|require|reverse|rng2Arg|rng3Arg|roundUp|ruleset|set-fps|set-res|setBool|subspan|toLower|toUpper|always|assert|assign|bundle|custom|delete|deload|equals|exists|global|invoke|lStrip|length|listen|median|member|mirror|object|rStrip|reload|remove|setInt|square|stddev|strLen|stride|string|toBool|unlock|update|array|batch|clear|close|crash|debug|draft|empty|error|false|fetch|first|floor|match|other|parse|print|query|regex|rmlui|round|slide|spawn|split|state|store|strip|throw|toInt|beep|bind|copy|echo|eval|exit|grid|help|ifft|iota|json|lPad|last|list|load|lock|move|nand|once|open|push|rPad|root|save|sort|sqrt|task|time|true|type|view|wait|warn|xnor|add|all|and|cam|cat|div|env|fft|for|geq|get|int|key|leq|log|map|max|min|mod|mul|neq|nop|nor|not|off|pad|pow|rng|set|sgn|sub|sum|xor|at|eq|gt|if|ls|lt|on|or)\\b" }, { "name": "markup.underline.link", diff --git a/doc/Commands.md b/doc/Commands.md index 37ca9fc28..ac257b557 100644 --- a/doc/Commands.md +++ b/doc/Commands.md @@ -2,7 +2,7 @@ This documentation is automatically generated. -Generated on: Tue Aug 25 19:16:25 CEST 2026 +Generated on: Thu Aug 27 08:43:11 CEST 2026 ## Table of Contents @@ -2104,6 +2104,7 @@ Available Functions | `echo` | Echoes the provided arguments to the console, with newline. | | `ensureArray` | Ensures the current JSON value is an array. | | `enumerate` | Enumerates the array in the current JSON value. | +| `enumerateInline` | Enumerates the array in the current JSON value using a provided key. | | `eq` | Checks if the current JSON value is equal to the specified value. | | `error` | Echoes the provided arguments to the console as an error message, with newline. | | `exists` | Checks if a specified key exists in the current JSON object. | @@ -2404,6 +2405,9 @@ Usage: |batchPadded -> {array} ``` Binds the elements of an array to the provided keys. +think of C++ structured bindings: auto [key1, key2, key3] = arr; +Fails if the given scope is not an array or if no keys are provided. +Inserts empty objects for missing values in the array. Usage: |bind ... -> {object} ``` @@ -2411,6 +2415,7 @@ Usage: |bind ... -> {object} ``` Gathers all members from the provided keys into an array. +Inserts empty objects for missing values in the object. Usage: |bundle ... -> {array} ``` @@ -2503,6 +2508,15 @@ Usage: |enumerate -> {array} Where indexKey is the key of each array element to populate with the index of the element in the array. ``` +#### `enumerateInline` + +``` +Enumerates the array in the current JSON value using a provided key. +Recommended over enumerate if the values stored are objects. +Usage: |enumerateInline -> {array} +Where indexKey is the key of each array element to populate with the index of the element in the array. +``` + #### `eq` ``` From 53c0c43fcf1c8399677ed3a1b4e537b219105789 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 27 Aug 2026 09:14:49 +0200 Subject: [PATCH 8/9] Refactor Collection::listMembersAndValues for potential speed increase --- .../Module/Transformation/Collection.cpp | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Nebulite/Module/Transformation/Collection.cpp b/src/Nebulite/Module/Transformation/Collection.cpp index d2cd8e363..9ff06d1ad 100644 --- a/src/Nebulite/Module/Transformation/Collection.cpp +++ b/src/Nebulite/Module/Transformation/Collection.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include // Nebulite @@ -43,7 +42,7 @@ bool Collection::map(std::span const args, Data::JsonSco return false; // still not an array, something went wrong } - std::size_t const arraySize = jsonDoc.memberSize(rootKey); + auto const arraySize = jsonDoc.memberSize(rootKey); for (std::uint32_t idx = 0; idx < arraySize; ++idx) { // Set temp document with current element auto const elementKey = rootKey.addIndex(idx); @@ -84,27 +83,31 @@ bool Collection::listMembers(Data::JsonScope& jsonDoc){ } bool Collection::listMembersAndValues(Data::JsonScope& jsonDoc){ - // Copy values auto const membersAndKeys = jsonDoc.listAvailableMembersAndKeys(rootKey); - std::vector values; - std::ranges::for_each( - membersAndKeys, - [&](auto const& memberAndKey) { - auto const& [member, key] = memberAndKey; - Data::Json newObject; - newObject.deserialize(jsonDoc.serialize(key)); - values.push_back(std::move(newObject)); - } - ); + auto const members = membersAndKeys + | std::views::transform([]([[clang::lifetimebound]] auto const& memberAndKey) -> auto const& { + return memberAndKey.member; + }); + + auto const keys = membersAndKeys + | std::views::transform([]([[clang::lifetimebound]] auto const& memberAndKey) -> auto const& { + return memberAndKey.key; + }); + + // Copy values + auto const values = keys + | std::views::transform([&](auto const& key) { + return jsonDoc.getSubDoc(key); + }) + | std::ranges::to(); // Reinsert, enumerated jsonDoc.removeMember(rootKey); jsonDoc.setEmptyArray(rootKey); std::ranges::for_each( - membersAndKeys | Utility::Ranges::enumerate, - [&](auto const& enumeratedMemberAndKey) { - auto const& [index, memberAndKey] = enumeratedMemberAndKey; - auto const& [member, key] = memberAndKey; + members | Utility::Ranges::enumerate, + [&](auto const& enumeratedMember) { + auto const& [index, member] = enumeratedMember; auto const key1 = rootKey.addIndex(index).addMember("key"); auto const key2 = rootKey.addIndex(index).addMember("value"); jsonDoc.set(key1,member); From 5583e310d1741bca3953b427d7a14fa207fdae61 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 27 Aug 2026 09:19:26 +0200 Subject: [PATCH 9/9] Update JsonScope documentation and add todo to late-init the ordered cache system. --- include/Nebulite/Data/Document/JsonScope.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/Nebulite/Data/Document/JsonScope.hpp b/include/Nebulite/Data/Document/JsonScope.hpp index 16a7fb3dd..2d9cc9fdc 100644 --- a/include/Nebulite/Data/Document/JsonScope.hpp +++ b/include/Nebulite/Data/Document/JsonScope.hpp @@ -46,7 +46,8 @@ namespace Nebulite::Data { * @details It allows for modifications to a JSON document within a specific scope, * that is a key-prefixed section of the document. This is useful for modular data management, * where different parts of a JSON document can be managed independently. - * Holds little data itself, mostly acts as a scoped view over an existing JSON document or another JsonScope. + * This class also includes an ordered cache list system for fast caching of numeric value references, + * breaking down the complexity of set/get operations into a more efficient structure for hot paths. */ class JsonScope final { public: @@ -72,6 +73,7 @@ class JsonScope final { /** * @brief Mapped ordered double pointers intended for non-locking access + * @todo Is a lazy init possible? This could reduce the memory footprint of JsonScope instances and make copying potentially cheaper. */ alignas(Constants::Alignment::simdAlign) std::array odpCache; @@ -307,7 +309,7 @@ class JsonScope final { [[nodiscard]] std::vector listAvailableKeys(ScopedKeyView const& key) const ; [[nodiscard]] std::vector listAvailableKeys(ScopedKey const& key) const ; - // Helper struct for holding a member as well as its full key + // Helper struct for holding a member name as well as its full key struct MemberAndKey { std::string member; ScopedKey key;