Skip to content

Commit 8533ca9

Browse files
committed
feat: add type information to evaluation results
1 parent fd90f42 commit 8533ca9

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

packages/sel-runtime/src/environment/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ export class SELRuntime {
457457
const evalResult: EvaluateResult<T> = executionMeta
458458
? { value, meta: executionMeta }
459459
: { value };
460+
461+
// Most likely the type is always available here.
462+
if (typeCheckResult.type) {
463+
evalResult.type = typeCheckResult.type;
464+
}
465+
460466
if (diagnostics.length > 0) {
461467
evalResult.diagnostics = diagnostics;
462468
}

packages/sel-runtime/src/execution/types.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import type { SELDiagnostic } from "@seljs/checker";
66
* Contains statistics and block information from the execution run.
77
*/
88
export interface ExecutionMeta {
9-
/** Number of rounds executed (topological depth) */
9+
/**
10+
* Number of rounds executed (topological depth)
11+
*/
1012
roundsExecuted: number;
1113

12-
/** Total number of contract calls executed */
14+
/**
15+
* Total number of contract calls executed
16+
*/
1317
totalCalls: number;
1418

15-
/** Block number at which calls were executed */
19+
/**
20+
* Block number at which calls were executed
21+
*/
1622
blockNumber: bigint;
1723
}
1824

@@ -21,10 +27,14 @@ export interface ExecutionMeta {
2127
* Maps call IDs to their decoded results.
2228
*/
2329
export interface ExecutionResult {
24-
/** Map of callId to decoded result value */
30+
/**
31+
* Map of callId to decoded result value
32+
*/
2533
results: Map<string, unknown>;
2634

27-
/** Execution metadata */
35+
/**
36+
* Execution metadata
37+
*/
2838
meta: ExecutionMeta;
2939
}
3040

@@ -33,18 +43,24 @@ export interface ExecutionResult {
3343
* Contains the block number and variable bindings.
3444
*/
3545
export interface ExecutionContext {
36-
/** Block number for consistent reads across all calls */
46+
/**
47+
* Block number for consistent reads across all calls
48+
*/
3749
blockNumber: bigint;
3850

39-
/** Variable name to value mapping from evaluate() context */
51+
/**
52+
* Variable name to value mapping from evaluate() context
53+
*/
4054
variables: Record<string, unknown>;
4155
}
4256

4357
/**
4458
* Options for the evaluate() call.
4559
*/
4660
export interface EvaluateOptions {
47-
/** Override client for this evaluation */
61+
/**
62+
* Override client for this evaluation
63+
*/
4864
client?: SELClient;
4965
}
5066

@@ -55,12 +71,23 @@ export interface EvaluateOptions {
5571
* contract calls were executed, absent for pure CEL expressions.
5672
*/
5773
export interface EvaluateResult<T = unknown> {
58-
/** The evaluated result value */
74+
/**
75+
* The evaluated result value
76+
*/
5977
value: T;
6078

61-
/** Execution metadata, present when contract calls were executed */
79+
/**
80+
* The inferred type of the expression, when available
81+
*/
82+
type?: string;
83+
84+
/**
85+
* Execution metadata, present when contract calls were executed
86+
*/
6287
meta?: ExecutionMeta;
6388

64-
/** Advisory diagnostics (warnings/info) from lint rules, when non-empty */
89+
/**
90+
* Advisory diagnostics (warnings/info) from lint rules, when non-empty
91+
*/
6592
diagnostics?: SELDiagnostic[];
6693
}

0 commit comments

Comments
 (0)