UNPKG

@nlighten/json-transform-core

Version:

Core types and utilities for handling JSON transformers

1,070 lines (1,069 loc) 92.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { and: { description: "Evaluates to `true` if all values provided will evaluate to `true` (using the [Truthy logic](../truthy-logic))", inputSchema: { type: "array", required: true, description: "Values to check" }, outputSchema: { type: "boolean" }, }, at: { description: "Retrieves an element from a specific position inside an input array", inputSchema: { type: "array", required: true, description: "Array to fetch from" }, outputSchemaTemplate: { type: "object", description: "Same as value at specified index" }, arguments: [ { name: "index", description: "The index of element to return, **negative** indices will return element from the end (`-n -> length - n`)", type: "integer", position: 0, required: true, }, ], }, avg: { description: "Returns the average of all values in the array", inputSchema: { type: "array", required: true, description: "Array to average" }, outputSchema: { type: "number", $comment: "BigDecimal" }, arguments: [ { name: "default", description: "The default value to use for empty values", type: "BigDecimal", position: 0, default: 0.0, }, { name: "by", description: "A transformer to extract a property to sum by (using `##current` to refer to the current item)", type: "transformer", position: 1, default: "##current", transformerArguments: [{ name: "##current", type: "any", position: 0, description: "Current element" }], }, ], }, base64: { description: "Encode to or decode from base64", inputSchema: { type: "string", required: true, description: "Value to encode/decode" }, outputSchema: { type: "string" }, arguments: [ { name: "action", description: "Whether to encode or decode input", type: "enum", enum: ["ENCODE", "DECODE"], position: 0, default: "ENCODE", }, { name: "rfc", description: 'Which alphabet to use (`BASIC` = "The Base64 Alphabet" from RFC-2045, `URL` = "URL and Filename safe Base64 Alphabet" from RFC-4648, `MIME` = Same as `BASIC` but in lines with no more than 76 characters each)', type: "enum", enum: ["BASIC", "URL", "MIME"], position: 1, default: "BASIC", }, { name: "without_padding", description: "Don't add padding at the end of the output (The character `=`)", type: "boolean", position: 2, default: false, }, ], }, boolean: { description: "Evaluates input to boolean using the [Truthy logic](../truthy-logic)", usageNotes: 'Strings evaluation depends on `style` argument:\n- By default, value must be `"true"` for `true`.\n- Unless `style` is set to `JS`, then any non-empty value is `true`. Arrays and objects of size 0 returns `false`.\n', inputSchema: { type: "any" }, outputSchema: { type: "boolean" }, arguments: [ { name: "style", description: "Style of considering truthy values (`JS` only relates to string handling; not objects and arrays)", type: "enum", enum: ["JAVA", "JS"], position: 0, default: "JAVA", }, ], }, coalesce: { aliases: ["first"], description: "Returns the first non-null value", notes: ":::tip\nCoalesce can also be referred to as `$$first` instead of `$$coealesce`\n:::\n", inputSchema: { type: "array", required: true, description: "Array of elements (may include nulls)" }, outputSchemaTemplate: { type: "object", description: "Same as first non-null value" }, }, concat: { description: "Concatenates primary value array with elements or other arrays of elements", notes: ":::note\nElements which are `null` on the primary value will be ignored.\n:::", inputSchema: { type: "array", required: true, description: "Array of arrays / elements (null elements are ignored)", }, outputSchemaTemplate: { type: "array" }, }, contains: { description: "Checks whether an array contains a certain value", inputSchema: { type: "array", required: true, description: "Array of arrays / elements (null elements are ignored)", }, outputSchema: { type: "boolean" }, arguments: [{ name: "that", required: true, description: "The value to look for", type: "any", position: 0 }], }, csv: { description: "Converts an array of objects/arrays to a CSV string", inputSchema: { type: "array", required: true, description: "Array of objects/arrays" }, outputSchemaTemplate: { type: "string", description: "CSV" }, outputSchema: { type: "string" }, arguments: [ { name: "no_headers", description: "Whether to include object keys as headers (taken from first object if no `names`)", type: "boolean", position: 0, default: false, }, { name: "force_quote", description: "Whether to quote all the values", type: "boolean", position: 1, default: false, }, { name: "separator", description: "Use an alternative field separator", type: "string", position: 2, default: ",", }, { name: "names", description: "Names of fields to extract into csv if objects (will be used as the header row, unless `no_headers`)", type: "string[]", position: 3, }, ], }, csvparse: { description: "Converts a CSV string into an array of objects/arrays", inputSchema: { type: "string", required: true, description: "csv contents" }, outputSchema: { type: "array", items: { type: "object" } }, subfunctions: [ { if: [{ argument: "no_headers", equals: "TRUE" }], then: { outputSchema: { type: "array", items: { type: "array" } }, description: "Converts a CSV string into an array of arrays", arguments: [ { name: "no_headers", description: "Whether to treat the first row as object keys", type: "const", position: 0, const: true, }, { name: "separator", description: "Use an alternative field separator", type: "string", position: 1, default: ",", }, { name: "names", description: "Names of fields of input arrays (by indices) or objects (can sift if provided less names than there are in the objects provided)", type: "array", position: 2, }, ], }, }, ], arguments: [ { name: "no_headers", description: "Whether to treat the first row as object keys", type: "boolean", position: 0, default: false, }, { name: "separator", description: "Use an alternative field separator", type: "string", position: 1, default: ",", }, { name: "names", description: "Names of fields of input arrays (by indices) or objects (can sift if provided less names than there are in the objects provided)", type: "array", position: 2, }, ], }, date: { description: "Date manipulation and formatting utility", notes: ":::note\ninput must be a Date in ISO-8601 format or Date or Instant\n:::\n\n:::tip\nUseful to be used in conjunction with `#now` as input\n:::\n", inputSchema: { type: "string", required: true, description: "Date or Date-Time in ISO-8601 format" }, outputSchema: { type: "string", format: "date-time" }, subfunctions: [ { if: [{ argument: "format", equals: "ISO" }], then: { outputSchema: { type: "string", format: "date-time" }, description: "Returns the ISO-8601 representation of the input date (to the specified precision set by `digits`)", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "ISO", }, { name: "digits", description: "precision for time part (scale) 0|3|6|9|-1 (-1 means maximum)", type: "integer", position: 1, default: -1, }, ], }, }, { if: [{ argument: "format", equals: "GMT" }], then: { outputSchema: { type: "string" }, description: "RFC-1123 format", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "GMT", }, ], }, }, { if: [{ argument: "format", equals: "DATE" }], then: { outputSchema: { type: "string", format: "date" }, description: "Date part of ISO 8601", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "DATE", }, ], }, }, { if: [{ argument: "format", equals: "ADD" }], then: { outputSchema: { type: "string", format: "date-time" }, description: "Adds an amount chronological units (`ChronoUnit`, see Java docs) to input date", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "ADD", }, { name: "units", description: "Units to use (ChronoUnit)", type: "enum", enum: [ "NANOS", "MICROS", "MILLIS", "SECONDS", "MINUTES", "HOURS", "HALF_DAYS", "DAYS", "MONTHS", "YEARS", ], position: 1, required: true, }, { name: "amount", description: "Amount of units to add (can be negative)", type: "long", position: 2, default: 0, }, ], }, }, { if: [{ argument: "format", equals: "SUB" }], then: { outputSchema: { type: "string", format: "date-time" }, description: "Subtracts an amount chronological units (`ChronoUnit`, see Java docs) from input date", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "SUB", }, { name: "units", description: "Units to use (ChronoUnit)", type: "enum", enum: [ "NANOS", "MICROS", "MILLIS", "SECONDS", "MINUTES", "HOURS", "HALF_DAYS", "DAYS", "MONTHS", "YEARS", ], position: 1, required: true, }, { name: "amount", description: "Amount of units to subtract (can be negative)", type: "long", position: 2, default: 0, }, ], }, }, { if: [{ argument: "format", equals: "DIFF" }], then: { outputSchema: { type: "integer" }, description: "Calculate the difference between two dates in specified units.", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "DIFF", }, { name: "units", description: "Units to use (ChronoUnit)", type: "enum", enum: ["NANOS", "MICROS", "MILLIS", "SECONDS", "MINUTES", "HOURS", "HALF_DAYS", "DAYS"], position: 1, required: true, }, { name: "end", description: "End date", type: "string", position: 2, required: true, }, ], }, }, { if: [{ argument: "format", equals: "EPOCH" }], then: { outputSchema: { type: "integer" }, description: "Seconds passed since 1970-01-01; unless `resolution`=`MS` then milliseconds,", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "EPOCH", }, { name: "resolution", description: "Resolution of epoch (Seconds or Milliseconds)", type: "enum", enum: ["UNIX", "MS"], position: 1, default: "UNIX", }, ], }, }, { if: [{ argument: "format", equals: "FORMAT" }], then: { outputSchema: { type: "string" }, description: "Format using a date format pattern (Java style)", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "FORMAT", }, { name: "pattern", description: "Pattern to use", type: "string", position: 1, required: true }, { name: "timezone", description: "Time zone to use", type: "string", position: 2, default: "UTC" }, ], }, }, { if: [{ argument: "format", equals: "ZONE" }], then: { outputSchema: { type: "string", format: "date-time" }, description: "Returns the ISO-8601 with offset by specifying a timezone", arguments: [ { name: "format", type: "const", position: 0, required: true, const: "ZONE", }, { name: "zone", description: "Time zone to use\n- Java's `ZoneId` (with `SHORT_IDS`)", type: "enum", enum: [], position: 1, default: "UTC", }, ], }, }, ], arguments: [ { name: "format", description: "Formatter to use", type: "enum", enum: ["ISO", "GMT", "DATE", "ADD", "SUB", "DIFF", "EPOCH", "FORMAT", "ZONE"], position: 0, default: "ISO", }, ], }, decimal: { description: "Converts number to BigDecimal type", inputSchema: { type: "any", required: true, description: "Value to convert" }, outputSchema: { type: "number", $comment: "BigDecimal" }, arguments: [ { name: "scale", description: "Scale of BigDecimal to set (default is 10 max)", type: "integer", position: 0, default: -1, }, { name: "rounding", description: "Java\u0027s `RoundingMode`", type: "enum", enum: ["UP", "DOWN", "CEILING", "FLOOR", "HALF_UP", "HALF_DOWN", "HALF_EVEN"], position: 1, default: "HALF_UP", }, ], }, digest: { description: "Creates a message digest based on a supported algorithm", inputSchema: { type: "string" }, outputSchema: { type: "string" }, subfunctions: [ { if: [{ argument: "algorithm", equals: "JAVA" }], then: { outputSchema: { type: "integer" }, description: "Creates a message digest based on Java's hashCode()", arguments: [ { name: "algorithm", type: "const", position: 0, const: "JAVA", }, ], }, }, ], arguments: [ { name: "algorithm", description: "Hashing algorithm", type: "enum", enum: ["SHA-1", "SHA-256", "SHA-384", "SHA-512", "MD5", "JAVA"], position: 0, default: "SHA-1", }, { name: "format", description: 'Format of output (`BASE64` = "The Base64 Alphabet" from RFC-2045, `BAS64URL` = "URL and Filename safe Base64 Alphabet" from RFC-4648, `HEX` = Hexadecimal string)', type: "enum", enum: ["BASE64", "BASE64URL", "HEX"], position: 1, default: "BASE64", }, ], }, distinct: { description: "Returns a distinct array (repeating elements removed, only primitive values are supported if no `by` was specified)", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchemaTemplate: { type: "array", description: "Same items type as input" }, pipedType: true, arguments: [ { name: "by", description: "A mapping for each element to distinct by (instead of the whole element, using `##current` to refer to the current item)", type: "transformer", position: 0, default: "##current", transformerArguments: [{ name: "##current", type: "any", position: 0, description: "Current element" }], }, ], }, entries: { description: "Gets the entries* of an object or an array", notes: ":::note\n*Entry is in the form of `[ key / index, value ]`\n:::", inputSchema: { type: "any", required: true, description: "An `object` or an `array` to get entries from", }, outputSchema: { type: "array", items: { type: "array", items: [{ type: "string" }, { type: undefined }] }, }, }, eval: { description: "Evaluates the input and then transforms the context with the expression", inputSchema: { type: "any", required: true, description: "Transformer definition" }, }, every: { aliases: ["all"], description: "Checks if all elements in an array satisfy a predicate", usageNotes: ":::info\npredicate `by` should resolve to a `boolean` value, it uses the [truthy logic](../truthy-logic)\n:::", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchema: { type: "boolean" }, arguments: [ { name: "by", description: "A predicate transformer for an element", type: "transformer", position: 0, required: true, transformerArguments: [{ name: "##current", type: "any", position: 0, description: "Current element" }], }, ], }, filter: { description: "Filter input array to all the elements that satisfy the predicate transformer", usageNotes: ":::info\npredicate `by` should resolve to a `boolean` value, it uses the [truthy logic](../truthy-logic)\n:::", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchemaTemplate: { type: "array", description: "Same items type as input" }, pipedType: true, arguments: [ { name: "by", description: "A predicate transformer for an element", type: "transformer", position: 0, required: true, transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##index", type: "integer", position: 1, description: "Current index" }, ], }, ], }, find: { description: "Find the first element in a specified array that satisfy the predicate transformer", usageNotes: ":::info\npredicate `by` should resolve to a `boolean` value, it uses the [truthy logic](../truthy-logic)\n:::", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchemaTemplate: { type: "object", description: "Same as found element" }, arguments: [ { name: "by", description: "A predicate transformer for an element", type: "transformer", position: 0, default: "##current", transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##index", type: "integer", position: 1, description: "Current index" }, ], }, ], }, findindex: { description: "Find the index of the first element in a specified array that satisfy the predicate transformer.\n\nIf none of the elements satisfy the predicate the result will be `-1`.", usageNotes: ":::info\npredicate `by` should resolve to a `boolean` value, it uses the [truthy logic](../truthy-logic)\n:::", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchema: { type: "number" }, arguments: [ { name: "by", description: "A predicate transformer for an element", type: "transformer", position: 0, default: "##current", transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##index", type: "integer", position: 1, description: "Current index" }, ], }, ], }, flat: { description: "Flatten an array of arrays (non array elements will remain)", notes: ":::note\nAll `null` elements are removed from result\n:::", inputSchema: { type: "array", required: true, description: "Array of arrays / elements" }, outputSchemaTemplate: { type: "array" }, }, flatten: { description: "Flattens an object into a flat dot seperated list of entries", inputSchema: { type: "object", required: true, description: "any object" }, outputSchema: { type: "object" }, arguments: [ { name: "target", description: "A target to merge into", type: "object", position: 0, default: null }, { name: "prefix", description: "A prefix to add to the base", type: "string", position: 1, default: "" }, { name: "array_prefix", description: 'Sets how array elements indices should be prefixed (If not set, elements will be prefixed like ` ${index}`).\n - Set to `"#null"` to not flatten arrays.', type: "string", position: 2, default: "$", }, ], }, form: { description: "Converts an object to Form URL-Encoded string (a.k.a Query String)", notes: "- Array values will be treated as multiple values for the same key (so the key will be duplicated in the result for each of the values)", inputSchema: { type: "object", required: true }, outputSchemaTemplate: { type: "string", description: "form url-encoded string" }, outputSchema: { type: "string" }, }, formparse: { description: "Parses a Form URL-Encoded string to `object`", notes: "- Every element will have 2 forms in the result object:\n - Singular with its original query name (e.g. `q`)\n - Plural with its name suffixed with `$$` (e.g. `q$$`)", inputSchema: { type: "string", required: true, description: "form url-encoded string" }, outputSchema: { type: "object" }, }, group: { description: "Groups an array of entries into a map of `key -&gt; array` by a specified transformer (with optional nested grouping)", notes: "Sorts elements of an array", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchemaTemplate: { type: "object", description: "Map of `key -&gt; array`" }, outputSchema: { type: "object", additionalProperties: { type: "array" } }, arguments: [ { name: "by", description: "A transformer to extract a property to group by", type: "transformer", position: 0, required: true, transformerArguments: [{ name: "##current", type: "any", position: 0, description: "Current element" }], }, { name: "order", description: "Direction of ordering (ascending / descending)", type: "enum", enum: ["ASC", "DESC"], position: 1, default: "ASC", }, { name: "type", description: "Type of values to expect when ordering the input array", type: "enum", enum: ["AUTO", "STRING", "NUMBER", "BOOLEAN"], position: 2, default: "AUTO", }, { name: "then", description: 'An array of subsequent grouping. When previous sort had no difference (only when `by` specified)\n`{ "by": ..., "order": ..., "type": ...}` // same 3 fields as above (`by` is required)', type: "array", position: 3, }, ], }, if: { description: "Conditionally returns a value, if the evaluation of the condition argument is truthy (using the [Truthy logic](../truthy-logic)).\nA fallback value (if condition evaluates to false) is optional", usageNotes: ":::note\nAlternative form is available using \n```transformers \n{\n" + ' "$$if": [ /* condition */, /* then */, /* else ? */]\n' + "}\n```\nIf `then` is used, the primary argument is treated as a condition\n:::", inputSchema: { type: "any", required: true, description: "Condition", }, arguments: [ { name: "then", required: true, description: "Value to return if condition is true", type: "any", position: 0 }, { name: "else", description: "Value to return if condition is false", type: "any", position: 1, default: null }, ], }, indexof: { description: "Find the index of the first element that matches the specified value.", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchema: { type: "number" }, arguments: [ { name: "of", description: "The value to look for", type: "any", position: 0, required: true, }, ], }, is: { description: "Checks value for one or more predicates (all predicates must be satisfied)", usageNotes: ":::note\n**Inline form** supports only `that` and `op` arguments.\n:::\n\n:::tip\n`gt`/`gte`/`lt`/`lte` - Uses the [Comparison logic](../comparison-logic)\n:::", inputSchema: { type: "object", required: true, description: "Value to check against" }, outputSchema: { type: "boolean" }, arguments: [ { name: "op", description: "A type of check to do exclusively (goes together with `that`)", type: "enum", enum: ["IN", "NIN", "EQ", "=", "==", "NEQ", "!=", "<>", "GT", ">", "GTE", ">=", "LT", "<", "LTE", "<="], position: 0, }, { name: "that", description: "", type: "any", position: 1 }, { name: "in", description: "Array of values the input should be part of", type: "array" }, { name: "nin", description: "Array of values the input should **NOT** be part of", type: "array" }, { name: "eq", description: "A value the input should be equal to", type: "any" }, { name: "neq", description: "A value the input should **NOT** be equal to", type: "any" }, { name: "gt", description: "A value the input should be greater than (input > value)", type: "any" }, { name: "gte", description: "A value the input should be greater than or equal (input >= value)", type: "any", }, { name: "lt", description: "A value the input should be lower than (input < value)", type: "any" }, { name: "lte", description: "A value the input should be lower than or equal (input <= value)", type: "any", }, ], }, isnull: { description: "Returns true if value does not exist or equal to null", inputSchema: { type: "object", required: true, description: "value to check against" }, outputSchema: { type: "boolean" }, }, join: { description: 'Joins an array of input as strings with an optional delimiter (default is `""`), prefix and suffix. `null` values are omitted', inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchema: { type: "string" }, arguments: [ { name: "delimiter", description: "Delimiter to join any 2 adjacent elements", type: "string", position: 0, default: "", }, { name: "prefix", description: "A string to prefix the result", type: "string", position: 1, default: "" }, { name: "keep_nulls", description: "Whether to keep null values when joining", type: "boolean", position: 3, default: false, }, { name: "suffix", description: "A string to suffix the result", type: "string", position: 2, default: "" }, ], }, jsonparse: { description: "Parses input as JSON string", inputSchema: { type: "string", required: true, description: "JSON serialized string" }, outputSchemaTemplate: { type: "object", description: "Parsed value" }, outputSchema: { type: "object" }, }, jsonpatch: { description: "Apply patches defined by JSON Patch RFC-6902", argumentsNotes: '#### JSON Patch Operations\n\n| Operation | Example |\n|-----------|---------------------------------------------------------------------------------------------------|\n| Add | `{ "op":"add", "path":"/...", "value":"..." }` |\n| Remove | `{ "op":"remove", "path":"/..." }` |\n| Replace | `{ "op":"replace", "path":"/...", "value":"..." }` |\n| Move | `{ "op":"move", "path":"/...", "from":"/..." }` |\n| Copy | `{ "op":"copy", "path":"/...", "from":"/..." }` |\n| Test | `{ "op":"test", "path":"/...", "value":"..." }` (if test fails, the function result will be null) |', inputSchema: { type: "any", required: true, description: "Object to patch" }, outputSchemaTemplate: { type: "object", description: "Operations output" }, arguments: [ { name: "ops", description: "A list of operations", type: "array", position: 0, required: true, }, ], }, jsonpath: { description: "Query a JSON document using JSONPath", inputSchema: { type: "object", required: true, description: "Object to query" }, outputSchema: { type: "object" }, arguments: [ { name: "path", description: "JSONPath expression", type: "string", position: 0, required: true, }, { name: "options", description: "Configurations for the resolver, A list of options [by jayway](https://github.com/json-path/JsonPath?tab=readme-ov-file#tweaking-configuration)", type: "string[]", position: 1, default: ["SUPPRESS_EXCEPTIONS"], }, ], }, jsonpointer: { description: "Apply mutations or queries over an object using JSON Pointer (defined by RFC-6901)", inputSchema: { type: "object", required: true, description: "Object to query" }, outputSchemaTemplate: { type: "object", description: "Query result" }, outputSchema: { type: "object" }, arguments: [ { name: "op", description: "Operation", type: "enum", enum: ["GET", "SET", "REMOVE"], position: 0, required: true, }, { name: "pointer", description: "JSON Pointer to apply operation on (as defined by RFC-6901)", type: "string", position: 1, required: true, }, { name: "value", description: "Value to use (when operation is `SET`)", type: "any", position: 2, }, ], }, jwtparse: { description: "Parses JWT tokens and returns their payload", notes: ":::caution\nThis function does not **validate** the JWT. Only returns its payload (claims).\n:::", inputSchema: { type: "string", required: true, description: "JWT string" }, outputSchemaTemplate: { type: "object", description: "Token's payload" }, outputSchema: { type: "object" }, }, length: { description: "Returns the length of a value", inputSchema: { type: "any", required: true, description: "Value to check length of (`string`/`object`/`array`)" }, outputSchema: { type: "integer" }, arguments: [ { name: "type", description: "Restrict the type of value to check length of (if specified type no detected the result will be `null`)", type: "enum", enum: ["AUTO", "STRING", "ARRAY", "OBJECT"], position: 0, default: "AUTO", }, { name: "default_zero", description: "Whether to return 0 instead of `null` (on any kind of issue)", type: "boolean", position: 1, default: false, }, ], }, long: { description: "Converts to integer, all decimal digits are truncated", inputSchema: { type: "any", description: "Value to convert" }, outputSchema: { type: "integer", $comment: "Long" }, }, lookup: { description: "Joins multiple arrays of objects by a dynamic condition (transformer) on each pair of matches", usageNotes: '```transformers\n{\n "$$lookup": [ /* values */ ],\n "using": [\n { "with": [ /* values 2 */], "as": /* name 2 */, "on": /* Transformer */ },\n { "with": [ /* values 3 */], "as": /* name 3 */, "on": /* Transformer */ },\n ...\n ],\n "to": /* Transformer */\n}\n```', inputSchema: { type: "array", required: true, description: "Main array of elements" }, outputSchemaTemplate: { type: "array", description: "of type of `to`'s result or the merge of both primary array's item and `with`'s item", }, arguments: [ { name: "using", description: "Array of definitions of how to match other arrays to the main one", type: "array", position: 0, required: true, }, { name: "to", description: "Transformer to map each pair of elements to its value in the result array\n\nDefault behavior is to merge `##current` with `##{as}` (append & overwrite)", type: "transformer", position: 1, transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##{as}", type: "any", position: 1, description: "Matched element from `with`" }, { name: "...", type: "any", position: 2 }, ], }, { name: "using[].with", type: "array", required: true, description: "Array of elements to match with", }, { name: "using[].as", type: "string", required: true, description: "The name the elements from this entry will be referred as (`#{as}`)", }, { name: "using[].on", type: "transformer", required: true, description: "Evaluated condition on when to match an element from the main array and with array (uses the [Truthy logic](../truthy-logic))", transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##index", type: "any", position: 1, description: "Current index" }, { name: "##{as}", type: "any", position: 2, description: "the matched element from the array (replace `{as}` with the name provided in `as` argument)", }, ], }, ], }, lower: { description: "Converts a string to all lowercase letters", inputSchema: { type: "string", required: true, description: "Input string" }, outputSchema: { type: "string" }, }, map: { description: "Returns a mapped array applying the transformer on each of the elements", usageNotes: ":::note\nAlternative form is available using \n```transformers \n{\n" + ' "$$map": [ /* values */, /* to */ ]\n' + "}\n```\nIf `to` is used, the primary argument is treated only as values\n:::", inputSchema: { type: "array", required: true, description: "Array of elements" }, outputSchemaTemplate: { type: "array", description: "of type of `to`'s result" }, arguments: [ { name: "to", description: "Transformer to map each element to its value in the result array", type: "transformer", position: 0, required: true, transformerArguments: [ { name: "##current", type: "any", position: 0, description: "Current element" }, { name: "##index", type: "integer", position: 1, description: "Current index" }, ], }, ], }, match: { description: "Returns a matched substring from input by a pattern (and optionally group id)", inputSchema: { type: "string", required: true, description: "Input string" }, outputSchema: { type: "string" }, arguments: [ { name: "pattern", description: "Regular expression to match and extract from input string", type: "string", position: 0, required: true, }, { name: "group", description: "The group id to get", type: "integer", position: 1, default: 0 }, ], }, matchall: { description: "Returns all matches substring from input by a pattern (and optionally group id)", inputSchema: { type: "string", required: true, description: "Input string" }, outputSchema: { type: "array", items: { type: "string" } }, arguments: [ { name: "pattern", description: "Regular expression to match and extract from input string", type: "string", position: 0, required: true, }, { name: "group", description: "The group id to get", type: "integer", position: 1, default: 0 }, ], }, math: { description: "Evaluate a mathematical expression", inputSchema: { type: "BigDecimal", required: true, description: "`op1` / `op` / `array` (`[op1, op, op2]` / `[op, op1, op2]`)", }, usageNotes: '**OR**\n```transformers\n{\n "$$math": [/* operator */, /* operand 1 */, /* operand 2 ? */]\n}\n```\n**OR**\n```transformers\n{\n "$$math": [/* operand 1 */, /* operator */, /* operand 2 ? */]\n}\n```\n**OR**\n```transformers\n"$$math(<operand1>,<operator>,[operand2])"\n\n"$$math(<operator>,<operand1>,[operand2])"\n\n"$$math(<operator>,[operand2]):{operand1}"\n```', argumentsNotes: '#### Operators\n\n| `operator` | Action | Example |\n|---------------------------|------------------------|-----------------------------|\n| `+`, `ADD` | Addition | `"$$math(2,+,3)"` = `5` |\n| `-`, `SUB`, `SUBTRACT` | Subtraction | `"$$math(5,-,3)"` = `2` |\n| `*`, `MUL`, `MULTIPLY` | Multiplication | `"$$math(2,*,3)"` = `6` |\n| `/`, `DIV`, `DIVIDE` | Division | `"$$math(6,/,3)"` = `2` |\n| `//`, `INTDIV` | Integer division | `"$$math(7,//,3)"` = `2` |\n| `%`, `MOD`, `REMAINDER` | Modulu | `"$$math(7,%,3)"` = `1` |\n| `^`, `**`, `POW`, `POWER` | Power | `"$$math(2,^,3)"` = `8` |\n| `&`, `AND` | Bit-wise AND | `"$$math(6,&,3)"` = `2` |\n| `\\|`, `OR` | Bit-wise OR | `"$$math(6,OR,3)"` = `7` |\n| `~`, `XOR` | Bit-wise XOR | `"$$math(6,~,3)"` = `5` |\n| `<<`, `SHL` | Shift left (bit-wise) | `"$$math(6,>>,1)"` = `3` |\n| `>>`, `SHR` | Shift right (bit-wise) | `"$$math(6,<<,3)"` = `48` |\n| `MIN` | Minimum | `"$$math(MIN,4,2)"` = `2` |\n| `MAX` | Maximum | `"$$math(MAX,4,2)"` = `4` |\n| `SQRT` | Square root | `"$$math(SQRT,81)"` = `9` |\n| `ROUND` | Round | `"$$math(ROUND,4.6)"` = `5` |\n| `FLOOR` | Floor | `"$$math(FLOOR,4.6)"` = `4` |\n| `CEIL` | Ceil | `"$$math(CEIL,4.2)"` = `5` |\n| `ABS` | Absolute | `"$$math(ABS,-10)"` = `10` |\n| `NEG`, `NEGATE` | Negation | `"$$math(NEG,4)"` = `-4` |\n| `SIG`, `SIGNUM` | Sign Number | `"$$math(SIG,-42)"` = `-1` |\n', outputSchema: { type: "number", $comment: "BigDecimal" }, argumentsAsInputSchema: true, arguments: [ { name: "op1", description: "First operand", type: "BigDecimal", position: 0, required: true }, { name: "op", description: "Math operation (operator)", type: "enum", enum: [ "+", "-", "*", "/", "//", "%", "^", "&", "|", "~", "<<", ">>", "MIN", "MAX", "SQRT", "ROUND", "FLOOR", "CEIL", "ABS", "NEG", "SIG", ], position: 1, required: true, }, { name: "op2", description: "Second operand or scale for `ROUND`/`FLOOR`/`CEIL`", type: "BigDecimal", position: 2, default: 0.0, }, ], }, max: { description: "Returns the max of all values in the array",