import "../../types/index.mjs"; import { RuleType } from "../../types/ruleGroups.mjs"; import { RuleGroupTypeAny } from "../../types/ruleGroupsIC.mjs"; import { ConstituentWordOrder, FormatQueryOptions, GroupVariantCondition, NLTranslationKey, NLTranslations, ValueProcessorByRule, ValueProcessorLegacy, ValueProcessorOptions } from "../../types/export.mjs"; import { SetRequired } from "../../types/typeUtils.mjs"; /** * Maps a {@link DefaultOperatorName} to a SQL operator. * * @group Export */ export declare const mapSQLOperator: (rqbOperator: string) => string; /** * Returns a preset-aware SQL string-concatenation function. Emits `CONCAT(a, b, ...)` when * `concatOperator` is `"CONCAT"` (case-insensitive), otherwise joins with the infix operator * (e.g. `a || b`, `a + b`). * * @group Export */ export declare const getSQLConcat: (concatOperator?: string) => (...values: string[]) => string; /** * Returns the `[prefix, suffix]` `LIKE` wildcards for a string-match operator (e.g. `contains` * → `['%', '%']`, `beginsWith` → `['', '%']`, `endsWith` → `['%', '']`). Unknown operators * yield `['', '']`. * * @group Export */ export declare const getLikeWildcards: (operatorLC: string) => [string, string]; /** * Wraps an already-serialized SQL fragment (a quoted field name or an expression) with the * `LIKE` wildcards for the given (lowercase) string-match operator, concatenating the literal * `%` markers via the preset-aware {@link getSQLConcat}. Returns the fragment untouched for * operators without wildcards. * * @group Export */ export declare const wrapLikeFragment: (fragment: string, operatorLC: string, { concatOperator, quoteValuesWith, wrapValueWith }?: { concatOperator?: string; quoteValuesWith?: string; wrapValueWith?: [string, string]; }) => string; /** * Maps a (lowercase) {@link DefaultOperatorName} to a MongoDB operator. * * @group Export */ export declare const mongoOperators: { "=": string; "!=": string; "<": string; "<=": string; ">": string; ">=": string; in: string; notin: string; notIn: string; }; /** * Maps a (lowercase) {@link DefaultOperatorName} to a Prisma ORM operator. * * @group Export */ export declare const prismaOperators: { "=": string; "!=": string; "<": string; "<=": string; ">": string; ">=": string; in: string; notin: string; }; /** * Maps a {@link DefaultCombinatorName} to a CEL combinator. * * @group Export */ export declare const celCombinatorMap: { and: "&&"; or: "||"; }; /** * Register these operators with `jsonLogic` before applying the result * of `formatQuery(query, 'jsonlogic')`. * * @example * ``` * for (const [op, func] of Object.entries(jsonLogicAdditionalOperators)) { * jsonLogic.add_operation(op, func); * } * jsonLogic.apply({ "startsWith": [{ "var": "firstName" }, "Stev"] }, data); * ``` * * @group Export */ export declare const jsonLogicAdditionalOperators: Record<"startsWith" | "endsWith", (a: string, b: string) => boolean>; /** * Returns a new query object with all `string`-type `value` properties converted * to `number` where appropriate. * * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`. * * @group Export */ export declare const numerifyValues: (rg: RuleGroupTypeAny, options: SetRequired) => RuleGroupTypeAny; /** * Determines whether a value is _anything_ except an empty `string` or `NaN`. * * @group Export */ export declare const isValidValue: (value: unknown) => boolean; /** * Determines whether {@link formatQuery} should render the given value as a number. * As long as `parseNumbers` is `true`, `number` and `bigint` values will return `true` and * `string` values will return `true` if they test positive against {@link numericRegex}. * * @group Export */ export declare const shouldRenderAsNumber: (value: unknown, parseNumbers?: boolean) => boolean; /** * Used by {@link formatQuery} to determine whether the given value processor is a * "legacy" value processor by counting the number of arguments. Legacy value * processors take 3 arguments (not counting any arguments with default values), while * rule-based value processors take no more than 2 arguments. * * @group Export */ export declare const isValueProcessorLegacy: (valueProcessor: ValueProcessorLegacy | ValueProcessorByRule) => valueProcessor is ValueProcessorLegacy; /** * Converts the `quoteFieldNamesWith` option into an array of two strings. * If the option is a string, the array elements are both that string. * * @default * ['', ''] * * @group Export */ export declare const getQuoteFieldNamesWithArray: (quoteFieldNamesWith?: null | string | [string, string]) => [string, string]; /** * Given a field name and relevant {@link ValueProcessorOptions}, returns the field name * wrapped in the configured quote character(s). * * Unless `escape` is `false`, occurrences of the closing quote character within each * identifier part are doubled (standard SQL/MSSQL/MySQL identifier escaping, e.g. * `a"b` → `"a""b"`). Unquoted identifiers (no closing quote configured) can't be escaped * and are emitted verbatim. * * @group Export */ export declare const getQuotedFieldName: (fieldName: string, { quoteFieldNamesWith, fieldIdentifierSeparator }: ValueProcessorOptions, escape?: boolean) => string; /** * Escapes backslashes and single quotes for embedding in a single-quoted string literal * (Gremlin/Groovy, Painless, JS). Used for field names (property keys, `doc['…']`). * * @group Export */ export declare const escapeSingleQuotedString: (s: S) => S; /** * Renders a (possibly `.`-delimited) field name as a Cypher/GQL property path. Segments that * aren't plain identifiers are backtick-quoted, with embedded backticks doubled * (e.g. `n.first name` → ``n.`first name` ``). Plain identifiers are emitted as-is. * * @group Export */ export declare const quoteCypherIdentifier: (fieldName: string) => string; /** * Renders a (possibly `.`-delimited) field name as a JS property accessor on `obj` (default * `"this"`) for MongoDB `$where` expressions. Segments that aren't plain identifiers use * bracket notation with a JSON-escaped string (e.g. `a.b c` → `this.a["b c"]`). * * @group Export */ export declare const getJSPropertyAccessor: (fieldName: string, obj?: string) => string; /** * Given a [Constituent word order](https://en.wikipedia.org/wiki/Word_order#Constituent_word_orders) * like "svo" or "sov", returns a permutation of `["S", "V", "O"]` based on the first occurrence of * each letter in the input string (case insensitive). This widens the valid input from abbreviations * like "svo" to more expressive strings like "subject-verb-object" or "sub ver obj". Any missing * letters are appended in the default order "SVO" (e.g., "object" would yield `["O", "S", "V"]`). * * @group Export */ export declare const normalizeConstituentWordOrder: (input: string) => ConstituentWordOrder; /** * Prefixes a named-parameter value with the given `paramPrefix` unless the value already * begins with it. Used by {@link formatQuery} to render rules whose `valueSource` is * `"parameter"` (e.g. `"p1"` with prefix `":"` → `":p1"`; `":p1"` → `":p1"`). * * @group Export */ export declare const withParamPrefix: (value: unknown, paramPrefix?: string) => string; /** * Strips a leading `paramPrefix` from a named-parameter value if present. Inverse of * {@link withParamPrefix}; used to normalize parameter names for validation/lookup. * * @group Export */ export declare const stripParamPrefix: (value: unknown, paramPrefix?: string) => string; /** * Default translations used by {@link formatQuery} for "natural_language" format. * * @group Export */ export declare const defaultNLTranslations: NLTranslations; /** * Used by {@link formatQuery} to get a translation based on certain conditions * for the "natural_language" format. * * @group Export */ export declare const getNLTranslataion: (key: NLTranslationKey, translations: NLTranslations, conditions?: GroupVariantCondition[]) => string; type ProcessedMatchMode = { mode: "all"; threshold?: number | null | undefined; } | { mode: "none"; threshold?: number | null | undefined; } | { mode: "some"; threshold?: number | null | undefined; } | { mode: "atleast"; threshold: number; } | { mode: "atmost"; threshold: number; } | { mode: "exactly"; threshold: number; }; /** * Transforms * - `match: { mode: "atLeast", threshold: 1 }` to `match: { mode: "some" }` * - `match: { mode: "atMost", threshold: 0 }` to `match: { mode: "none" }`. * * Returns: * - Processed `{ mode, threshold }` object for valid subqueries * - `null` if match mode is not applicable for the rule * - `false` if match mode is valid, but either * 1. `threshold` is required and invalid, or * 2. `value` is not a valid rule group. */ export declare const processMatchMode: (rule: RuleType) => null | false | ProcessedMatchMode; /** * Base alias assigned to the element binding of a subquery generated for a rule's * {@link MatchMode `match` mode} (e.g. `unnest(field) as elem_alias`). */ export declare const subqueryElementAliasBase = "elem_alias"; /** * Returns the element alias for a subquery at the given nesting depth. Depth 0 (the common, * non-nested case) uses {@link subqueryElementAliasBase} unchanged; deeper levels are suffixed * with the depth, so a subquery nested within a subquery cannot shadow its parent's binding. * * Deterministic by depth rather than randomized, so output remains stable and snapshot-friendly. * * @group Export */ export declare const getSubqueryElementAlias: (subqueryDepth?: number) => string; /** * "Replacer" method for JSON.stringify's second argument. Converts `bigint` values to * objects with a `$bigint` property having a value of a string representation of * the actual `bigint`-type value. * * Inverse of {@link bigIntJsonParseReviver}. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json */ export declare const bigIntJsonStringifyReplacer: (_key: string, value: unknown) => unknown; /** * "Reviver" method for JSON.parse's second argument. Converts objects having a single * `$bigint: string` property to an actual `bigint` value. * * Inverse of {@link bigIntJsonStringifyReplacer}. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json */ export declare const bigIntJsonParseReviver: (_key: string, value: unknown) => unknown; /** * Determines whether an operator is a regular expression operator (`matches`/`doesNotMatch`, * case-insensitive). * * @group Export */ export declare const isRegexOperator: (operator: string) => boolean; /** * Filters regular expression flags to the given whitelist, removing duplicates. `g` and `y` * are never kept (stateful/irrelevant for match tests). * * @group Export */ export declare const sanitizeRegexFlags: (flags: unknown, whitelist?: string) => string; /** * Returns the pattern string of a `RegExp` (its `source`) or the string itself. * * @group Export */ export declare const toRegExpSource: (pattern: RegExp | string) => string; /** * Determines whether `pattern` is a valid (JS) regular expression with the given flags. * * @group Export */ export declare const isValidRegex: (pattern: unknown, flags?: string) => boolean; /** * Prefixes a pattern with inline flags (e.g. `(?i)`) for targets without a flags argument. * When `full` is `true` (target requires a full-string match), the pattern is wrapped in * `[\s\S]*(?:…)[\s\S]*` to preserve the unanchored "find" semantics of `matches` (spans * line terminators w/o altering the pattern's own `s` flag). * * @group Export */ export declare const toInlineFlagsRegex: (pattern: string, flags: unknown, { whitelist, full }?: { whitelist?: string; full?: boolean; }) => string; /** * Converts a `matches`/`doesNotMatch` rule to `contains`/`doesNotContain` with the pattern * as a literal value. Used by formats with no regular expression support. Other rules are * returned as-is. * * @group Export */ export declare const regexFallbackRule: (rule: R) => R; /** * Determines whether a rule is a `matches`/`doesNotMatch` rule with an invalid pattern. * Rules with a `valueSource` other than `"value"` are never considered invalid. * * @group Export */ export declare const isRegexRuleInvalid: (rule: RuleType) => boolean; export {};