@constela/core 0.21.4 → 0.22.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/index.d.ts +57 -1
- package/dist/index.js +576 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2469,4 +2469,60 @@ declare const GLOBAL_FUNCTIONS: Record<string, (...args: unknown[]) => unknown>;
|
|
|
2469
2469
|
*/
|
|
2470
2470
|
declare function callGlobalFunction(method: string, args: unknown[]): unknown;
|
|
2471
2471
|
|
|
2472
|
-
|
|
2472
|
+
/**
|
|
2473
|
+
* Types for the unified evaluate module.
|
|
2474
|
+
*
|
|
2475
|
+
* StateReader: abstracts Map.get() and StateStore.get()
|
|
2476
|
+
* EnvironmentAdapter: abstracts SSR/CSR differences
|
|
2477
|
+
* CoreEvaluationContext: the evaluation context consumed by evaluate()
|
|
2478
|
+
*/
|
|
2479
|
+
|
|
2480
|
+
interface StateReader {
|
|
2481
|
+
get(name: string): unknown;
|
|
2482
|
+
}
|
|
2483
|
+
interface EnvironmentAdapter {
|
|
2484
|
+
resolveRef(name: string): unknown;
|
|
2485
|
+
resolveValidity(ref: string, property?: string): unknown;
|
|
2486
|
+
resolveGlobal(name: string): unknown;
|
|
2487
|
+
bindFunction?(value: Function, parent: unknown): unknown;
|
|
2488
|
+
callFunction?(target: Function, args: unknown[]): unknown;
|
|
2489
|
+
}
|
|
2490
|
+
interface CoreEvaluationContext {
|
|
2491
|
+
state: StateReader;
|
|
2492
|
+
locals: Record<string, unknown>;
|
|
2493
|
+
route?: {
|
|
2494
|
+
params: Record<string, string>;
|
|
2495
|
+
query: Record<string, string>;
|
|
2496
|
+
path: string;
|
|
2497
|
+
} | undefined;
|
|
2498
|
+
imports?: Record<string, unknown> | undefined;
|
|
2499
|
+
styles?: Record<string, StylePreset> | undefined;
|
|
2500
|
+
env: EnvironmentAdapter;
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
/**
|
|
2504
|
+
* Unified Expression Evaluator
|
|
2505
|
+
*
|
|
2506
|
+
* Single source of truth for evaluating compiled expressions.
|
|
2507
|
+
* SSR/CSR differences are abstracted via EnvironmentAdapter.
|
|
2508
|
+
*
|
|
2509
|
+
* Based on runtime/evaluator.ts (most complete implementation)
|
|
2510
|
+
* with bug fixes from the unification plan.
|
|
2511
|
+
*/
|
|
2512
|
+
|
|
2513
|
+
declare function evaluate(expr: unknown, ctx: CoreEvaluationContext): unknown;
|
|
2514
|
+
declare function evaluateStyle(expr: unknown, ctx: CoreEvaluationContext): string;
|
|
2515
|
+
|
|
2516
|
+
/**
|
|
2517
|
+
* Constants for the unified evaluate module.
|
|
2518
|
+
*
|
|
2519
|
+
* Extracted from runtime/evaluator.ts, server/renderer.ts, server/streaming.ts
|
|
2520
|
+
*/
|
|
2521
|
+
declare const SAFE_ARRAY_METHODS: Set<string>;
|
|
2522
|
+
declare const SAFE_STRING_METHODS: Set<string>;
|
|
2523
|
+
declare const SAFE_MATH_METHODS: Set<string>;
|
|
2524
|
+
declare const SAFE_DATE_STATIC_METHODS: Set<string>;
|
|
2525
|
+
declare const SAFE_DATE_INSTANCE_METHODS: Set<string>;
|
|
2526
|
+
declare const FORBIDDEN_KEYS: Set<string>;
|
|
2527
|
+
|
|
2528
|
+
export { AI_OUTPUT_TYPES, AI_PROVIDER_TYPES, type ActionDefinition, type ActionStep, type AiDataSource, type AiOutputType, type AiProviderType, type ArrayExpr, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BindStep, type BooleanField, CLIPBOARD_OPERATIONS, COLOR_SCHEMES, type CalendarDay, type CallExpr, type CallStep, type ClearTimerStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ColorScheme, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type ConcatExpr, type CondExpr, type ConfirmStep, type ConstelaAst, ConstelaError, type ConstelaProgram, type CookieInitialExpr, type CoreEvaluationContext, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DelayStep, type DisposeStep, type DomStep, type EachNode, type ElementNode, type EnvironmentAdapter, type ErrorBoundaryNode, type ErrorCode, type ErrorOptions, type EventHandler, type EventHandlerOptions, type Expression, FOCUS_OPERATIONS, FORBIDDEN_KEYS, type FetchStep, type FlushStrategy, type FocusOperation, type FocusStep, GLOBAL_FUNCTIONS, type GenerateStep, type GetExpr, HTTP_METHODS, type HttpMethod, ISLAND_STRATEGIES, type IfNode, type IfStep, type ImportExpr, type ImportStep, type IndexExpr, type IntervalStep, type IslandNode, type IslandStrategy, type IslandStrategyOptions, type LambdaExpr, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type LocalActionDefinition, type LocalActionStep, type LocalExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjExpr, type ObjectField, type OptimisticStep, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type PortalNode, type Program, type ReconnectConfig, type RefExpr, type RejectStep, type RouteDefinition, type RouteExpr, SAFE_ARRAY_METHODS, SAFE_DATE_INSTANCE_METHODS, SAFE_DATE_STATIC_METHODS, SAFE_MATH_METHODS, SAFE_STRING_METHODS, type SSECloseStep, type SSEConnectStep, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StateReader, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StreamChunk, type StreamChunkType, type StreamingRenderOptions, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type SuspenseBoundary, type SuspenseNode, type TextNode, type ThemeColors, type ThemeConfig, type ThemeFonts, UPDATE_OPERATIONS, type UnbindStep, type UpdateOperation, type UpdateStep, VALIDITY_PROPERTIES, type ValidationFailure, type ValidationResult, type ValidationSuccess, type ValidityExpr, type ValidityProperty, type VarExpr, type ViewNode, astSchema, callGlobalFunction, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateIslandIdError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createLocalActionInvalidStepError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedLocalStateError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, evaluate, evaluateStyle, findSimilarNames, isActionStep, isAiDataSource, isArrayExpr, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isColorScheme, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isCookieInitialExpr, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isErrorBoundaryNode, isEventHandler, isExpression, isFetchStep, isFocusStep, isGenerateStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isIslandNode, isIslandStrategy, isIslandStrategyOptions, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isPortalNode, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStreamChunk, isStreamingRenderOptions, isStringField, isStyleExpr, isSubscribeStep, isSuspenseBoundary, isSuspenseNode, isTextNode, isThemeColors, isThemeConfig, isThemeFonts, isUpdateStep, isValidityExpr, isVarExpr, isViewNode, validateAst };
|
package/dist/index.js
CHANGED
|
@@ -3680,6 +3680,574 @@ function callGlobalFunction(method, args) {
|
|
|
3680
3680
|
}
|
|
3681
3681
|
return fn(...args);
|
|
3682
3682
|
}
|
|
3683
|
+
|
|
3684
|
+
// src/evaluate/constants.ts
|
|
3685
|
+
var SAFE_ARRAY_METHODS = /* @__PURE__ */ new Set([
|
|
3686
|
+
"length",
|
|
3687
|
+
"at",
|
|
3688
|
+
"includes",
|
|
3689
|
+
"slice",
|
|
3690
|
+
"indexOf",
|
|
3691
|
+
"join",
|
|
3692
|
+
"filter",
|
|
3693
|
+
"map",
|
|
3694
|
+
"find",
|
|
3695
|
+
"findIndex",
|
|
3696
|
+
"some",
|
|
3697
|
+
"every"
|
|
3698
|
+
]);
|
|
3699
|
+
var SAFE_STRING_METHODS = /* @__PURE__ */ new Set([
|
|
3700
|
+
"length",
|
|
3701
|
+
"charAt",
|
|
3702
|
+
"substring",
|
|
3703
|
+
"slice",
|
|
3704
|
+
"split",
|
|
3705
|
+
"trim",
|
|
3706
|
+
"toUpperCase",
|
|
3707
|
+
"toLowerCase",
|
|
3708
|
+
"replace",
|
|
3709
|
+
"includes",
|
|
3710
|
+
"startsWith",
|
|
3711
|
+
"endsWith",
|
|
3712
|
+
"indexOf"
|
|
3713
|
+
]);
|
|
3714
|
+
var SAFE_MATH_METHODS = /* @__PURE__ */ new Set([
|
|
3715
|
+
"min",
|
|
3716
|
+
"max",
|
|
3717
|
+
"round",
|
|
3718
|
+
"floor",
|
|
3719
|
+
"ceil",
|
|
3720
|
+
"abs",
|
|
3721
|
+
"sqrt",
|
|
3722
|
+
"pow",
|
|
3723
|
+
"random",
|
|
3724
|
+
"sin",
|
|
3725
|
+
"cos",
|
|
3726
|
+
"tan"
|
|
3727
|
+
]);
|
|
3728
|
+
var SAFE_DATE_STATIC_METHODS = /* @__PURE__ */ new Set([
|
|
3729
|
+
"now",
|
|
3730
|
+
"parse"
|
|
3731
|
+
]);
|
|
3732
|
+
var SAFE_DATE_INSTANCE_METHODS = /* @__PURE__ */ new Set([
|
|
3733
|
+
"toISOString",
|
|
3734
|
+
"toDateString",
|
|
3735
|
+
"toTimeString",
|
|
3736
|
+
"getTime",
|
|
3737
|
+
"getFullYear",
|
|
3738
|
+
"getMonth",
|
|
3739
|
+
"getDate",
|
|
3740
|
+
"getHours",
|
|
3741
|
+
"getMinutes",
|
|
3742
|
+
"getSeconds",
|
|
3743
|
+
"getMilliseconds"
|
|
3744
|
+
]);
|
|
3745
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set([
|
|
3746
|
+
"__proto__",
|
|
3747
|
+
"constructor",
|
|
3748
|
+
"prototype"
|
|
3749
|
+
]);
|
|
3750
|
+
|
|
3751
|
+
// src/evaluate/evaluate.ts
|
|
3752
|
+
function evaluate(expr, ctx) {
|
|
3753
|
+
const e = expr;
|
|
3754
|
+
switch (e.expr) {
|
|
3755
|
+
case "lit":
|
|
3756
|
+
return e.value;
|
|
3757
|
+
case "state": {
|
|
3758
|
+
const stateValue = ctx.state.get(e.name);
|
|
3759
|
+
if (e.path && stateValue != null) {
|
|
3760
|
+
return getNestedValue(stateValue, e.path);
|
|
3761
|
+
}
|
|
3762
|
+
return stateValue;
|
|
3763
|
+
}
|
|
3764
|
+
case "local":
|
|
3765
|
+
return ctx.locals[e.name];
|
|
3766
|
+
case "var": {
|
|
3767
|
+
let varName = e.name;
|
|
3768
|
+
let pathParts = [];
|
|
3769
|
+
if (varName.includes(".")) {
|
|
3770
|
+
const parts = varName.split(".");
|
|
3771
|
+
varName = parts[0];
|
|
3772
|
+
pathParts = parts.slice(1);
|
|
3773
|
+
}
|
|
3774
|
+
if (e.path) {
|
|
3775
|
+
pathParts = pathParts.concat(e.path.split("."));
|
|
3776
|
+
}
|
|
3777
|
+
for (const part of pathParts) {
|
|
3778
|
+
if (FORBIDDEN_KEYS.has(part)) {
|
|
3779
|
+
return void 0;
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
let value = ctx.locals[varName];
|
|
3783
|
+
if (value === void 0) {
|
|
3784
|
+
value = ctx.env.resolveGlobal(varName);
|
|
3785
|
+
}
|
|
3786
|
+
for (const part of pathParts) {
|
|
3787
|
+
if (value == null) break;
|
|
3788
|
+
value = value[part];
|
|
3789
|
+
}
|
|
3790
|
+
if (typeof value === "function" && pathParts.length > 0) {
|
|
3791
|
+
let parent = ctx.locals[varName];
|
|
3792
|
+
if (parent === void 0) {
|
|
3793
|
+
parent = ctx.env.resolveGlobal(varName);
|
|
3794
|
+
}
|
|
3795
|
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
3796
|
+
if (parent == null) break;
|
|
3797
|
+
parent = parent[pathParts[i]];
|
|
3798
|
+
}
|
|
3799
|
+
if (parent != null) {
|
|
3800
|
+
if (ctx.env.bindFunction) {
|
|
3801
|
+
return ctx.env.bindFunction(value, parent);
|
|
3802
|
+
}
|
|
3803
|
+
return value;
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
return value;
|
|
3807
|
+
}
|
|
3808
|
+
case "bin":
|
|
3809
|
+
return evaluateBinary(e.op, e.left, e.right, ctx);
|
|
3810
|
+
case "not":
|
|
3811
|
+
return !evaluate(e.operand, ctx);
|
|
3812
|
+
case "cond":
|
|
3813
|
+
return evaluate(e.if, ctx) ? evaluate(e.then, ctx) : evaluate(e.else, ctx);
|
|
3814
|
+
case "get": {
|
|
3815
|
+
const baseValue = evaluate(e.base, ctx);
|
|
3816
|
+
if (baseValue == null) return void 0;
|
|
3817
|
+
const pathParts = e.path.split(".");
|
|
3818
|
+
let value = baseValue;
|
|
3819
|
+
for (const part of pathParts) {
|
|
3820
|
+
if (FORBIDDEN_KEYS.has(part)) return void 0;
|
|
3821
|
+
if (value == null) return void 0;
|
|
3822
|
+
value = value[part];
|
|
3823
|
+
}
|
|
3824
|
+
return value;
|
|
3825
|
+
}
|
|
3826
|
+
case "route": {
|
|
3827
|
+
const source = e.source ?? "param";
|
|
3828
|
+
const routeCtx = ctx.route;
|
|
3829
|
+
if (!routeCtx) return "";
|
|
3830
|
+
switch (source) {
|
|
3831
|
+
case "param":
|
|
3832
|
+
return routeCtx.params[e.name] ?? "";
|
|
3833
|
+
case "query":
|
|
3834
|
+
return routeCtx.query[e.name] ?? "";
|
|
3835
|
+
case "path":
|
|
3836
|
+
return routeCtx.path;
|
|
3837
|
+
default:
|
|
3838
|
+
return "";
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
case "import": {
|
|
3842
|
+
const importData = ctx.imports?.[e.name];
|
|
3843
|
+
if (importData === void 0) return void 0;
|
|
3844
|
+
if (e.path) {
|
|
3845
|
+
return getNestedValue(importData, e.path);
|
|
3846
|
+
}
|
|
3847
|
+
return importData;
|
|
3848
|
+
}
|
|
3849
|
+
case "data": {
|
|
3850
|
+
const dataValue = ctx.imports?.[e.name];
|
|
3851
|
+
if (dataValue === void 0) return void 0;
|
|
3852
|
+
if (e.path) {
|
|
3853
|
+
return getNestedValue(dataValue, e.path);
|
|
3854
|
+
}
|
|
3855
|
+
return dataValue;
|
|
3856
|
+
}
|
|
3857
|
+
case "ref":
|
|
3858
|
+
return ctx.env.resolveRef(e.name);
|
|
3859
|
+
case "index": {
|
|
3860
|
+
const base = evaluate(e.base, ctx);
|
|
3861
|
+
const key = evaluate(e.key, ctx);
|
|
3862
|
+
if (base == null || key == null) return void 0;
|
|
3863
|
+
if (typeof key === "string" && FORBIDDEN_KEYS.has(key)) return void 0;
|
|
3864
|
+
return base[key];
|
|
3865
|
+
}
|
|
3866
|
+
case "param":
|
|
3867
|
+
return void 0;
|
|
3868
|
+
case "style":
|
|
3869
|
+
return evaluateStyle(e, ctx);
|
|
3870
|
+
case "concat": {
|
|
3871
|
+
return e.items.map((item) => {
|
|
3872
|
+
const val = evaluate(item, ctx);
|
|
3873
|
+
return val == null ? "" : String(val);
|
|
3874
|
+
}).join("");
|
|
3875
|
+
}
|
|
3876
|
+
case "validity":
|
|
3877
|
+
return ctx.env.resolveValidity(e.ref, e.property);
|
|
3878
|
+
case "call": {
|
|
3879
|
+
const target = e.target != null ? evaluate(e.target, ctx) : null;
|
|
3880
|
+
const args = e.args?.map((arg) => {
|
|
3881
|
+
if (arg.expr === "lambda") return arg;
|
|
3882
|
+
return evaluate(arg, ctx);
|
|
3883
|
+
}) ?? [];
|
|
3884
|
+
if (target === null) {
|
|
3885
|
+
return callGlobalFunction(e.method, args);
|
|
3886
|
+
}
|
|
3887
|
+
if (Array.isArray(target)) {
|
|
3888
|
+
return callArrayMethod(target, e.method, args, ctx, e.args);
|
|
3889
|
+
}
|
|
3890
|
+
if (typeof target === "string") {
|
|
3891
|
+
return callStringMethod(target, e.method, args);
|
|
3892
|
+
}
|
|
3893
|
+
if (target === Math) {
|
|
3894
|
+
return callMathMethod(e.method, args);
|
|
3895
|
+
}
|
|
3896
|
+
if (target === Date) {
|
|
3897
|
+
return callDateStaticMethod(e.method, args);
|
|
3898
|
+
}
|
|
3899
|
+
if (target instanceof Date) {
|
|
3900
|
+
return callDateInstanceMethod(target, e.method);
|
|
3901
|
+
}
|
|
3902
|
+
if (typeof target === "function" && e.method === "call") {
|
|
3903
|
+
if (ctx.env.callFunction) {
|
|
3904
|
+
return ctx.env.callFunction(target, args);
|
|
3905
|
+
}
|
|
3906
|
+
return target(...args);
|
|
3907
|
+
}
|
|
3908
|
+
return void 0;
|
|
3909
|
+
}
|
|
3910
|
+
case "lambda":
|
|
3911
|
+
return void 0;
|
|
3912
|
+
case "array":
|
|
3913
|
+
return e.elements.map((elem) => evaluate(elem, ctx));
|
|
3914
|
+
case "obj": {
|
|
3915
|
+
const result = {};
|
|
3916
|
+
for (const [key, value] of Object.entries(e.props)) {
|
|
3917
|
+
result[key] = evaluate(value, ctx);
|
|
3918
|
+
}
|
|
3919
|
+
return result;
|
|
3920
|
+
}
|
|
3921
|
+
default:
|
|
3922
|
+
return void 0;
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
function evaluateStyle(expr, ctx) {
|
|
3926
|
+
const e = expr;
|
|
3927
|
+
const preset = ctx.styles?.[e.name];
|
|
3928
|
+
if (!preset) return "";
|
|
3929
|
+
let classes = preset.base;
|
|
3930
|
+
if (preset.variants) {
|
|
3931
|
+
for (const variantKey of Object.keys(preset.variants)) {
|
|
3932
|
+
let variantValueStr = null;
|
|
3933
|
+
if (e.variants?.[variantKey]) {
|
|
3934
|
+
let variantValue;
|
|
3935
|
+
try {
|
|
3936
|
+
variantValue = evaluate(e.variants[variantKey], ctx);
|
|
3937
|
+
} catch {
|
|
3938
|
+
continue;
|
|
3939
|
+
}
|
|
3940
|
+
if (variantValue != null) {
|
|
3941
|
+
variantValueStr = String(variantValue);
|
|
3942
|
+
}
|
|
3943
|
+
} else if (preset.defaultVariants?.[variantKey] !== void 0) {
|
|
3944
|
+
variantValueStr = preset.defaultVariants[variantKey];
|
|
3945
|
+
}
|
|
3946
|
+
if (variantValueStr !== null) {
|
|
3947
|
+
const variantClasses = preset.variants[variantKey]?.[variantValueStr];
|
|
3948
|
+
if (variantClasses) {
|
|
3949
|
+
classes += " " + variantClasses;
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
}
|
|
3954
|
+
return classes.trim();
|
|
3955
|
+
}
|
|
3956
|
+
function getNestedValue(obj, path) {
|
|
3957
|
+
const parts = path.split(".");
|
|
3958
|
+
let value = obj;
|
|
3959
|
+
let parent = null;
|
|
3960
|
+
for (const part of parts) {
|
|
3961
|
+
if (FORBIDDEN_KEYS.has(part)) return void 0;
|
|
3962
|
+
if (value == null) return void 0;
|
|
3963
|
+
parent = value;
|
|
3964
|
+
if (Array.isArray(value)) {
|
|
3965
|
+
const index = Number(part);
|
|
3966
|
+
if (Number.isInteger(index) && index >= 0) {
|
|
3967
|
+
value = value[index];
|
|
3968
|
+
} else {
|
|
3969
|
+
value = value[part];
|
|
3970
|
+
}
|
|
3971
|
+
} else if (typeof value === "object") {
|
|
3972
|
+
value = value[part];
|
|
3973
|
+
} else {
|
|
3974
|
+
return void 0;
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
if (typeof value === "function" && parent != null) {
|
|
3978
|
+
return value.bind(parent);
|
|
3979
|
+
}
|
|
3980
|
+
return value;
|
|
3981
|
+
}
|
|
3982
|
+
function evaluateBinary(op, left, right, ctx) {
|
|
3983
|
+
if (op === "&&") {
|
|
3984
|
+
const leftVal2 = evaluate(left, ctx);
|
|
3985
|
+
if (!leftVal2) return leftVal2;
|
|
3986
|
+
return evaluate(right, ctx);
|
|
3987
|
+
}
|
|
3988
|
+
if (op === "||") {
|
|
3989
|
+
const leftVal2 = evaluate(left, ctx);
|
|
3990
|
+
if (leftVal2) return leftVal2;
|
|
3991
|
+
return evaluate(right, ctx);
|
|
3992
|
+
}
|
|
3993
|
+
const leftVal = evaluate(left, ctx);
|
|
3994
|
+
const rightVal = evaluate(right, ctx);
|
|
3995
|
+
switch (op) {
|
|
3996
|
+
case "+":
|
|
3997
|
+
if (typeof leftVal === "number" && typeof rightVal === "number") {
|
|
3998
|
+
return leftVal + rightVal;
|
|
3999
|
+
}
|
|
4000
|
+
return String(leftVal) + String(rightVal);
|
|
4001
|
+
case "-":
|
|
4002
|
+
return (typeof leftVal === "number" ? leftVal : 0) - (typeof rightVal === "number" ? rightVal : 0);
|
|
4003
|
+
case "*":
|
|
4004
|
+
return (typeof leftVal === "number" ? leftVal : 0) * (typeof rightVal === "number" ? rightVal : 0);
|
|
4005
|
+
case "/": {
|
|
4006
|
+
const dividend = typeof leftVal === "number" ? leftVal : 0;
|
|
4007
|
+
const divisor = typeof rightVal === "number" ? rightVal : 0;
|
|
4008
|
+
if (divisor === 0) {
|
|
4009
|
+
return dividend === 0 ? NaN : dividend > 0 ? Infinity : -Infinity;
|
|
4010
|
+
}
|
|
4011
|
+
return dividend / divisor;
|
|
4012
|
+
}
|
|
4013
|
+
case "%": {
|
|
4014
|
+
const dividend = typeof leftVal === "number" ? leftVal : 0;
|
|
4015
|
+
const divisor = typeof rightVal === "number" ? rightVal : 0;
|
|
4016
|
+
if (divisor === 0) return NaN;
|
|
4017
|
+
return dividend % divisor;
|
|
4018
|
+
}
|
|
4019
|
+
case "==":
|
|
4020
|
+
return leftVal === rightVal;
|
|
4021
|
+
case "!=":
|
|
4022
|
+
return leftVal !== rightVal;
|
|
4023
|
+
case "<":
|
|
4024
|
+
if (typeof leftVal === "number" && typeof rightVal === "number") return leftVal < rightVal;
|
|
4025
|
+
return String(leftVal) < String(rightVal);
|
|
4026
|
+
case "<=":
|
|
4027
|
+
if (typeof leftVal === "number" && typeof rightVal === "number") return leftVal <= rightVal;
|
|
4028
|
+
return String(leftVal) <= String(rightVal);
|
|
4029
|
+
case ">":
|
|
4030
|
+
if (typeof leftVal === "number" && typeof rightVal === "number") return leftVal > rightVal;
|
|
4031
|
+
return String(leftVal) > String(rightVal);
|
|
4032
|
+
case ">=":
|
|
4033
|
+
if (typeof leftVal === "number" && typeof rightVal === "number") return leftVal >= rightVal;
|
|
4034
|
+
return String(leftVal) >= String(rightVal);
|
|
4035
|
+
default:
|
|
4036
|
+
throw new Error("Unknown binary operator: " + op);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
function createLambdaFunction(lambda, ctx) {
|
|
4040
|
+
return (item, index) => {
|
|
4041
|
+
const lambdaLocals = {
|
|
4042
|
+
...ctx.locals,
|
|
4043
|
+
[lambda.param]: item
|
|
4044
|
+
};
|
|
4045
|
+
if (lambda.index !== void 0) {
|
|
4046
|
+
lambdaLocals[lambda.index] = index;
|
|
4047
|
+
}
|
|
4048
|
+
return evaluate(lambda.body, { ...ctx, locals: lambdaLocals });
|
|
4049
|
+
};
|
|
4050
|
+
}
|
|
4051
|
+
function callArrayMethod(target, method, args, ctx, rawArgs) {
|
|
4052
|
+
if (!SAFE_ARRAY_METHODS.has(method)) return void 0;
|
|
4053
|
+
switch (method) {
|
|
4054
|
+
case "length":
|
|
4055
|
+
return target.length;
|
|
4056
|
+
case "at": {
|
|
4057
|
+
const index = typeof args[0] === "number" ? args[0] : 0;
|
|
4058
|
+
return target.at(index);
|
|
4059
|
+
}
|
|
4060
|
+
case "includes": {
|
|
4061
|
+
const searchElement = args[0];
|
|
4062
|
+
const fromIndex = typeof args[1] === "number" ? args[1] : void 0;
|
|
4063
|
+
return target.includes(searchElement, fromIndex);
|
|
4064
|
+
}
|
|
4065
|
+
case "slice": {
|
|
4066
|
+
const start = typeof args[0] === "number" ? args[0] : void 0;
|
|
4067
|
+
const end = typeof args[1] === "number" ? args[1] : void 0;
|
|
4068
|
+
return target.slice(start, end);
|
|
4069
|
+
}
|
|
4070
|
+
case "indexOf": {
|
|
4071
|
+
const searchElement = args[0];
|
|
4072
|
+
const fromIndex = typeof args[1] === "number" ? args[1] : void 0;
|
|
4073
|
+
return target.indexOf(searchElement, fromIndex);
|
|
4074
|
+
}
|
|
4075
|
+
case "join": {
|
|
4076
|
+
const separator = typeof args[0] === "string" ? args[0] : ",";
|
|
4077
|
+
return target.join(separator);
|
|
4078
|
+
}
|
|
4079
|
+
case "filter": {
|
|
4080
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4081
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4082
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4083
|
+
return target.filter((item, index) => !!fn(item, index));
|
|
4084
|
+
}
|
|
4085
|
+
case "map": {
|
|
4086
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4087
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4088
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4089
|
+
return target.map((item, index) => fn(item, index));
|
|
4090
|
+
}
|
|
4091
|
+
case "find": {
|
|
4092
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4093
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4094
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4095
|
+
return target.find((item, index) => !!fn(item, index));
|
|
4096
|
+
}
|
|
4097
|
+
case "findIndex": {
|
|
4098
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4099
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4100
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4101
|
+
return target.findIndex((item, index) => !!fn(item, index));
|
|
4102
|
+
}
|
|
4103
|
+
case "some": {
|
|
4104
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4105
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4106
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4107
|
+
return target.some((item, index) => !!fn(item, index));
|
|
4108
|
+
}
|
|
4109
|
+
case "every": {
|
|
4110
|
+
const lambdaExpr = rawArgs?.[0];
|
|
4111
|
+
if (!lambdaExpr || lambdaExpr.expr !== "lambda") return void 0;
|
|
4112
|
+
const fn = createLambdaFunction(lambdaExpr, ctx);
|
|
4113
|
+
return target.every((item, index) => !!fn(item, index));
|
|
4114
|
+
}
|
|
4115
|
+
default:
|
|
4116
|
+
return void 0;
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
function callStringMethod(target, method, args) {
|
|
4120
|
+
if (!SAFE_STRING_METHODS.has(method)) return void 0;
|
|
4121
|
+
switch (method) {
|
|
4122
|
+
case "length":
|
|
4123
|
+
return target.length;
|
|
4124
|
+
case "charAt": {
|
|
4125
|
+
const index = typeof args[0] === "number" ? args[0] : 0;
|
|
4126
|
+
return target.charAt(index);
|
|
4127
|
+
}
|
|
4128
|
+
case "substring": {
|
|
4129
|
+
const start = typeof args[0] === "number" ? args[0] : 0;
|
|
4130
|
+
const end = typeof args[1] === "number" ? args[1] : void 0;
|
|
4131
|
+
return target.substring(start, end);
|
|
4132
|
+
}
|
|
4133
|
+
case "slice": {
|
|
4134
|
+
const start = typeof args[0] === "number" ? args[0] : void 0;
|
|
4135
|
+
const end = typeof args[1] === "number" ? args[1] : void 0;
|
|
4136
|
+
return target.slice(start, end);
|
|
4137
|
+
}
|
|
4138
|
+
case "split": {
|
|
4139
|
+
const separator = typeof args[0] === "string" ? args[0] : "";
|
|
4140
|
+
return target.split(separator);
|
|
4141
|
+
}
|
|
4142
|
+
case "trim":
|
|
4143
|
+
return target.trim();
|
|
4144
|
+
case "toUpperCase":
|
|
4145
|
+
return target.toUpperCase();
|
|
4146
|
+
case "toLowerCase":
|
|
4147
|
+
return target.toLowerCase();
|
|
4148
|
+
case "replace": {
|
|
4149
|
+
const search = typeof args[0] === "string" ? args[0] : "";
|
|
4150
|
+
const replace = typeof args[1] === "string" ? args[1] : "";
|
|
4151
|
+
return target.replace(search, replace);
|
|
4152
|
+
}
|
|
4153
|
+
case "includes": {
|
|
4154
|
+
const search = typeof args[0] === "string" ? args[0] : "";
|
|
4155
|
+
const position = typeof args[1] === "number" ? args[1] : void 0;
|
|
4156
|
+
return target.includes(search, position);
|
|
4157
|
+
}
|
|
4158
|
+
case "startsWith": {
|
|
4159
|
+
const search = typeof args[0] === "string" ? args[0] : "";
|
|
4160
|
+
const position = typeof args[1] === "number" ? args[1] : void 0;
|
|
4161
|
+
return target.startsWith(search, position);
|
|
4162
|
+
}
|
|
4163
|
+
case "endsWith": {
|
|
4164
|
+
const search = typeof args[0] === "string" ? args[0] : "";
|
|
4165
|
+
const length = typeof args[1] === "number" ? args[1] : void 0;
|
|
4166
|
+
return target.endsWith(search, length);
|
|
4167
|
+
}
|
|
4168
|
+
case "indexOf": {
|
|
4169
|
+
const search = typeof args[0] === "string" ? args[0] : "";
|
|
4170
|
+
const position = typeof args[1] === "number" ? args[1] : void 0;
|
|
4171
|
+
return target.indexOf(search, position);
|
|
4172
|
+
}
|
|
4173
|
+
default:
|
|
4174
|
+
return void 0;
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
function callMathMethod(method, args) {
|
|
4178
|
+
if (!SAFE_MATH_METHODS.has(method)) return void 0;
|
|
4179
|
+
const numbers = args.filter((a) => typeof a === "number");
|
|
4180
|
+
switch (method) {
|
|
4181
|
+
case "min":
|
|
4182
|
+
return numbers.length > 0 ? Math.min(...numbers) : void 0;
|
|
4183
|
+
case "max":
|
|
4184
|
+
return numbers.length > 0 ? Math.max(...numbers) : void 0;
|
|
4185
|
+
case "round":
|
|
4186
|
+
return numbers[0] !== void 0 ? Math.round(numbers[0]) : void 0;
|
|
4187
|
+
case "floor":
|
|
4188
|
+
return numbers[0] !== void 0 ? Math.floor(numbers[0]) : void 0;
|
|
4189
|
+
case "ceil":
|
|
4190
|
+
return numbers[0] !== void 0 ? Math.ceil(numbers[0]) : void 0;
|
|
4191
|
+
case "abs":
|
|
4192
|
+
return numbers[0] !== void 0 ? Math.abs(numbers[0]) : void 0;
|
|
4193
|
+
case "sqrt":
|
|
4194
|
+
return numbers[0] !== void 0 ? Math.sqrt(numbers[0]) : void 0;
|
|
4195
|
+
case "pow":
|
|
4196
|
+
return numbers[0] !== void 0 && numbers[1] !== void 0 ? Math.pow(numbers[0], numbers[1]) : void 0;
|
|
4197
|
+
case "random":
|
|
4198
|
+
return Math.random();
|
|
4199
|
+
case "sin":
|
|
4200
|
+
return numbers[0] !== void 0 ? Math.sin(numbers[0]) : void 0;
|
|
4201
|
+
case "cos":
|
|
4202
|
+
return numbers[0] !== void 0 ? Math.cos(numbers[0]) : void 0;
|
|
4203
|
+
case "tan":
|
|
4204
|
+
return numbers[0] !== void 0 ? Math.tan(numbers[0]) : void 0;
|
|
4205
|
+
default:
|
|
4206
|
+
return void 0;
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
function callDateStaticMethod(method, args) {
|
|
4210
|
+
if (!SAFE_DATE_STATIC_METHODS.has(method)) return void 0;
|
|
4211
|
+
switch (method) {
|
|
4212
|
+
case "now":
|
|
4213
|
+
return Date.now();
|
|
4214
|
+
case "parse": {
|
|
4215
|
+
const dateString = args[0];
|
|
4216
|
+
return typeof dateString === "string" ? Date.parse(dateString) : void 0;
|
|
4217
|
+
}
|
|
4218
|
+
default:
|
|
4219
|
+
return void 0;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
function callDateInstanceMethod(target, method) {
|
|
4223
|
+
if (!SAFE_DATE_INSTANCE_METHODS.has(method)) return void 0;
|
|
4224
|
+
switch (method) {
|
|
4225
|
+
case "toISOString":
|
|
4226
|
+
return target.toISOString();
|
|
4227
|
+
case "toDateString":
|
|
4228
|
+
return target.toDateString();
|
|
4229
|
+
case "toTimeString":
|
|
4230
|
+
return target.toTimeString();
|
|
4231
|
+
case "getTime":
|
|
4232
|
+
return target.getTime();
|
|
4233
|
+
case "getFullYear":
|
|
4234
|
+
return target.getFullYear();
|
|
4235
|
+
case "getMonth":
|
|
4236
|
+
return target.getMonth();
|
|
4237
|
+
case "getDate":
|
|
4238
|
+
return target.getDate();
|
|
4239
|
+
case "getHours":
|
|
4240
|
+
return target.getHours();
|
|
4241
|
+
case "getMinutes":
|
|
4242
|
+
return target.getMinutes();
|
|
4243
|
+
case "getSeconds":
|
|
4244
|
+
return target.getSeconds();
|
|
4245
|
+
case "getMilliseconds":
|
|
4246
|
+
return target.getMilliseconds();
|
|
4247
|
+
default:
|
|
4248
|
+
return void 0;
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
3683
4251
|
export {
|
|
3684
4252
|
AI_OUTPUT_TYPES,
|
|
3685
4253
|
AI_PROVIDER_TYPES,
|
|
@@ -3690,11 +4258,17 @@ export {
|
|
|
3690
4258
|
DATA_SOURCE_TYPES,
|
|
3691
4259
|
DATA_TRANSFORMS,
|
|
3692
4260
|
FOCUS_OPERATIONS,
|
|
4261
|
+
FORBIDDEN_KEYS,
|
|
3693
4262
|
GLOBAL_FUNCTIONS,
|
|
3694
4263
|
HTTP_METHODS,
|
|
3695
4264
|
ISLAND_STRATEGIES,
|
|
3696
4265
|
NAVIGATE_TARGETS,
|
|
3697
4266
|
PARAM_TYPES,
|
|
4267
|
+
SAFE_ARRAY_METHODS,
|
|
4268
|
+
SAFE_DATE_INSTANCE_METHODS,
|
|
4269
|
+
SAFE_DATE_STATIC_METHODS,
|
|
4270
|
+
SAFE_MATH_METHODS,
|
|
4271
|
+
SAFE_STRING_METHODS,
|
|
3698
4272
|
STORAGE_OPERATIONS,
|
|
3699
4273
|
STORAGE_TYPES,
|
|
3700
4274
|
UPDATE_OPERATIONS,
|
|
@@ -3742,6 +4316,8 @@ export {
|
|
|
3742
4316
|
createUndefinedVarError,
|
|
3743
4317
|
createUndefinedVariantError,
|
|
3744
4318
|
createUnsupportedVersionError,
|
|
4319
|
+
evaluate,
|
|
4320
|
+
evaluateStyle,
|
|
3745
4321
|
findSimilarNames,
|
|
3746
4322
|
isActionStep,
|
|
3747
4323
|
isAiDataSource,
|