@react-querybuilder/core 8.9.2 → 8.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{arrayUtils-BF1P8iHS.mjs → arrayUtils-A_OXU9W1.mjs} +3 -75
- package/dist/arrayUtils-A_OXU9W1.mjs.map +1 -0
- package/dist/arrayUtils-QxZOZTf6.js +73 -0
- package/dist/arrayUtils-QxZOZTf6.js.map +1 -0
- package/dist/basic-DEc65Kng.d.mts +363 -0
- package/dist/basic-Dd_M2f3M.d.ts +363 -0
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +806 -1366
- package/dist/cjs/react-querybuilder_core.cjs.development.js +455 -116
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +806 -1366
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-H7RhQiIc.mjs → convertQuery-CqX3rPvj.mjs} +3 -3
- package/dist/{convertQuery-H7RhQiIc.mjs.map → convertQuery-CqX3rPvj.mjs.map} +1 -1
- package/dist/{export-DyrnTh6K.d.ts → export-Dy4FckB-.d.ts} +7 -6
- package/dist/{export-r-V7bU31.d.mts → export-t1V2N8pz.d.mts} +7 -6
- package/dist/formatQuery.d.mts +3 -2
- package/dist/formatQuery.d.ts +3 -2
- package/dist/formatQuery.js +217 -87
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +217 -87
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-Cksobmln.d.ts → import-Cz8canKo.d.mts} +3 -3
- package/dist/{import-BwbbP4oU.d.mts → import-DtS9Ocx5.d.ts} +3 -3
- package/dist/{isRuleGroup-CnhYpLOM.mjs → isRuleGroup-CYcfPgbg.mjs} +2 -2
- package/dist/{isRuleGroup-CnhYpLOM.mjs.map → isRuleGroup-CYcfPgbg.mjs.map} +1 -1
- package/dist/lexer-C53tqS2p.js +406 -0
- package/dist/lexer-C53tqS2p.js.map +1 -0
- package/dist/{optGroupUtils-CXLgyg2i.js → optGroupUtils-B0hTpodo.js} +114 -1
- package/dist/optGroupUtils-B0hTpodo.js.map +1 -0
- package/dist/{optGroupUtils-Duv-M8rf.mjs → optGroupUtils-VeZ3k7-1.mjs} +86 -3
- package/dist/optGroupUtils-VeZ3k7-1.mjs.map +1 -0
- package/dist/parseCEL.d.mts +292 -11
- package/dist/parseCEL.d.ts +292 -11
- package/dist/parseCEL.js +874 -1125
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +828 -1126
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +3 -2
- package/dist/parseJSONata.d.ts +3 -2
- package/dist/parseJSONata.js +49 -77
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +4 -5
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +4 -3
- package/dist/parseJsonLogic.d.ts +4 -3
- package/dist/parseJsonLogic.js +5 -6
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +5 -6
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +3 -2
- package/dist/parseMongoDB.d.ts +3 -2
- package/dist/parseMongoDB.js +15 -16
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +5 -6
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/{parseNumber-BtGKa58z.mjs → parseNumber-CXdMVNFx.mjs} +2 -2
- package/dist/{parseNumber-BtGKa58z.mjs.map → parseNumber-CXdMVNFx.mjs.map} +1 -1
- package/dist/{parseNumber-Bcys1kOH.js → parseNumber-D4iQDxK-.js} +1 -1
- package/dist/{parseNumber-Bcys1kOH.js.map → parseNumber-D4iQDxK-.js.map} +1 -1
- package/dist/parseSQL.d.mts +3 -2
- package/dist/parseSQL.d.ts +3 -2
- package/dist/parseSQL.js +2691 -3036
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +2691 -3037
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +3 -2
- package/dist/parseSpEL.d.ts +3 -2
- package/dist/parseSpEL.js +7 -9
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +5 -6
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BqFEs4eV.js → prepareQueryObjects-BOUWfel5.js} +4 -5
- package/dist/prepareQueryObjects-BOUWfel5.js.map +1 -0
- package/dist/{prepareQueryObjects-CS6Wmhmf.mjs → prepareQueryObjects-DPCC-iHp.mjs} +6 -7
- package/dist/prepareQueryObjects-DPCC-iHp.mjs.map +1 -0
- package/dist/query-builder-layout.css +1 -1
- package/dist/query-builder-layout.css.map +1 -1
- package/dist/query-builder.css +1 -1
- package/dist/query-builder.css.map +1 -1
- package/dist/react-querybuilder_core.d.mts +806 -1366
- package/dist/react-querybuilder_core.legacy-esm.d.ts +806 -1366
- package/dist/react-querybuilder_core.legacy-esm.js +455 -114
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +448 -117
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +806 -1366
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/styles/_layout.scss +61 -17
- package/dist/styles/_main.scss +22 -4
- package/dist/{transformQuery-FL_nlpp5.js → transformQuery-CWDPogO5.js} +1 -1
- package/dist/{transformQuery-FL_nlpp5.js.map → transformQuery-CWDPogO5.js.map} +1 -1
- package/dist/{transformQuery-DdMvmrCh.mjs → transformQuery-DCCpjtyq.mjs} +3 -3
- package/dist/{transformQuery-DdMvmrCh.mjs.map → transformQuery-DCCpjtyq.mjs.map} +1 -1
- package/dist/transformQuery.d.mts +1 -1
- package/dist/transformQuery.d.ts +1 -1
- package/dist/transformQuery.js +1 -1
- package/dist/transformQuery.mjs +2 -2
- package/package.json +14 -12
- package/dist/arrayUtils-BF1P8iHS.mjs.map +0 -1
- package/dist/arrayUtils-D5EoIsKP.js +0 -164
- package/dist/arrayUtils-D5EoIsKP.js.map +0 -1
- package/dist/basic-BfD-7CN3.d.mts +0 -1235
- package/dist/basic-C8xXKHIA.d.ts +0 -1235
- package/dist/objectUtils-BBZSfZJz.js +0 -17
- package/dist/objectUtils-BBZSfZJz.js.map +0 -1
- package/dist/objectUtils-BtWdcZVG.mjs +0 -11
- package/dist/objectUtils-BtWdcZVG.mjs.map +0 -1
- package/dist/optGroupUtils-CXLgyg2i.js.map +0 -1
- package/dist/optGroupUtils-Duv-M8rf.mjs.map +0 -1
- package/dist/prepareQueryObjects-BqFEs4eV.js.map +0 -1
- package/dist/prepareQueryObjects-CS6Wmhmf.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optGroupUtils-B0hTpodo.js","names":["defaultPlaceholderFieldName: typeof defaultPlaceholderName","defaultPlaceholderOperatorName: typeof defaultPlaceholderName","defaultOperatorNegationMap: Record<DefaultOperatorName, DefaultOperatorName>","defaultCombinators: DefaultCombinators","defaultCombinatorsExtended: DefaultCombinatorsExtended","isPojo","idObj: { name?: string; value?: string }","newArray: T[]"],"sources":["../src/defaults.ts","../src/utils/objectUtils.ts","../src/utils/optGroupUtils.ts"],"sourcesContent":["import type {\n BaseTranslationsFull,\n Classnames,\n DefaultCombinatorName,\n DefaultCombinatorNameExtended,\n DefaultOperatorName,\n MatchMode,\n Path,\n QueryBuilderFlags,\n StringUnionToFullOptionArray,\n} from './types';\n\n// DO NOT ALTER OR REMOVE REGION NAMES. Some of them are used\n// to generate code snippets in the documentation.\n\n/**\n * @group Defaults\n */\nexport const defaultPlaceholderName = '~';\n/**\n * @group Defaults\n */\nexport const defaultPlaceholderLabel = '------';\n/**\n * Default `name` for placeholder option in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldLabel: typeof defaultPlaceholderLabel = defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `name` for placeholder option in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `name` for placeholder option in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueLabel: typeof defaultPlaceholderLabel = defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n\n/**\n * Default configuration of translatable strings.\n *\n * @group Defaults\n */\n// #region docs-translations\nexport const defaultTranslations: BaseTranslationsFull = {\n fields: {\n title: 'Field',\n placeholderName: defaultPlaceholderFieldName,\n placeholderLabel: defaultPlaceholderFieldLabel,\n placeholderGroupLabel: defaultPlaceholderFieldGroupLabel,\n } as const,\n operators: {\n title: 'Operator',\n placeholderName: defaultPlaceholderOperatorName,\n placeholderLabel: defaultPlaceholderOperatorLabel,\n placeholderGroupLabel: defaultPlaceholderOperatorGroupLabel,\n } as const,\n values: {\n title: 'Values',\n placeholderName: defaultPlaceholderValueName,\n placeholderLabel: defaultPlaceholderValueLabel,\n placeholderGroupLabel: defaultPlaceholderValueGroupLabel,\n } as const,\n matchMode: { title: 'Match mode' } as const,\n matchThreshold: { title: 'Match threshold' } as const,\n value: { title: 'Value' } as const,\n removeRule: { label: '⨯', title: 'Remove rule' } as const,\n removeGroup: { label: '⨯', title: 'Remove group' } as const,\n addRule: { label: '+ Rule', title: 'Add rule' } as const,\n addGroup: { label: '+ Group', title: 'Add group' } as const,\n combinators: { title: 'Combinator' } as const,\n notToggle: { label: 'Not', title: 'Invert this group' } as const,\n cloneRule: { label: '⧉', title: 'Clone rule' } as const,\n cloneRuleGroup: { label: '⧉', title: 'Clone group' } as const,\n shiftActionUp: { label: '˄', title: 'Shift up' } as const,\n shiftActionDown: { label: '˅', title: 'Shift down' } as const,\n dragHandle: { label: '⁞⁞', title: 'Drag handle' } as const,\n lockRule: { label: '🔓', title: 'Lock rule' } as const,\n lockGroup: { label: '🔓', title: 'Lock group' } as const,\n lockRuleDisabled: { label: '🔒', title: 'Unlock rule' } as const,\n lockGroupDisabled: { label: '🔒', title: 'Unlock group' } as const,\n muteRule: { label: '🔊', title: 'Mute rule' } as const,\n muteGroup: { label: '🔊', title: 'Mute group' } as const,\n unmuteRule: { label: '🔇', title: 'Unmute rule' } as const,\n unmuteGroup: { label: '🔇', title: 'Unmute group' } as const,\n valueSourceSelector: { title: 'Value source' } as const,\n} satisfies BaseTranslationsFull;\n// #endregion\n\n/**\n * Default character used to `.join` and `.split` arrays.\n *\n * @group Defaults\n */\nexport const defaultJoinChar = ',';\n\nexport type DefaultOperators = StringUnionToFullOptionArray<DefaultOperatorName>;\n\nexport const defaultOperatorLabelMap: Record<DefaultOperatorName, string> = {\n '=': '=',\n '!=': '!=',\n '<': '<',\n '>': '>',\n '<=': '<=',\n '>=': '>=',\n contains: 'contains',\n beginsWith: 'begins with',\n endsWith: 'ends with',\n doesNotContain: 'does not contain',\n doesNotBeginWith: 'does not begin with',\n doesNotEndWith: 'does not end with',\n null: 'is null',\n notNull: 'is not null',\n in: 'in',\n notIn: 'not in',\n between: 'between',\n notBetween: 'not between',\n};\n\nexport const defaultCombinatorLabelMap: Record<DefaultCombinatorNameExtended, string> = {\n and: 'AND',\n or: 'OR',\n xor: 'XOR',\n};\n\n/**\n * Default operator list.\n *\n * @group Defaults\n */\n// #region docs-operators\nexport const defaultOperators: DefaultOperators = [\n { name: '=', value: '=', label: '=' },\n { name: '!=', value: '!=', label: '!=' },\n { name: '<', value: '<', label: '<' },\n { name: '>', value: '>', label: '>' },\n { name: '<=', value: '<=', label: '<=' },\n { name: '>=', value: '>=', label: '>=' },\n { name: 'contains', value: 'contains', label: 'contains' },\n { name: 'beginsWith', value: 'beginsWith', label: 'begins with' },\n { name: 'endsWith', value: 'endsWith', label: 'ends with' },\n { name: 'doesNotContain', value: 'doesNotContain', label: 'does not contain' },\n { name: 'doesNotBeginWith', value: 'doesNotBeginWith', label: 'does not begin with' },\n { name: 'doesNotEndWith', value: 'doesNotEndWith', label: 'does not end with' },\n { name: 'null', value: 'null', label: 'is null' },\n { name: 'notNull', value: 'notNull', label: 'is not null' },\n { name: 'in', value: 'in', label: 'in' },\n { name: 'notIn', value: 'notIn', label: 'not in' },\n { name: 'between', value: 'between', label: 'between' },\n { name: 'notBetween', value: 'notBetween', label: 'not between' },\n];\n// #endregion\n\n/**\n * Map of default operators to their respective opposite/negating operators.\n *\n * @group Defaults\n */\nexport const defaultOperatorNegationMap: Record<DefaultOperatorName, DefaultOperatorName> = {\n '=': '!=',\n '!=': '=',\n '<': '>=',\n '<=': '>',\n '>': '<=',\n '>=': '<',\n beginsWith: 'doesNotBeginWith',\n doesNotBeginWith: 'beginsWith',\n endsWith: 'doesNotEndWith',\n doesNotEndWith: 'endsWith',\n contains: 'doesNotContain',\n doesNotContain: 'contains',\n between: 'notBetween',\n notBetween: 'between',\n in: 'notIn',\n notIn: 'in',\n notNull: 'null',\n null: 'notNull',\n} satisfies Record<DefaultOperatorName, DefaultOperatorName>;\n\nexport type DefaultCombinators = StringUnionToFullOptionArray<DefaultCombinatorName>;\n\n/**\n * Default combinator list.\n *\n * @group Defaults\n */\n// #region docs-combinators\nexport const defaultCombinators: DefaultCombinators = [\n { name: 'and', value: 'and', label: 'AND' } as const,\n { name: 'or', value: 'or', label: 'OR' } as const,\n];\n// #endregion\n\nexport type DefaultCombinatorsExtended =\n StringUnionToFullOptionArray<DefaultCombinatorNameExtended>;\n\n/**\n * Default combinator list, with `XOR` added.\n *\n * @group Defaults\n */\nexport const defaultCombinatorsExtended: DefaultCombinatorsExtended = [\n ...defaultCombinators,\n { name: 'xor', value: 'xor', label: 'XOR' } as const,\n];\n\nexport type DefaultMatchModes = StringUnionToFullOptionArray<MatchMode>;\n\n/**\n * Default match modes.\n *\n * @group Defaults\n */\n// #region docs-matchmodes\nexport const defaultMatchModes: DefaultMatchModes = [\n { name: 'all', value: 'all', label: 'all' },\n { name: 'some', value: 'some', label: 'some' },\n { name: 'none', value: 'none', label: 'none' },\n { name: 'atLeast', value: 'atLeast', label: 'at least' },\n { name: 'atMost', value: 'atMost', label: 'at most' },\n { name: 'exactly', value: 'exactly', label: 'exactly' },\n];\n// #endregion\n\n/**\n * Standard classnames applied to each component.\n *\n * @group Defaults\n */\n// #region docs-standardclassnames\nexport const standardClassnames = {\n queryBuilder: 'queryBuilder',\n ruleGroup: 'ruleGroup',\n header: 'ruleGroup-header',\n body: 'ruleGroup-body',\n combinators: 'ruleGroup-combinators',\n addRule: 'ruleGroup-addRule',\n addGroup: 'ruleGroup-addGroup',\n cloneRule: 'rule-cloneRule',\n cloneGroup: 'ruleGroup-cloneGroup',\n removeGroup: 'ruleGroup-remove',\n notToggle: 'ruleGroup-notToggle',\n rule: 'rule',\n fields: 'rule-fields',\n matchMode: 'rule-matchMode',\n matchThreshold: 'rule-matchThreshold',\n operators: 'rule-operators',\n value: 'rule-value',\n removeRule: 'rule-remove',\n betweenRules: 'betweenRules',\n valid: 'queryBuilder-valid',\n invalid: 'queryBuilder-invalid',\n shiftActions: 'shiftActions',\n dndDragging: 'dndDragging',\n dndOver: 'dndOver',\n dndCopy: 'dndCopy',\n dndGroup: 'dndGroup',\n dndDropNotAllowed: 'dndDropNotAllowed',\n dragHandle: 'queryBuilder-dragHandle',\n disabled: 'queryBuilder-disabled',\n muted: 'queryBuilder-muted',\n lockRule: 'rule-lock',\n lockGroup: 'ruleGroup-lock',\n muteRule: 'rule-mute',\n muteGroup: 'ruleGroup-mute',\n valueSource: 'rule-valueSource',\n valueListItem: 'rule-value-list-item',\n branches: 'queryBuilder-branches',\n justified: 'queryBuilder-justified',\n hasSubQuery: 'rule-hasSubQuery',\n} as const;\n// #endregion\n\n/**\n * Default classnames for each component.\n *\n * @group Defaults\n */\nexport const defaultControlClassnames: Classnames = {\n queryBuilder: '',\n ruleGroup: '',\n header: '',\n body: '',\n combinators: '',\n addRule: '',\n addGroup: '',\n cloneRule: '',\n cloneGroup: '',\n removeGroup: '',\n notToggle: '',\n rule: '',\n fields: '',\n matchMode: '',\n matchThreshold: '',\n operators: '',\n value: '',\n removeRule: '',\n shiftActions: '',\n dragHandle: '',\n lockRule: '',\n lockGroup: '',\n muteRule: '',\n muteGroup: '',\n muted: '',\n valueSource: '',\n actionElement: '',\n valueSelector: '',\n betweenRules: '',\n valid: '',\n invalid: '',\n dndDragging: '',\n dndOver: '',\n dndGroup: '',\n dndCopy: '',\n dndDropNotAllowed: '',\n disabled: '',\n valueListItem: '',\n branches: '',\n hasSubQuery: '',\n} satisfies Classnames;\n\n/**\n * Default reason codes for a group being invalid.\n *\n * @group Defaults\n */\nexport const groupInvalidReasons = {\n empty: 'empty',\n invalidCombinator: 'invalid combinator',\n invalidIndependentCombinators: 'invalid independent combinators',\n} as const;\n\n/**\n * Component identifiers for testing.\n *\n * @group Defaults\n */\nexport const TestID = {\n rule: 'rule',\n ruleGroup: 'rule-group',\n inlineCombinator: 'inline-combinator',\n addGroup: 'add-group',\n removeGroup: 'remove-group',\n cloneGroup: 'clone-group',\n cloneRule: 'clone-rule',\n addRule: 'add-rule',\n removeRule: 'remove-rule',\n combinators: 'combinators',\n fields: 'fields',\n operators: 'operators',\n valueEditor: 'value-editor',\n notToggle: 'not-toggle',\n shiftActions: 'shift-actions',\n dragHandle: 'drag-handle',\n lockRule: 'lock-rule',\n lockGroup: 'lock-group',\n muteRule: 'mute-rule',\n muteGroup: 'mute-group',\n valueSourceSelector: 'value-source-selector',\n matchModeEditor: 'match-mode-editor',\n} as const;\n\nexport const LogType = {\n parentPathDisabled: 'action aborted: parent path disabled',\n pathDisabled: 'action aborted: path is disabled',\n queryUpdate: 'query updated',\n onAddRuleFalse: 'onAddRule callback returned false',\n onAddGroupFalse: 'onAddGroup callback returned false',\n onGroupRuleFalse: 'onGroupRule callback returned false',\n onGroupGroupFalse: 'onGroupGroup callback returned false',\n onMoveRuleFalse: 'onMoveRule callback returned false',\n onMoveGroupFalse: 'onMoveGroup callback returned false',\n onRemoveFalse: 'onRemove callback returned false',\n add: 'rule or group added',\n remove: 'rule or group removed',\n update: 'rule or group updated',\n move: 'rule or group moved',\n group: 'rule or group grouped with another',\n} as const;\n\n/**\n * The {@link Path} of the root group.\n *\n * @group Defaults\n */\nexport const rootPath: Path = [] satisfies Path;\n\n/**\n * Default values for all `boolean`\n * {@link react-querybuilder!QueryBuilder QueryBuilder} options.\n *\n * @group Defaults\n */\nexport const queryBuilderFlagDefaults: Required<QueryBuilderFlags> = {\n addRuleToNewGroups: false,\n autoSelectField: true,\n autoSelectOperator: true,\n autoSelectValue: false,\n debugMode: false,\n enableDragAndDrop: false,\n enableMountQueryChange: true,\n listsAsArrays: false,\n resetOnFieldChange: true,\n resetOnOperatorChange: false,\n showCloneButtons: false,\n showCombinatorsBetweenRules: false,\n showLockButtons: false,\n showMuteButtons: false,\n showNotToggle: false,\n showShiftActions: false,\n suppressStandardClassnames: false,\n};\n","// All code in this file is adapted from:\n// npm: https://www.npmjs.com/package/ts-extras\n// src: https://github.com/sindresorhus/ts-extras\n\n/**\n * Original looked like this (not sure why template string is used):\n * ```\n * type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;\n * ```\n */\ntype ObjectKeys<T extends object> = Exclude<keyof T, symbol>;\n\n/**\n * A strongly-typed version of `Object.keys()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)\n */\nexport const objectKeys = Object.keys as <Type extends object>(\n value: Type\n) => Array<ObjectKeys<Type>>;\n\n/**\n * A strongly-typed version of `Object.entries()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-entries.ts)\n */\nexport const objectEntries = Object.entries as <Type extends Record<PropertyKey, unknown>>(\n value: Type\n) => Array<[ObjectKeys<Type>, Type[ObjectKeys<Type>]]>;\n","import type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport type { RequireAtLeastOne } from 'type-fest';\nimport { defaultPlaceholderLabel, defaultPlaceholderName } from '../defaults';\nimport type {\n BaseOption,\n BaseOptionMap,\n FlexibleOption,\n FlexibleOptionGroup,\n FlexibleOptionList,\n FlexibleOptionListProp,\n FullOption,\n FullOptionList,\n FullOptionMap,\n FullOptionRecord,\n GetOptionIdentifierType,\n Option,\n OptionGroup,\n Placeholder,\n ToFullOption,\n ValueOption,\n WithUnknownIndex,\n} from '../types';\nimport { isPojo } from './misc';\nimport { objectKeys } from './objectUtils';\n\nconst isOptionWithName = (opt: BaseOption): opt is Option =>\n isPojo(opt) && 'name' in opt && typeof opt.name === 'string';\nconst isOptionWithValue = (opt: BaseOption): opt is ValueOption =>\n isPojo(opt) && 'value' in opt && typeof opt.value === 'string';\n\n/**\n * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})\n * into a {@link FullOption}. Full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOption<Opt extends BaseOption>(\n opt: Opt | string,\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): ToFullOption<Opt> {\n const recipe: (o: Opt | string) => ToFullOption<Opt> = produce(draft => {\n const idObj: { name?: string; value?: string } = {};\n let needsUpdating = !!baseProperties;\n\n if (typeof draft === 'string') {\n return {\n ...baseProperties,\n name: draft,\n value: draft,\n label: labelMap?.[draft] ?? draft,\n } as Draft<Opt>;\n }\n\n if (isOptionWithName(draft) && !isOptionWithValue(draft)) {\n idObj.value = draft.name;\n needsUpdating = true;\n } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {\n idObj.name = draft.value;\n needsUpdating = true;\n }\n\n if (needsUpdating) {\n return Object.assign({}, baseProperties, draft, idObj);\n }\n });\n return recipe(opt);\n}\n\n/**\n * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionList<Opt extends BaseOption>(\n optList: unknown[],\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): FullOptionList<Opt> {\n if (!Array.isArray(optList)) {\n return [] as unknown as FullOptionList<Opt>;\n }\n\n const recipe: (ol: FlexibleOptionList<Opt>) => FullOptionList<Opt> = produce(draft => {\n if (isFlexibleOptionGroupArray(draft)) {\n for (const optGroup of draft) {\n for (const [idx, opt] of optGroup.options.entries())\n optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n } else {\n for (const [idx, opt] of (draft as Opt[]).entries())\n draft[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n });\n\n return recipe(optList as FlexibleOptionList<Opt>);\n}\n\n/**\n * Converts a {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionMap<OptMap extends BaseOptionMap>(\n optMap: OptMap,\n baseProperties?: Record<string, unknown>\n): OptMap extends BaseOptionMap<infer V, infer K> ? Partial<Record<K, ToFullOption<V>>> : never {\n type FullOptMapType =\n OptMap extends BaseOptionMap<infer VT, infer KT>\n ? Partial<Record<KT, ToFullOption<VT>>>\n : never;\n\n return Object.fromEntries(\n (Object.entries(optMap) as [string, FlexibleOption][]).map(([k, v]) => [\n k,\n toFullOption(v, baseProperties),\n ])\n ) as FullOptMapType;\n}\n\n/**\n * @deprecated Renamed to {@link uniqByIdentifier}.\n *\n * @group Option Lists\n */\nexport const uniqByName = <\n T extends { name: string; value?: string } | { name?: string; value: string },\n>(\n originalArray: T[]\n): T[] => uniqByIdentifier(originalArray);\n\n/**\n * Generates a new array of objects with duplicates removed based\n * on the identifying property (`value` or `name`)\n *\n * @group Option Lists\n */\nexport const uniqByIdentifier = <\n T extends RequireAtLeastOne<{ name: string; value: string }, 'name' | 'value'>,\n>(\n originalArray: T[]\n): T[] => {\n const names = new Set<string>();\n const newArray: T[] = [];\n for (const el of originalArray) {\n if (!names.has((el.value ?? el.name)!)) {\n names.add((el.value ?? el.name)!);\n newArray.push(el);\n }\n }\n return originalArray.length === newArray.length ? originalArray : newArray;\n};\n\n/**\n * Determines if an {@link OptionList} is an {@link OptionGroup} array.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isOptionGroupArray = (arr: any): arr is OptionGroup<BaseOption>[] =>\n Array.isArray(arr) &&\n arr.length > 0 &&\n isPojo(arr[0]) &&\n 'options' in arr[0] &&\n Array.isArray(arr[0].options);\n\n/**\n * Determines if an array is a flat array of {@link FlexibleOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFlexibleOptionArray = (arr: any): arr is FlexibleOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) || isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if an array is a flat array of {@link FullOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFullOptionArray = (arr: any): arr is FullOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) && isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.\n *\n * @group Option Lists\n */\nexport const isFlexibleOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is FlexibleOptionGroup[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFlexibleOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link OptionGroup} array of {@link FullOption}.\n *\n * @group Option Lists\n */\nexport const isFullOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is OptionGroup<FullOption>[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFullOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Gets the option from an {@link OptionList} with the given `name`. Handles\n * {@link Option} arrays as well as {@link OptionGroup} arrays.\n *\n * @group Option Lists\n */\nexport function getOption<OptType extends FullOption>(\n arr: FullOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends ValueOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends Option>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends BaseOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined {\n const options = isFlexibleOptionGroupArray(arr, { allowEmpty: true })\n ? arr.flatMap(og => og.options)\n : arr;\n return options.find(op => op.value === name || op.name === name) as OptType | undefined;\n}\n\n/**\n * Gets the first option from an {@link OptionList}.\n *\n * @group Option Lists\n */\nexport function getFirstOption<Opt extends FullOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends ValueOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends Option>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends BaseOption>(\n arr?: FlexibleOptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null {\n if (!Array.isArray(arr) || arr.length === 0) {\n return null;\n } else if (isFlexibleOptionGroupArray(arr, { allowEmpty: true })) {\n for (const og of arr) {\n if (og.options.length > 0) {\n return (og.options[0].value ?? og.options[0].name) as GetOptionIdentifierType<Opt>;\n }\n }\n // istanbul ignore next\n return null;\n }\n\n return (arr[0].value ?? arr[0].name) as GetOptionIdentifierType<Opt>;\n}\n\n/**\n * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.\n * If the array is already flat, it is returned as is.\n *\n * @group Option Lists\n */\nexport const toFlatOptionArray = <T extends FullOption, OL extends FullOptionList<T>>(arr: OL) =>\n uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap(og => og.options) : arr) as T[];\n\n/**\n * Generates a new {@link OptionGroup} array with duplicates\n * removed based on the identifying property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptGroups = <T extends BaseOption>(\n originalArray: FlexibleOptionGroup<T>[]\n): OptionGroup<ToFullOption<T>>[] => {\n type K = T extends BaseOption<infer KT> ? KT : never;\n const labels = new Set<string>();\n const names = new Set<K>();\n const newArray: OptionGroup<ToFullOption<T>>[] = [];\n for (const el of originalArray) {\n if (!labels.has(el.label)) {\n labels.add(el.label);\n const optionsForThisGroup: WithUnknownIndex<ToFullOption<T>>[] = [];\n for (const opt of el.options) {\n if (!names.has((opt.value ?? opt.name) as K)) {\n names.add((opt.value ?? opt.name) as K);\n optionsForThisGroup.push(toFullOption(opt) as WithUnknownIndex<ToFullOption<T>>);\n }\n }\n newArray.push({ ...el, options: optionsForThisGroup });\n }\n }\n return newArray;\n};\n\n/**\n * Generates a new {@link Option} or {@link OptionGroup} array with duplicates\n * removed based on the identifier property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptList = <T extends BaseOption>(\n originalArray: FlexibleOptionList<T>\n): WithUnknownIndex<BaseOption & FullOption>[] | OptionGroup<ToFullOption<T>>[] => {\n if (isFlexibleOptionGroupArray(originalArray)) {\n return uniqOptGroups(originalArray) as OptionGroup<ToFullOption<T>>[];\n }\n return uniqByIdentifier((originalArray as BaseOption[]).map(o => toFullOption(o)));\n};\n\nexport interface PreparedOptionList<O extends FullOption> {\n defaultOption: FullOption;\n optionList: O[] | OptionGroup<O>[];\n optionsMap: Partial<FullOptionRecord<FullOption>>;\n}\n\nexport interface PrepareOptionListParams<O extends FullOption> {\n placeholder?: Placeholder;\n optionList?: FlexibleOptionListProp<O> | BaseOptionMap<O>;\n baseOption?: Record<string, unknown>;\n labelMap?: Record<string, string>;\n autoSelectOption?: boolean;\n}\n\nexport const prepareOptionList = <O extends FullOption>(\n props: PrepareOptionListParams<O>\n): PreparedOptionList<O> => {\n type OptionIdentifier = GetOptionIdentifierType<O>;\n\n // istanbul ignore next\n const {\n optionList: optionListPropOriginal,\n baseOption = {},\n labelMap = {},\n placeholder: {\n placeholderName = defaultPlaceholderName,\n placeholderLabel = defaultPlaceholderLabel,\n placeholderGroupLabel = defaultPlaceholderLabel,\n } = {},\n autoSelectOption = true,\n } = props;\n\n const defaultOption = {\n id: placeholderName,\n name: placeholderName,\n value: placeholderName,\n label: placeholderLabel,\n } as FullOption;\n\n const optionsProp = optionListPropOriginal ?? ([defaultOption] as FlexibleOptionList<O>);\n\n let optionList: O[] | OptionGroup<O>[] = [];\n const opts = (\n Array.isArray(optionsProp)\n ? toFullOptionList(optionsProp, baseOption, labelMap)\n : (objectKeys(toFullOptionMap(optionsProp, baseOption)) as unknown as OptionIdentifier[])\n .map<FullOption<OptionIdentifier>>(opt => ({\n ...optionsProp[opt]!,\n name: opt,\n value: opt,\n }))\n // oxlint-disable-next-line no-array-sort\n .sort((a, b) => a.label.localeCompare(b.label))\n ) as FullOptionList<O>;\n if (isFlexibleOptionGroupArray(opts)) {\n optionList = autoSelectOption\n ? (uniqOptGroups(opts) as FullOptionList<O>)\n : (uniqOptGroups([\n {\n label: placeholderGroupLabel,\n options: [defaultOption],\n },\n ...opts,\n ]) as FullOptionList<O>);\n } else {\n optionList = autoSelectOption\n ? (uniqByIdentifier(opts as O[]) as FullOptionList<O>)\n : (uniqByIdentifier([defaultOption, ...(opts as O[])]) as FullOptionList<O>);\n }\n\n let optionsMap: Partial<FullOptionRecord<FullOption>> = {};\n if (!Array.isArray(optionsProp)) {\n const op = toFullOptionMap(optionsProp, baseOption) as FullOptionMap<\n FullOption,\n OptionIdentifier\n >;\n optionsMap = autoSelectOption ? op : { ...op, [placeholderName]: defaultOption };\n } else {\n if (isFlexibleOptionGroupArray(optionList)) {\n for (const og of optionList) {\n for (const opt of og.options) {\n optionsMap[(opt.value ?? /* istanbul ignore next */ opt.name) as OptionIdentifier] =\n toFullOption(opt, baseOption) as FullOption;\n }\n }\n } else {\n for (const opt of optionList) {\n optionsMap[(opt.value ?? /* istanbul ignore next */ opt.name) as OptionIdentifier] =\n toFullOption(opt, baseOption) as FullOption;\n }\n }\n }\n\n return { defaultOption, optionList, optionsMap };\n};\n"],"mappings":"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"}
|
|
@@ -1,6 +1,89 @@
|
|
|
1
|
-
import { isPojo } from "./isRuleGroup-
|
|
1
|
+
import { i as isPojo } from "./isRuleGroup-CYcfPgbg.mjs";
|
|
2
2
|
import { produce } from "immer";
|
|
3
3
|
|
|
4
|
+
//#region src/defaults.ts
|
|
5
|
+
/**
|
|
6
|
+
* @group Defaults
|
|
7
|
+
*/
|
|
8
|
+
const defaultPlaceholderName = "~";
|
|
9
|
+
/**
|
|
10
|
+
* Default `name` for placeholder option in the `fields` array.
|
|
11
|
+
*
|
|
12
|
+
* @group Defaults
|
|
13
|
+
*/
|
|
14
|
+
const defaultPlaceholderFieldName = defaultPlaceholderName;
|
|
15
|
+
/**
|
|
16
|
+
* Default `name` for placeholder option in the `operators` array.
|
|
17
|
+
*
|
|
18
|
+
* @group Defaults
|
|
19
|
+
*/
|
|
20
|
+
const defaultPlaceholderOperatorName = defaultPlaceholderName;
|
|
21
|
+
/**
|
|
22
|
+
* Default character used to `.join` and `.split` arrays.
|
|
23
|
+
*
|
|
24
|
+
* @group Defaults
|
|
25
|
+
*/
|
|
26
|
+
const defaultJoinChar = ",";
|
|
27
|
+
/**
|
|
28
|
+
* Map of default operators to their respective opposite/negating operators.
|
|
29
|
+
*
|
|
30
|
+
* @group Defaults
|
|
31
|
+
*/
|
|
32
|
+
const defaultOperatorNegationMap = {
|
|
33
|
+
"=": "!=",
|
|
34
|
+
"!=": "=",
|
|
35
|
+
"<": ">=",
|
|
36
|
+
"<=": ">",
|
|
37
|
+
">": "<=",
|
|
38
|
+
">=": "<",
|
|
39
|
+
beginsWith: "doesNotBeginWith",
|
|
40
|
+
doesNotBeginWith: "beginsWith",
|
|
41
|
+
endsWith: "doesNotEndWith",
|
|
42
|
+
doesNotEndWith: "endsWith",
|
|
43
|
+
contains: "doesNotContain",
|
|
44
|
+
doesNotContain: "contains",
|
|
45
|
+
between: "notBetween",
|
|
46
|
+
notBetween: "between",
|
|
47
|
+
in: "notIn",
|
|
48
|
+
notIn: "in",
|
|
49
|
+
notNull: "null",
|
|
50
|
+
null: "notNull"
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Default combinator list.
|
|
54
|
+
*
|
|
55
|
+
* @group Defaults
|
|
56
|
+
*/
|
|
57
|
+
const defaultCombinators = [{
|
|
58
|
+
name: "and",
|
|
59
|
+
value: "and",
|
|
60
|
+
label: "AND"
|
|
61
|
+
}, {
|
|
62
|
+
name: "or",
|
|
63
|
+
value: "or",
|
|
64
|
+
label: "OR"
|
|
65
|
+
}];
|
|
66
|
+
/**
|
|
67
|
+
* Default combinator list, with `XOR` added.
|
|
68
|
+
*
|
|
69
|
+
* @group Defaults
|
|
70
|
+
*/
|
|
71
|
+
const defaultCombinatorsExtended = [...defaultCombinators, {
|
|
72
|
+
name: "xor",
|
|
73
|
+
value: "xor",
|
|
74
|
+
label: "XOR"
|
|
75
|
+
}];
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/utils/objectUtils.ts
|
|
79
|
+
/**
|
|
80
|
+
* A strongly-typed version of `Object.keys()`.
|
|
81
|
+
*
|
|
82
|
+
* [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)
|
|
83
|
+
*/
|
|
84
|
+
const objectKeys = Object.keys;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
4
87
|
//#region src/utils/optGroupUtils.ts
|
|
5
88
|
const isOptionWithName = (opt) => isPojo(opt) && "name" in opt && typeof opt.name === "string";
|
|
6
89
|
const isOptionWithValue = (opt) => isPojo(opt) && "value" in opt && typeof opt.value === "string";
|
|
@@ -98,5 +181,5 @@ function getOption(arr, name) {
|
|
|
98
181
|
const toFlatOptionArray = (arr) => uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap((og) => og.options) : arr);
|
|
99
182
|
|
|
100
183
|
//#endregion
|
|
101
|
-
export {
|
|
102
|
-
//# sourceMappingURL=optGroupUtils-
|
|
184
|
+
export { toFullOption as a, defaultJoinChar as c, defaultPlaceholderOperatorName as d, toFlatOptionArray as i, defaultOperatorNegationMap as l, isFlexibleOptionArray as n, toFullOptionList as o, isFlexibleOptionGroupArray as r, objectKeys as s, getOption as t, defaultPlaceholderFieldName as u };
|
|
185
|
+
//# sourceMappingURL=optGroupUtils-VeZ3k7-1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optGroupUtils-VeZ3k7-1.mjs","names":["defaultPlaceholderFieldName: typeof defaultPlaceholderName","defaultPlaceholderOperatorName: typeof defaultPlaceholderName","defaultOperatorNegationMap: Record<DefaultOperatorName, DefaultOperatorName>","defaultCombinators: DefaultCombinators","defaultCombinatorsExtended: DefaultCombinatorsExtended","idObj: { name?: string; value?: string }","newArray: T[]"],"sources":["../src/defaults.ts","../src/utils/objectUtils.ts","../src/utils/optGroupUtils.ts"],"sourcesContent":["import type {\n BaseTranslationsFull,\n Classnames,\n DefaultCombinatorName,\n DefaultCombinatorNameExtended,\n DefaultOperatorName,\n MatchMode,\n Path,\n QueryBuilderFlags,\n StringUnionToFullOptionArray,\n} from './types';\n\n// DO NOT ALTER OR REMOVE REGION NAMES. Some of them are used\n// to generate code snippets in the documentation.\n\n/**\n * @group Defaults\n */\nexport const defaultPlaceholderName = '~';\n/**\n * @group Defaults\n */\nexport const defaultPlaceholderLabel = '------';\n/**\n * Default `name` for placeholder option in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldLabel: typeof defaultPlaceholderLabel = defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `fields` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderFieldGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `name` for placeholder option in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `operators` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderOperatorGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n/**\n * Default `name` for placeholder option in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueName: typeof defaultPlaceholderName = defaultPlaceholderName;\n/**\n * Default `label` for placeholder option in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueLabel: typeof defaultPlaceholderLabel = defaultPlaceholderLabel;\n/**\n * Default `label` for placeholder option group in the `values` array.\n *\n * @group Defaults\n */\nexport const defaultPlaceholderValueGroupLabel: typeof defaultPlaceholderLabel =\n defaultPlaceholderLabel;\n\n/**\n * Default configuration of translatable strings.\n *\n * @group Defaults\n */\n// #region docs-translations\nexport const defaultTranslations: BaseTranslationsFull = {\n fields: {\n title: 'Field',\n placeholderName: defaultPlaceholderFieldName,\n placeholderLabel: defaultPlaceholderFieldLabel,\n placeholderGroupLabel: defaultPlaceholderFieldGroupLabel,\n } as const,\n operators: {\n title: 'Operator',\n placeholderName: defaultPlaceholderOperatorName,\n placeholderLabel: defaultPlaceholderOperatorLabel,\n placeholderGroupLabel: defaultPlaceholderOperatorGroupLabel,\n } as const,\n values: {\n title: 'Values',\n placeholderName: defaultPlaceholderValueName,\n placeholderLabel: defaultPlaceholderValueLabel,\n placeholderGroupLabel: defaultPlaceholderValueGroupLabel,\n } as const,\n matchMode: { title: 'Match mode' } as const,\n matchThreshold: { title: 'Match threshold' } as const,\n value: { title: 'Value' } as const,\n removeRule: { label: '⨯', title: 'Remove rule' } as const,\n removeGroup: { label: '⨯', title: 'Remove group' } as const,\n addRule: { label: '+ Rule', title: 'Add rule' } as const,\n addGroup: { label: '+ Group', title: 'Add group' } as const,\n combinators: { title: 'Combinator' } as const,\n notToggle: { label: 'Not', title: 'Invert this group' } as const,\n cloneRule: { label: '⧉', title: 'Clone rule' } as const,\n cloneRuleGroup: { label: '⧉', title: 'Clone group' } as const,\n shiftActionUp: { label: '˄', title: 'Shift up' } as const,\n shiftActionDown: { label: '˅', title: 'Shift down' } as const,\n dragHandle: { label: '⁞⁞', title: 'Drag handle' } as const,\n lockRule: { label: '🔓', title: 'Lock rule' } as const,\n lockGroup: { label: '🔓', title: 'Lock group' } as const,\n lockRuleDisabled: { label: '🔒', title: 'Unlock rule' } as const,\n lockGroupDisabled: { label: '🔒', title: 'Unlock group' } as const,\n muteRule: { label: '🔊', title: 'Mute rule' } as const,\n muteGroup: { label: '🔊', title: 'Mute group' } as const,\n unmuteRule: { label: '🔇', title: 'Unmute rule' } as const,\n unmuteGroup: { label: '🔇', title: 'Unmute group' } as const,\n valueSourceSelector: { title: 'Value source' } as const,\n} satisfies BaseTranslationsFull;\n// #endregion\n\n/**\n * Default character used to `.join` and `.split` arrays.\n *\n * @group Defaults\n */\nexport const defaultJoinChar = ',';\n\nexport type DefaultOperators = StringUnionToFullOptionArray<DefaultOperatorName>;\n\nexport const defaultOperatorLabelMap: Record<DefaultOperatorName, string> = {\n '=': '=',\n '!=': '!=',\n '<': '<',\n '>': '>',\n '<=': '<=',\n '>=': '>=',\n contains: 'contains',\n beginsWith: 'begins with',\n endsWith: 'ends with',\n doesNotContain: 'does not contain',\n doesNotBeginWith: 'does not begin with',\n doesNotEndWith: 'does not end with',\n null: 'is null',\n notNull: 'is not null',\n in: 'in',\n notIn: 'not in',\n between: 'between',\n notBetween: 'not between',\n};\n\nexport const defaultCombinatorLabelMap: Record<DefaultCombinatorNameExtended, string> = {\n and: 'AND',\n or: 'OR',\n xor: 'XOR',\n};\n\n/**\n * Default operator list.\n *\n * @group Defaults\n */\n// #region docs-operators\nexport const defaultOperators: DefaultOperators = [\n { name: '=', value: '=', label: '=' },\n { name: '!=', value: '!=', label: '!=' },\n { name: '<', value: '<', label: '<' },\n { name: '>', value: '>', label: '>' },\n { name: '<=', value: '<=', label: '<=' },\n { name: '>=', value: '>=', label: '>=' },\n { name: 'contains', value: 'contains', label: 'contains' },\n { name: 'beginsWith', value: 'beginsWith', label: 'begins with' },\n { name: 'endsWith', value: 'endsWith', label: 'ends with' },\n { name: 'doesNotContain', value: 'doesNotContain', label: 'does not contain' },\n { name: 'doesNotBeginWith', value: 'doesNotBeginWith', label: 'does not begin with' },\n { name: 'doesNotEndWith', value: 'doesNotEndWith', label: 'does not end with' },\n { name: 'null', value: 'null', label: 'is null' },\n { name: 'notNull', value: 'notNull', label: 'is not null' },\n { name: 'in', value: 'in', label: 'in' },\n { name: 'notIn', value: 'notIn', label: 'not in' },\n { name: 'between', value: 'between', label: 'between' },\n { name: 'notBetween', value: 'notBetween', label: 'not between' },\n];\n// #endregion\n\n/**\n * Map of default operators to their respective opposite/negating operators.\n *\n * @group Defaults\n */\nexport const defaultOperatorNegationMap: Record<DefaultOperatorName, DefaultOperatorName> = {\n '=': '!=',\n '!=': '=',\n '<': '>=',\n '<=': '>',\n '>': '<=',\n '>=': '<',\n beginsWith: 'doesNotBeginWith',\n doesNotBeginWith: 'beginsWith',\n endsWith: 'doesNotEndWith',\n doesNotEndWith: 'endsWith',\n contains: 'doesNotContain',\n doesNotContain: 'contains',\n between: 'notBetween',\n notBetween: 'between',\n in: 'notIn',\n notIn: 'in',\n notNull: 'null',\n null: 'notNull',\n} satisfies Record<DefaultOperatorName, DefaultOperatorName>;\n\nexport type DefaultCombinators = StringUnionToFullOptionArray<DefaultCombinatorName>;\n\n/**\n * Default combinator list.\n *\n * @group Defaults\n */\n// #region docs-combinators\nexport const defaultCombinators: DefaultCombinators = [\n { name: 'and', value: 'and', label: 'AND' } as const,\n { name: 'or', value: 'or', label: 'OR' } as const,\n];\n// #endregion\n\nexport type DefaultCombinatorsExtended =\n StringUnionToFullOptionArray<DefaultCombinatorNameExtended>;\n\n/**\n * Default combinator list, with `XOR` added.\n *\n * @group Defaults\n */\nexport const defaultCombinatorsExtended: DefaultCombinatorsExtended = [\n ...defaultCombinators,\n { name: 'xor', value: 'xor', label: 'XOR' } as const,\n];\n\nexport type DefaultMatchModes = StringUnionToFullOptionArray<MatchMode>;\n\n/**\n * Default match modes.\n *\n * @group Defaults\n */\n// #region docs-matchmodes\nexport const defaultMatchModes: DefaultMatchModes = [\n { name: 'all', value: 'all', label: 'all' },\n { name: 'some', value: 'some', label: 'some' },\n { name: 'none', value: 'none', label: 'none' },\n { name: 'atLeast', value: 'atLeast', label: 'at least' },\n { name: 'atMost', value: 'atMost', label: 'at most' },\n { name: 'exactly', value: 'exactly', label: 'exactly' },\n];\n// #endregion\n\n/**\n * Standard classnames applied to each component.\n *\n * @group Defaults\n */\n// #region docs-standardclassnames\nexport const standardClassnames = {\n queryBuilder: 'queryBuilder',\n ruleGroup: 'ruleGroup',\n header: 'ruleGroup-header',\n body: 'ruleGroup-body',\n combinators: 'ruleGroup-combinators',\n addRule: 'ruleGroup-addRule',\n addGroup: 'ruleGroup-addGroup',\n cloneRule: 'rule-cloneRule',\n cloneGroup: 'ruleGroup-cloneGroup',\n removeGroup: 'ruleGroup-remove',\n notToggle: 'ruleGroup-notToggle',\n rule: 'rule',\n fields: 'rule-fields',\n matchMode: 'rule-matchMode',\n matchThreshold: 'rule-matchThreshold',\n operators: 'rule-operators',\n value: 'rule-value',\n removeRule: 'rule-remove',\n betweenRules: 'betweenRules',\n valid: 'queryBuilder-valid',\n invalid: 'queryBuilder-invalid',\n shiftActions: 'shiftActions',\n dndDragging: 'dndDragging',\n dndOver: 'dndOver',\n dndCopy: 'dndCopy',\n dndGroup: 'dndGroup',\n dndDropNotAllowed: 'dndDropNotAllowed',\n dragHandle: 'queryBuilder-dragHandle',\n disabled: 'queryBuilder-disabled',\n muted: 'queryBuilder-muted',\n lockRule: 'rule-lock',\n lockGroup: 'ruleGroup-lock',\n muteRule: 'rule-mute',\n muteGroup: 'ruleGroup-mute',\n valueSource: 'rule-valueSource',\n valueListItem: 'rule-value-list-item',\n branches: 'queryBuilder-branches',\n justified: 'queryBuilder-justified',\n hasSubQuery: 'rule-hasSubQuery',\n} as const;\n// #endregion\n\n/**\n * Default classnames for each component.\n *\n * @group Defaults\n */\nexport const defaultControlClassnames: Classnames = {\n queryBuilder: '',\n ruleGroup: '',\n header: '',\n body: '',\n combinators: '',\n addRule: '',\n addGroup: '',\n cloneRule: '',\n cloneGroup: '',\n removeGroup: '',\n notToggle: '',\n rule: '',\n fields: '',\n matchMode: '',\n matchThreshold: '',\n operators: '',\n value: '',\n removeRule: '',\n shiftActions: '',\n dragHandle: '',\n lockRule: '',\n lockGroup: '',\n muteRule: '',\n muteGroup: '',\n muted: '',\n valueSource: '',\n actionElement: '',\n valueSelector: '',\n betweenRules: '',\n valid: '',\n invalid: '',\n dndDragging: '',\n dndOver: '',\n dndGroup: '',\n dndCopy: '',\n dndDropNotAllowed: '',\n disabled: '',\n valueListItem: '',\n branches: '',\n hasSubQuery: '',\n} satisfies Classnames;\n\n/**\n * Default reason codes for a group being invalid.\n *\n * @group Defaults\n */\nexport const groupInvalidReasons = {\n empty: 'empty',\n invalidCombinator: 'invalid combinator',\n invalidIndependentCombinators: 'invalid independent combinators',\n} as const;\n\n/**\n * Component identifiers for testing.\n *\n * @group Defaults\n */\nexport const TestID = {\n rule: 'rule',\n ruleGroup: 'rule-group',\n inlineCombinator: 'inline-combinator',\n addGroup: 'add-group',\n removeGroup: 'remove-group',\n cloneGroup: 'clone-group',\n cloneRule: 'clone-rule',\n addRule: 'add-rule',\n removeRule: 'remove-rule',\n combinators: 'combinators',\n fields: 'fields',\n operators: 'operators',\n valueEditor: 'value-editor',\n notToggle: 'not-toggle',\n shiftActions: 'shift-actions',\n dragHandle: 'drag-handle',\n lockRule: 'lock-rule',\n lockGroup: 'lock-group',\n muteRule: 'mute-rule',\n muteGroup: 'mute-group',\n valueSourceSelector: 'value-source-selector',\n matchModeEditor: 'match-mode-editor',\n} as const;\n\nexport const LogType = {\n parentPathDisabled: 'action aborted: parent path disabled',\n pathDisabled: 'action aborted: path is disabled',\n queryUpdate: 'query updated',\n onAddRuleFalse: 'onAddRule callback returned false',\n onAddGroupFalse: 'onAddGroup callback returned false',\n onGroupRuleFalse: 'onGroupRule callback returned false',\n onGroupGroupFalse: 'onGroupGroup callback returned false',\n onMoveRuleFalse: 'onMoveRule callback returned false',\n onMoveGroupFalse: 'onMoveGroup callback returned false',\n onRemoveFalse: 'onRemove callback returned false',\n add: 'rule or group added',\n remove: 'rule or group removed',\n update: 'rule or group updated',\n move: 'rule or group moved',\n group: 'rule or group grouped with another',\n} as const;\n\n/**\n * The {@link Path} of the root group.\n *\n * @group Defaults\n */\nexport const rootPath: Path = [] satisfies Path;\n\n/**\n * Default values for all `boolean`\n * {@link react-querybuilder!QueryBuilder QueryBuilder} options.\n *\n * @group Defaults\n */\nexport const queryBuilderFlagDefaults: Required<QueryBuilderFlags> = {\n addRuleToNewGroups: false,\n autoSelectField: true,\n autoSelectOperator: true,\n autoSelectValue: false,\n debugMode: false,\n enableDragAndDrop: false,\n enableMountQueryChange: true,\n listsAsArrays: false,\n resetOnFieldChange: true,\n resetOnOperatorChange: false,\n showCloneButtons: false,\n showCombinatorsBetweenRules: false,\n showLockButtons: false,\n showMuteButtons: false,\n showNotToggle: false,\n showShiftActions: false,\n suppressStandardClassnames: false,\n};\n","// All code in this file is adapted from:\n// npm: https://www.npmjs.com/package/ts-extras\n// src: https://github.com/sindresorhus/ts-extras\n\n/**\n * Original looked like this (not sure why template string is used):\n * ```\n * type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;\n * ```\n */\ntype ObjectKeys<T extends object> = Exclude<keyof T, symbol>;\n\n/**\n * A strongly-typed version of `Object.keys()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)\n */\nexport const objectKeys = Object.keys as <Type extends object>(\n value: Type\n) => Array<ObjectKeys<Type>>;\n\n/**\n * A strongly-typed version of `Object.entries()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-entries.ts)\n */\nexport const objectEntries = Object.entries as <Type extends Record<PropertyKey, unknown>>(\n value: Type\n) => Array<[ObjectKeys<Type>, Type[ObjectKeys<Type>]]>;\n","import type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport type { RequireAtLeastOne } from 'type-fest';\nimport { defaultPlaceholderLabel, defaultPlaceholderName } from '../defaults';\nimport type {\n BaseOption,\n BaseOptionMap,\n FlexibleOption,\n FlexibleOptionGroup,\n FlexibleOptionList,\n FlexibleOptionListProp,\n FullOption,\n FullOptionList,\n FullOptionMap,\n FullOptionRecord,\n GetOptionIdentifierType,\n Option,\n OptionGroup,\n Placeholder,\n ToFullOption,\n ValueOption,\n WithUnknownIndex,\n} from '../types';\nimport { isPojo } from './misc';\nimport { objectKeys } from './objectUtils';\n\nconst isOptionWithName = (opt: BaseOption): opt is Option =>\n isPojo(opt) && 'name' in opt && typeof opt.name === 'string';\nconst isOptionWithValue = (opt: BaseOption): opt is ValueOption =>\n isPojo(opt) && 'value' in opt && typeof opt.value === 'string';\n\n/**\n * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})\n * into a {@link FullOption}. Full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOption<Opt extends BaseOption>(\n opt: Opt | string,\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): ToFullOption<Opt> {\n const recipe: (o: Opt | string) => ToFullOption<Opt> = produce(draft => {\n const idObj: { name?: string; value?: string } = {};\n let needsUpdating = !!baseProperties;\n\n if (typeof draft === 'string') {\n return {\n ...baseProperties,\n name: draft,\n value: draft,\n label: labelMap?.[draft] ?? draft,\n } as Draft<Opt>;\n }\n\n if (isOptionWithName(draft) && !isOptionWithValue(draft)) {\n idObj.value = draft.name;\n needsUpdating = true;\n } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {\n idObj.name = draft.value;\n needsUpdating = true;\n }\n\n if (needsUpdating) {\n return Object.assign({}, baseProperties, draft, idObj);\n }\n });\n return recipe(opt);\n}\n\n/**\n * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionList<Opt extends BaseOption>(\n optList: unknown[],\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): FullOptionList<Opt> {\n if (!Array.isArray(optList)) {\n return [] as unknown as FullOptionList<Opt>;\n }\n\n const recipe: (ol: FlexibleOptionList<Opt>) => FullOptionList<Opt> = produce(draft => {\n if (isFlexibleOptionGroupArray(draft)) {\n for (const optGroup of draft) {\n for (const [idx, opt] of optGroup.options.entries())\n optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n } else {\n for (const [idx, opt] of (draft as Opt[]).entries())\n draft[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n });\n\n return recipe(optList as FlexibleOptionList<Opt>);\n}\n\n/**\n * Converts a {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionMap<OptMap extends BaseOptionMap>(\n optMap: OptMap,\n baseProperties?: Record<string, unknown>\n): OptMap extends BaseOptionMap<infer V, infer K> ? Partial<Record<K, ToFullOption<V>>> : never {\n type FullOptMapType =\n OptMap extends BaseOptionMap<infer VT, infer KT>\n ? Partial<Record<KT, ToFullOption<VT>>>\n : never;\n\n return Object.fromEntries(\n (Object.entries(optMap) as [string, FlexibleOption][]).map(([k, v]) => [\n k,\n toFullOption(v, baseProperties),\n ])\n ) as FullOptMapType;\n}\n\n/**\n * @deprecated Renamed to {@link uniqByIdentifier}.\n *\n * @group Option Lists\n */\nexport const uniqByName = <\n T extends { name: string; value?: string } | { name?: string; value: string },\n>(\n originalArray: T[]\n): T[] => uniqByIdentifier(originalArray);\n\n/**\n * Generates a new array of objects with duplicates removed based\n * on the identifying property (`value` or `name`)\n *\n * @group Option Lists\n */\nexport const uniqByIdentifier = <\n T extends RequireAtLeastOne<{ name: string; value: string }, 'name' | 'value'>,\n>(\n originalArray: T[]\n): T[] => {\n const names = new Set<string>();\n const newArray: T[] = [];\n for (const el of originalArray) {\n if (!names.has((el.value ?? el.name)!)) {\n names.add((el.value ?? el.name)!);\n newArray.push(el);\n }\n }\n return originalArray.length === newArray.length ? originalArray : newArray;\n};\n\n/**\n * Determines if an {@link OptionList} is an {@link OptionGroup} array.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isOptionGroupArray = (arr: any): arr is OptionGroup<BaseOption>[] =>\n Array.isArray(arr) &&\n arr.length > 0 &&\n isPojo(arr[0]) &&\n 'options' in arr[0] &&\n Array.isArray(arr[0].options);\n\n/**\n * Determines if an array is a flat array of {@link FlexibleOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFlexibleOptionArray = (arr: any): arr is FlexibleOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) || isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if an array is a flat array of {@link FullOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFullOptionArray = (arr: any): arr is FullOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) && isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.\n *\n * @group Option Lists\n */\nexport const isFlexibleOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is FlexibleOptionGroup[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFlexibleOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link OptionGroup} array of {@link FullOption}.\n *\n * @group Option Lists\n */\nexport const isFullOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is OptionGroup<FullOption>[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFullOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Gets the option from an {@link OptionList} with the given `name`. Handles\n * {@link Option} arrays as well as {@link OptionGroup} arrays.\n *\n * @group Option Lists\n */\nexport function getOption<OptType extends FullOption>(\n arr: FullOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends ValueOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends Option>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends BaseOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined {\n const options = isFlexibleOptionGroupArray(arr, { allowEmpty: true })\n ? arr.flatMap(og => og.options)\n : arr;\n return options.find(op => op.value === name || op.name === name) as OptType | undefined;\n}\n\n/**\n * Gets the first option from an {@link OptionList}.\n *\n * @group Option Lists\n */\nexport function getFirstOption<Opt extends FullOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends ValueOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends Option>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends BaseOption>(\n arr?: FlexibleOptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null {\n if (!Array.isArray(arr) || arr.length === 0) {\n return null;\n } else if (isFlexibleOptionGroupArray(arr, { allowEmpty: true })) {\n for (const og of arr) {\n if (og.options.length > 0) {\n return (og.options[0].value ?? og.options[0].name) as GetOptionIdentifierType<Opt>;\n }\n }\n // istanbul ignore next\n return null;\n }\n\n return (arr[0].value ?? arr[0].name) as GetOptionIdentifierType<Opt>;\n}\n\n/**\n * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.\n * If the array is already flat, it is returned as is.\n *\n * @group Option Lists\n */\nexport const toFlatOptionArray = <T extends FullOption, OL extends FullOptionList<T>>(arr: OL) =>\n uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap(og => og.options) : arr) as T[];\n\n/**\n * Generates a new {@link OptionGroup} array with duplicates\n * removed based on the identifying property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptGroups = <T extends BaseOption>(\n originalArray: FlexibleOptionGroup<T>[]\n): OptionGroup<ToFullOption<T>>[] => {\n type K = T extends BaseOption<infer KT> ? KT : never;\n const labels = new Set<string>();\n const names = new Set<K>();\n const newArray: OptionGroup<ToFullOption<T>>[] = [];\n for (const el of originalArray) {\n if (!labels.has(el.label)) {\n labels.add(el.label);\n const optionsForThisGroup: WithUnknownIndex<ToFullOption<T>>[] = [];\n for (const opt of el.options) {\n if (!names.has((opt.value ?? opt.name) as K)) {\n names.add((opt.value ?? opt.name) as K);\n optionsForThisGroup.push(toFullOption(opt) as WithUnknownIndex<ToFullOption<T>>);\n }\n }\n newArray.push({ ...el, options: optionsForThisGroup });\n }\n }\n return newArray;\n};\n\n/**\n * Generates a new {@link Option} or {@link OptionGroup} array with duplicates\n * removed based on the identifier property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptList = <T extends BaseOption>(\n originalArray: FlexibleOptionList<T>\n): WithUnknownIndex<BaseOption & FullOption>[] | OptionGroup<ToFullOption<T>>[] => {\n if (isFlexibleOptionGroupArray(originalArray)) {\n return uniqOptGroups(originalArray) as OptionGroup<ToFullOption<T>>[];\n }\n return uniqByIdentifier((originalArray as BaseOption[]).map(o => toFullOption(o)));\n};\n\nexport interface PreparedOptionList<O extends FullOption> {\n defaultOption: FullOption;\n optionList: O[] | OptionGroup<O>[];\n optionsMap: Partial<FullOptionRecord<FullOption>>;\n}\n\nexport interface PrepareOptionListParams<O extends FullOption> {\n placeholder?: Placeholder;\n optionList?: FlexibleOptionListProp<O> | BaseOptionMap<O>;\n baseOption?: Record<string, unknown>;\n labelMap?: Record<string, string>;\n autoSelectOption?: boolean;\n}\n\nexport const prepareOptionList = <O extends FullOption>(\n props: PrepareOptionListParams<O>\n): PreparedOptionList<O> => {\n type OptionIdentifier = GetOptionIdentifierType<O>;\n\n // istanbul ignore next\n const {\n optionList: optionListPropOriginal,\n baseOption = {},\n labelMap = {},\n placeholder: {\n placeholderName = defaultPlaceholderName,\n placeholderLabel = defaultPlaceholderLabel,\n placeholderGroupLabel = defaultPlaceholderLabel,\n } = {},\n autoSelectOption = true,\n } = props;\n\n const defaultOption = {\n id: placeholderName,\n name: placeholderName,\n value: placeholderName,\n label: placeholderLabel,\n } as FullOption;\n\n const optionsProp = optionListPropOriginal ?? ([defaultOption] as FlexibleOptionList<O>);\n\n let optionList: O[] | OptionGroup<O>[] = [];\n const opts = (\n Array.isArray(optionsProp)\n ? toFullOptionList(optionsProp, baseOption, labelMap)\n : (objectKeys(toFullOptionMap(optionsProp, baseOption)) as unknown as OptionIdentifier[])\n .map<FullOption<OptionIdentifier>>(opt => ({\n ...optionsProp[opt]!,\n name: opt,\n value: opt,\n }))\n // oxlint-disable-next-line no-array-sort\n .sort((a, b) => a.label.localeCompare(b.label))\n ) as FullOptionList<O>;\n if (isFlexibleOptionGroupArray(opts)) {\n optionList = autoSelectOption\n ? (uniqOptGroups(opts) as FullOptionList<O>)\n : (uniqOptGroups([\n {\n label: placeholderGroupLabel,\n options: [defaultOption],\n },\n ...opts,\n ]) as FullOptionList<O>);\n } else {\n optionList = autoSelectOption\n ? (uniqByIdentifier(opts as O[]) as FullOptionList<O>)\n : (uniqByIdentifier([defaultOption, ...(opts as O[])]) as FullOptionList<O>);\n }\n\n let optionsMap: Partial<FullOptionRecord<FullOption>> = {};\n if (!Array.isArray(optionsProp)) {\n const op = toFullOptionMap(optionsProp, baseOption) as FullOptionMap<\n FullOption,\n OptionIdentifier\n >;\n optionsMap = autoSelectOption ? op : { ...op, [placeholderName]: defaultOption };\n } else {\n if (isFlexibleOptionGroupArray(optionList)) {\n for (const og of optionList) {\n for (const opt of og.options) {\n optionsMap[(opt.value ?? /* istanbul ignore next */ opt.name) as OptionIdentifier] =\n toFullOption(opt, baseOption) as FullOption;\n }\n }\n } else {\n for (const opt of optionList) {\n optionsMap[(opt.value ?? /* istanbul ignore next */ opt.name) as OptionIdentifier] =\n toFullOption(opt, baseOption) as FullOption;\n }\n }\n }\n\n return { defaultOption, optionList, optionsMap };\n};\n"],"mappings":"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"}
|
package/dist/parseCEL.d.mts
CHANGED
|
@@ -1,12 +1,228 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ParserCommonOptions } from "./import-
|
|
1
|
+
import { _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, h as DefaultOperatorName, m as DefaultCombinatorName, p as RuleGroupTypeIC, v as RuleType } from "./basic-DEc65Kng.mjs";
|
|
2
|
+
import { t as ParserCommonOptions } from "./import-Cz8canKo.mjs";
|
|
3
|
+
import { Except } from "type-fest";
|
|
3
4
|
|
|
5
|
+
//#region src/utils/parseCEL/types.d.ts
|
|
6
|
+
type CELExpressionType = "Addition" | "BooleanLiteral" | "BytesLiteral" | "ConditionalAnd" | "ConditionalExpr" | "ConditionalOr" | "Division" | "DynamicPropertyAccessor" | "ExpressionGroup" | "ExpressionList" | "FieldInit" | "FieldInits" | "FieldsObject" | "FloatLiteral" | "FunctionCall" | "Identifier" | "IntegerLiteral" | "List" | "Map" | "MapInit" | "MapInits" | "Member" | "Modulo" | "Multiplication" | "Negation" | "Negative" | "NullLiteral" | "Property" | "Relation" | "StringLiteral" | "Subtraction" | "Unary" | "UnsignedIntegerLiteral" | "LikeExpression";
|
|
7
|
+
type CELRelop = "==" | ">=" | ">" | "<=" | "<" | "!=" | "in";
|
|
8
|
+
interface CELExpression {
|
|
9
|
+
type: CELExpressionType;
|
|
10
|
+
}
|
|
11
|
+
interface CELIdentifier<LimitTo extends string = string> extends CELExpression {
|
|
12
|
+
type: "Identifier";
|
|
13
|
+
value: LimitTo;
|
|
14
|
+
}
|
|
15
|
+
interface CELStringLiteral extends CELExpression {
|
|
16
|
+
type: "StringLiteral";
|
|
17
|
+
value: `'${string}'` | `"${string}"` | `'''${string}'''` | `"""${string}"""`;
|
|
18
|
+
}
|
|
19
|
+
interface CELBytesLiteral extends CELExpression {
|
|
20
|
+
type: "BytesLiteral";
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
interface CELIntegerLiteral extends CELExpression {
|
|
24
|
+
type: "IntegerLiteral";
|
|
25
|
+
value: number;
|
|
26
|
+
}
|
|
27
|
+
interface CELUnsignedIntegerLiteral extends CELExpression {
|
|
28
|
+
type: "UnsignedIntegerLiteral";
|
|
29
|
+
value: number;
|
|
30
|
+
}
|
|
31
|
+
interface CELFloatLiteral extends CELExpression {
|
|
32
|
+
type: "FloatLiteral";
|
|
33
|
+
value: number;
|
|
34
|
+
}
|
|
35
|
+
interface CELBooleanLiteral extends CELExpression {
|
|
36
|
+
type: "BooleanLiteral";
|
|
37
|
+
value: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface CELNullLiteral extends CELExpression {
|
|
40
|
+
type: "NullLiteral";
|
|
41
|
+
value: null;
|
|
42
|
+
}
|
|
43
|
+
interface CELRelation extends CELExpression {
|
|
44
|
+
type: "Relation";
|
|
45
|
+
left: CELExpression;
|
|
46
|
+
operator: CELRelop;
|
|
47
|
+
right: CELExpression;
|
|
48
|
+
}
|
|
49
|
+
interface CELConditionalExpr extends CELExpression {
|
|
50
|
+
type: "ConditionalExpr";
|
|
51
|
+
condition: CELExpression;
|
|
52
|
+
valueIfTrue: CELExpression;
|
|
53
|
+
valueIfFalse: CELExpression;
|
|
54
|
+
}
|
|
55
|
+
interface CELNegation extends CELExpression {
|
|
56
|
+
type: "Negation";
|
|
57
|
+
negations: number;
|
|
58
|
+
value: CELPrimary;
|
|
59
|
+
}
|
|
60
|
+
interface CELNegative extends CELExpression {
|
|
61
|
+
type: "Negative";
|
|
62
|
+
negatives: number;
|
|
63
|
+
value: CELMember;
|
|
64
|
+
}
|
|
65
|
+
interface CELMember extends CELExpression {
|
|
66
|
+
type: "Member";
|
|
67
|
+
value?: CELPrimary;
|
|
68
|
+
left?: CELPrimary | CELMember;
|
|
69
|
+
right?: CELIdentifier;
|
|
70
|
+
list?: CELExpressionList;
|
|
71
|
+
}
|
|
72
|
+
interface CELMemberIdentifierChain extends CELMember {
|
|
73
|
+
type: "Member";
|
|
74
|
+
value: never;
|
|
75
|
+
left: CELMemberIdentifierChain;
|
|
76
|
+
right: CELIdentifier;
|
|
77
|
+
list: never;
|
|
78
|
+
}
|
|
79
|
+
interface CELMemberNegatedIdentifier extends CELNegation {
|
|
80
|
+
value: CELIdentifier;
|
|
81
|
+
}
|
|
82
|
+
interface CELMemberNegatedIdentifierChain extends CELExpression {
|
|
83
|
+
value: never;
|
|
84
|
+
left: CELMemberIdentifierChain | CELMemberNegatedIdentifier;
|
|
85
|
+
right: CELIdentifier;
|
|
86
|
+
list: never;
|
|
87
|
+
}
|
|
88
|
+
interface CELDynamicPropertyAccessor extends CELExpression {
|
|
89
|
+
type: "DynamicPropertyAccessor";
|
|
90
|
+
left: CELMember;
|
|
91
|
+
right: CELExpression;
|
|
92
|
+
}
|
|
93
|
+
interface CELProperty extends CELExpression {
|
|
94
|
+
type: "Property";
|
|
95
|
+
value: CELIdentifier;
|
|
96
|
+
args?: CELExpressionList;
|
|
97
|
+
trailingComma?: boolean;
|
|
98
|
+
}
|
|
99
|
+
interface CELFunctionCall extends CELExpression {
|
|
100
|
+
type: "FunctionCall";
|
|
101
|
+
name: CELIdentifier;
|
|
102
|
+
args: CELExpressionList;
|
|
103
|
+
trailingComma?: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface CELExpressionGroup extends CELExpression {
|
|
106
|
+
type: "ExpressionGroup";
|
|
107
|
+
value: CELExpression;
|
|
108
|
+
}
|
|
109
|
+
interface CELList extends CELExpression {
|
|
110
|
+
type: "List";
|
|
111
|
+
value: CELExpressionList;
|
|
112
|
+
trailingComma?: boolean;
|
|
113
|
+
}
|
|
114
|
+
interface CELMap extends CELExpression {
|
|
115
|
+
type: "Map";
|
|
116
|
+
value: CELMapInits;
|
|
117
|
+
trailingComma?: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface CELAddition extends CELExpression {
|
|
120
|
+
type: "Addition";
|
|
121
|
+
left: CELExpression;
|
|
122
|
+
right: CELExpression;
|
|
123
|
+
}
|
|
124
|
+
interface CELSubtraction extends CELExpression {
|
|
125
|
+
type: "Subtraction";
|
|
126
|
+
left: CELExpression;
|
|
127
|
+
right: CELExpression;
|
|
128
|
+
}
|
|
129
|
+
interface CELMultiplication extends CELExpression {
|
|
130
|
+
type: "Multiplication";
|
|
131
|
+
left: CELExpression;
|
|
132
|
+
right: CELExpression;
|
|
133
|
+
}
|
|
134
|
+
interface CELDivision extends CELExpression {
|
|
135
|
+
type: "Division";
|
|
136
|
+
left: CELExpression;
|
|
137
|
+
right: CELExpression;
|
|
138
|
+
}
|
|
139
|
+
interface CELModulo extends CELExpression {
|
|
140
|
+
type: "Modulo";
|
|
141
|
+
left: CELExpression;
|
|
142
|
+
right: CELExpression;
|
|
143
|
+
}
|
|
144
|
+
interface CELConditionalOr extends CELExpression {
|
|
145
|
+
type: "ConditionalOr";
|
|
146
|
+
left: CELExpression;
|
|
147
|
+
right: CELExpression;
|
|
148
|
+
}
|
|
149
|
+
interface CELConditionalAnd extends CELExpression {
|
|
150
|
+
type: "ConditionalAnd";
|
|
151
|
+
left: CELExpression;
|
|
152
|
+
right: CELExpression;
|
|
153
|
+
}
|
|
154
|
+
interface CELExpressionList extends CELExpression {
|
|
155
|
+
type: "ExpressionList";
|
|
156
|
+
value: CELExpression[];
|
|
157
|
+
}
|
|
158
|
+
interface CELFieldsObject extends CELExpression {
|
|
159
|
+
type: "FieldsObject";
|
|
160
|
+
left: CELMember;
|
|
161
|
+
list: CELFieldInits;
|
|
162
|
+
trailingComma?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface CELFieldInits extends CELExpression {
|
|
165
|
+
type: "FieldInits";
|
|
166
|
+
value: CELFieldInit[];
|
|
167
|
+
}
|
|
168
|
+
interface CELFieldInit extends CELExpression {
|
|
169
|
+
type: "FieldInit";
|
|
170
|
+
left: CELIdentifier;
|
|
171
|
+
right: CELExpression;
|
|
172
|
+
}
|
|
173
|
+
interface CELMapInits extends CELExpression {
|
|
174
|
+
type: "MapInits";
|
|
175
|
+
value: CELMapInit[];
|
|
176
|
+
}
|
|
177
|
+
interface CELMapInit extends CELExpression {
|
|
178
|
+
type: "MapInit";
|
|
179
|
+
left: CELExpression;
|
|
180
|
+
right: CELExpression;
|
|
181
|
+
}
|
|
182
|
+
interface CELLikeExpression extends CELExpression {
|
|
183
|
+
type: "LikeExpression";
|
|
184
|
+
left: CELIdentifier | CELMemberIdentifierChain;
|
|
185
|
+
right: CELIdentifier<"contains" | "startsWith" | "endsWith">;
|
|
186
|
+
list: CELExpressionList & {
|
|
187
|
+
value: [CELStringLiteral | CELIdentifier];
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
interface CELNegatedLikeExpression extends CELExpression {
|
|
191
|
+
type: "LikeExpression";
|
|
192
|
+
left: CELMemberNegatedIdentifier | CELMemberNegatedIdentifierChain;
|
|
193
|
+
right: CELIdentifier<"contains" | "startsWith" | "endsWith">;
|
|
194
|
+
list: CELExpressionList & {
|
|
195
|
+
value: [CELStringLiteral | CELIdentifier];
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
type CELNumericLiteral = CELIntegerLiteral | CELUnsignedIntegerLiteral | CELFloatLiteral;
|
|
199
|
+
type CELLiteral = CELStringLiteral | CELBytesLiteral | CELNumericLiteral | CELBooleanLiteral | CELNullLiteral;
|
|
200
|
+
type CELPrimary = CELProperty | CELIdentifier | CELExpressionGroup | CELFunctionCall | CELLiteral | CELList | CELMap;
|
|
201
|
+
type CELMathOperation = CELAddition | CELSubtraction | CELMultiplication | CELDivision | CELModulo;
|
|
202
|
+
interface ParsedCEL {
|
|
203
|
+
nodeType: "Main";
|
|
204
|
+
value: CELExpression;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
4
207
|
//#region src/utils/parseCEL/parseCEL.d.ts
|
|
5
|
-
|
|
208
|
+
interface ParseCELOptionsStandard extends Except<ParserCommonOptions, "independentCombinators"> {
|
|
209
|
+
independentCombinators?: false;
|
|
210
|
+
/**
|
|
211
|
+
* Handler for custom CEL expressions.
|
|
212
|
+
*/
|
|
213
|
+
customExpressionHandler?: (expr: CELExpression) => RuleType | RuleGroupType | null;
|
|
214
|
+
}
|
|
215
|
+
interface ParseCELOptionsIC extends Except<ParserCommonOptions, "independentCombinators"> {
|
|
216
|
+
independentCombinators: true;
|
|
217
|
+
/**
|
|
218
|
+
* Handler for custom CEL expressions.
|
|
219
|
+
*/
|
|
220
|
+
customExpressionHandler?: (expr: CELExpression) => RuleType | RuleGroupTypeIC | null;
|
|
221
|
+
}
|
|
6
222
|
/**
|
|
7
223
|
* Options object for {@link parseCEL}.
|
|
8
224
|
*/
|
|
9
|
-
|
|
225
|
+
type ParseCELOptions = ParseCELOptionsStandard | ParseCELOptionsIC;
|
|
10
226
|
/**
|
|
11
227
|
* Converts a CEL string expression into a query suitable for the
|
|
12
228
|
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
|
|
@@ -16,19 +232,84 @@ declare function parseCEL(cel: string): DefaultRuleGroupType;
|
|
|
16
232
|
/**
|
|
17
233
|
* Converts a CEL string expression into a query suitable for the
|
|
18
234
|
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
|
|
235
|
+
* ({@link index!RuleGroupType RuleGroupType}).
|
|
236
|
+
*/
|
|
237
|
+
declare function parseCEL(cel: string, options: ParseCELOptionsStandard & {
|
|
238
|
+
customExpressionHandler: (expr: CELExpression) => RuleType | RuleGroupType | null;
|
|
239
|
+
}): RuleGroupType;
|
|
240
|
+
/**
|
|
241
|
+
* Converts a CEL string expression into a query suitable for the
|
|
242
|
+
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
|
|
243
|
+
* ({@link index!RuleGroupTypeIC RuleGroupTypeIC}).
|
|
244
|
+
*/
|
|
245
|
+
declare function parseCEL(cel: string, options: ParseCELOptionsIC & {
|
|
246
|
+
customExpressionHandler: (expr: CELExpression) => RuleType | RuleGroupTypeIC | null;
|
|
247
|
+
}): RuleGroupTypeIC;
|
|
248
|
+
/**
|
|
249
|
+
* Converts a CEL string expression into a query suitable for the
|
|
250
|
+
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
|
|
19
251
|
* ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).
|
|
20
252
|
*/
|
|
21
|
-
declare function parseCEL(cel: string, options:
|
|
22
|
-
independentCombinators?: false;
|
|
23
|
-
}): DefaultRuleGroupType;
|
|
253
|
+
declare function parseCEL(cel: string, options?: ParseCELOptionsStandard): DefaultRuleGroupType;
|
|
24
254
|
/**
|
|
25
255
|
* Converts a CEL string expression into a query suitable for the
|
|
26
256
|
* {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
|
|
27
257
|
* ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).
|
|
28
258
|
*/
|
|
29
|
-
declare function parseCEL(cel: string, options:
|
|
30
|
-
|
|
31
|
-
|
|
259
|
+
declare function parseCEL(cel: string, options: ParseCELOptionsIC): DefaultRuleGroupTypeIC;
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/utils/parseCEL/utils.d.ts
|
|
262
|
+
declare const isCELExpressionGroup: (expr: CELExpression) => expr is CELExpressionGroup;
|
|
263
|
+
declare const isCELConditionalAnd: (expr: CELExpression) => expr is CELConditionalAnd;
|
|
264
|
+
declare const isCELConditionalOr: (expr: CELExpression) => expr is CELConditionalOr;
|
|
265
|
+
declare const isCELStringLiteral: (expr: CELExpression) => expr is CELStringLiteral;
|
|
266
|
+
declare const isCELLiteral: (expr: CELExpression) => expr is CELLiteral;
|
|
267
|
+
declare const isCELNumericLiteral: (expr: CELExpression) => expr is CELNumericLiteral;
|
|
268
|
+
declare const isCELRelation: (expr: CELExpression) => expr is CELRelation;
|
|
269
|
+
declare const isCELList: (expr: CELExpression) => expr is CELList;
|
|
270
|
+
declare const isCELMap: (expr: CELExpression) => expr is CELMap;
|
|
271
|
+
declare const isCELIdentifier: (expr: CELExpression) => expr is CELIdentifier;
|
|
272
|
+
declare const isCELNegation: (expr: CELExpression) => expr is CELNegation;
|
|
273
|
+
declare const isCELMember: (expr: CELExpression) => expr is CELMember;
|
|
274
|
+
declare const isCELAddition: (expr: CELExpression) => expr is CELAddition;
|
|
275
|
+
declare const isCELBooleanLiteral: (expr: CELExpression) => expr is CELBooleanLiteral;
|
|
276
|
+
declare const isCELBytesLiteral: (expr: CELExpression) => expr is CELBytesLiteral;
|
|
277
|
+
declare const isCELConditionalExpr: (expr: CELExpression) => expr is CELConditionalExpr;
|
|
278
|
+
declare const isCELDivision: (expr: CELExpression) => expr is CELDivision;
|
|
279
|
+
declare const isCELDynamicPropertyAccessor: (expr: CELExpression) => expr is CELDynamicPropertyAccessor;
|
|
280
|
+
declare const isCELExpressionList: (expr: CELExpression) => expr is CELExpressionList;
|
|
281
|
+
declare const isCELFieldInit: (expr: CELExpression) => expr is CELFieldInit;
|
|
282
|
+
declare const isCELFieldInits: (expr: CELExpression) => expr is CELFieldInits;
|
|
283
|
+
declare const isCELFieldsObject: (expr: CELExpression) => expr is CELFieldsObject;
|
|
284
|
+
declare const isCELFloatLiteral: (expr: CELExpression) => expr is CELFloatLiteral;
|
|
285
|
+
declare const isCELFunctionCall: (expr: CELExpression) => expr is CELFunctionCall;
|
|
286
|
+
declare const isCELIntegerLiteral: (expr: CELExpression) => expr is CELIntegerLiteral;
|
|
287
|
+
declare const isCELMapInit: (expr: CELExpression) => expr is CELMapInit;
|
|
288
|
+
declare const isCELMapInits: (expr: CELExpression) => expr is CELMapInits;
|
|
289
|
+
declare const isCELModulo: (expr: CELExpression) => expr is CELModulo;
|
|
290
|
+
declare const isCELMultiplication: (expr: CELExpression) => expr is CELMultiplication;
|
|
291
|
+
declare const isCELNegative: (expr: CELExpression) => expr is CELNegative;
|
|
292
|
+
declare const isCELNullLiteral: (expr: CELExpression) => expr is CELNullLiteral;
|
|
293
|
+
declare const isCELProperty: (expr: CELExpression) => expr is CELProperty;
|
|
294
|
+
declare const isCELSubtraction: (expr: CELExpression) => expr is CELSubtraction;
|
|
295
|
+
declare const isCELUnsignedIntegerLiteral: (expr: CELExpression) => expr is CELUnsignedIntegerLiteral;
|
|
296
|
+
declare const isCELIdentifierOrChain: (expr: CELExpression) => expr is CELMemberIdentifierChain | CELIdentifier;
|
|
297
|
+
declare const isCELNegatedIdentifier: (expr: CELExpression) => expr is CELMemberNegatedIdentifier;
|
|
298
|
+
declare const isCELNegatedIdentifierOrChain: (expr: CELExpression) => expr is CELMemberNegatedIdentifierChain | CELMemberNegatedIdentifier;
|
|
299
|
+
declare const isCELLikeExpression: (expr: CELExpression) => expr is CELLikeExpression;
|
|
300
|
+
declare const isCELNegatedLikeExpression: (expr: CELExpression) => expr is CELNegatedLikeExpression;
|
|
301
|
+
declare const getCELIdentifierFromChain: (expr: CELIdentifier | CELMemberIdentifierChain) => string;
|
|
302
|
+
declare const getCELIdentifierFromNegatedChain: (expr: CELMemberNegatedIdentifier | CELMemberNegatedIdentifierChain) => string;
|
|
303
|
+
declare function evalCELLiteralValue(literal: CELStringLiteral): string;
|
|
304
|
+
declare function evalCELLiteralValue(literal: CELBooleanLiteral): boolean;
|
|
305
|
+
declare function evalCELLiteralValue(literal: CELNumericLiteral): number | null;
|
|
306
|
+
declare function evalCELLiteralValue(literal: CELBytesLiteral): null;
|
|
307
|
+
declare function evalCELLiteralValue(literal: CELNullLiteral): null;
|
|
308
|
+
declare function evalCELLiteralValue(literal: CELLiteral): string | boolean | number | null;
|
|
309
|
+
declare const celNormalizeCombinator: (c: "&&" | "||") => DefaultCombinatorName;
|
|
310
|
+
declare const celNormalizeOperator: (op: CELRelop, flip?: boolean) => DefaultOperatorName;
|
|
311
|
+
declare const celGenerateFlatAndOrList: (expr: CELConditionalAnd | CELConditionalOr) => (DefaultCombinatorName | CELExpression)[];
|
|
312
|
+
declare const celGenerateMixedAndOrList: (expr: CELConditionalAnd | CELConditionalOr) => (DefaultCombinatorName | CELExpression | ("and" | CELExpression)[])[];
|
|
32
313
|
//#endregion
|
|
33
|
-
export { ParseCELOptions, parseCEL };
|
|
314
|
+
export { CELAddition, CELBooleanLiteral, CELBytesLiteral, CELConditionalAnd, CELConditionalExpr, CELConditionalOr, CELDivision, CELDynamicPropertyAccessor, CELExpression, CELExpressionGroup, CELExpressionList, CELExpressionType, CELFieldInit, CELFieldInits, CELFieldsObject, CELFloatLiteral, CELFunctionCall, CELIdentifier, CELIntegerLiteral, CELLikeExpression, CELList, CELLiteral, CELMap, CELMapInit, CELMapInits, CELMathOperation, CELMember, CELMemberIdentifierChain, CELMemberNegatedIdentifier, CELMemberNegatedIdentifierChain, CELModulo, CELMultiplication, CELNegatedLikeExpression, CELNegation, CELNegative, CELNullLiteral, CELNumericLiteral, CELPrimary, CELProperty, CELRelation, CELRelop, CELStringLiteral, CELSubtraction, CELUnsignedIntegerLiteral, ParseCELOptions, ParseCELOptionsIC, ParseCELOptionsStandard, ParsedCEL, celGenerateFlatAndOrList, celGenerateMixedAndOrList, celNormalizeCombinator, celNormalizeOperator, evalCELLiteralValue, getCELIdentifierFromChain, getCELIdentifierFromNegatedChain, isCELAddition, isCELBooleanLiteral, isCELBytesLiteral, isCELConditionalAnd, isCELConditionalExpr, isCELConditionalOr, isCELDivision, isCELDynamicPropertyAccessor, isCELExpressionGroup, isCELExpressionList, isCELFieldInit, isCELFieldInits, isCELFieldsObject, isCELFloatLiteral, isCELFunctionCall, isCELIdentifier, isCELIdentifierOrChain, isCELIntegerLiteral, isCELLikeExpression, isCELList, isCELLiteral, isCELMap, isCELMapInit, isCELMapInits, isCELMember, isCELModulo, isCELMultiplication, isCELNegatedIdentifier, isCELNegatedIdentifierOrChain, isCELNegatedLikeExpression, isCELNegation, isCELNegative, isCELNullLiteral, isCELNumericLiteral, isCELProperty, isCELRelation, isCELStringLiteral, isCELSubtraction, isCELUnsignedIntegerLiteral, parseCEL };
|
|
34
315
|
//# sourceMappingURL=parseCEL.d.mts.map
|