Files
twenty/packages/twenty-shared/src/expr-eval.d.ts
T
Raphaël BosiandGitHub b11f77df2a [FRONT COMPONENTS] Introduce conditionalAvailabilityExpression to command menu items (#18319)
## PR Description

- Uses `expr-eval` to enable front components (SDK plugins) to define
conditional availability as declarative expressions.
- Moves shared types and constants to `twenty-shared`
- Introduces a `conditionalAvailabilityExpression` field on
`CommandMenuItemEntity`, allowing command menu items to store an
`expr-eval` compatible expression string that is evaluated against a
CommandMenuContext to determine if the item should be shown.
- Creates an esbuild transform plugin
`conditional-availability-transform-plugin` in `twenty-sdk` that
converts TypeScript conditional availability expressions into
`expr-eval` compatible syntax at build time, so SDK developers can write
natural TS expressions that get transformed to evaluable strings.
- Removes deprecated `forceRegisteredActionsByKey` state and its usage.
- Creates `useCommandMenuContext` hook that builds the full
`CommandMenuContext` object from React state, which is then passed to
`useCommandMenuItemFrontComponentActions` for evaluating conditional
availability expressions.
2026-03-04 16:33:58 +01:00

96 lines
2.3 KiB
TypeScript

declare module 'expr-eval' {
export type Value =
| number
| string
| boolean
| null
| undefined
| Value[]
| ((...args: Value[]) => Value)
| { [propertyName: string]: Value };
export type EvaluationContext = Record<string, unknown>;
export interface Values {
[propertyName: string]: Value;
}
export interface ParserOptions {
allowMemberAccess?: boolean;
operators?: {
add?: boolean;
comparison?: boolean;
concatenate?: boolean;
conditional?: boolean;
divide?: boolean;
factorial?: boolean;
logical?: boolean;
multiply?: boolean;
power?: boolean;
remainder?: boolean;
subtract?: boolean;
sin?: boolean;
cos?: boolean;
tan?: boolean;
asin?: boolean;
acos?: boolean;
atan?: boolean;
sinh?: boolean;
cosh?: boolean;
tanh?: boolean;
asinh?: boolean;
acosh?: boolean;
atanh?: boolean;
sqrt?: boolean;
log?: boolean;
ln?: boolean;
lg?: boolean;
log10?: boolean;
abs?: boolean;
ceil?: boolean;
floor?: boolean;
round?: boolean;
trunc?: boolean;
exp?: boolean;
length?: boolean;
in?: boolean;
random?: boolean;
min?: boolean;
max?: boolean;
assignment?: boolean;
fndef?: boolean;
cbrt?: boolean;
expm1?: boolean;
log1p?: boolean;
sign?: boolean;
log2?: boolean;
};
}
export class Parser {
constructor(options?: ParserOptions);
unaryOps: any;
functions: any;
consts: any;
parse(expression: string): Expression;
evaluate(expression: string, values?: EvaluationContext): number;
static parse(expression: string): Expression;
static evaluate(expression: string, values?: EvaluationContext): number;
}
export interface Expression {
simplify(values?: EvaluationContext): Expression;
evaluate(values?: EvaluationContext): any;
substitute(
variable: string,
value: Expression | string | number,
): Expression;
symbols(options?: { withMembers?: boolean }): string[];
variables(options?: { withMembers?: boolean }): string[];
toJSFunction(
params: string,
values?: EvaluationContext,
): (...args: any[]) => number;
}
}