11/* eslint-disable @typescript-eslint/no-explicit-any */
22
33import { API } from 'jsEngine/api/API' ;
4+ import type { ExecuteFileEngineExecutionParams , ExecuteFileSimpleEngineExecutionParams } from 'jsEngine/api/Internal' ;
45import { AbstractMarkdownElement } from 'jsEngine/api/markdown/AbstractMarkdownElement' ;
56import type { TableElementType } from 'jsEngine/api/markdown/AbstractMarkdownElementContainer' ;
67import type {
@@ -14,7 +15,16 @@ import type {
1415 YesNoPromptOptions ,
1516} from 'jsEngine/api/PromptAPI' ;
1617import type { EngineExecutionParams } from 'jsEngine/engine/Engine' ;
17- import type { Block , ExecutionContext , JsExecutionGlobalsConstructionOptions } from 'jsEngine/engine/JsExecution' ;
18+ import type {
19+ Block ,
20+ ExecutionContext ,
21+ JsExecutionGlobalsConstructionOptions ,
22+ JSFileExecutionContext ,
23+ MarkdownCallingJSFileExecutionContext ,
24+ MarkdownCodeBlockExecutionContext ,
25+ MarkdownOtherExecutionContext ,
26+ UnknownExecutionContext ,
27+ } from 'jsEngine/engine/JsExecution' ;
1828import { ExecutionSource } from 'jsEngine/engine/JsExecution' ;
1929import { MessageType } from 'jsEngine/messages/MessageManager' ;
2030import { ErrorLevel , JSEngineValidationError } from 'jsEngine/utils/Errors' ;
@@ -50,6 +60,11 @@ export class Validators {
5060 block : z . ZodType < Block , any , any > ;
5161 tableElementType : z . ZodType < TableElementType , any , any > ;
5262 tableElementBody : z . ZodType < TableElementType [ ] [ ] , any , any > ;
63+ markdownCodeBlockExecutionContext : z . ZodType < MarkdownCodeBlockExecutionContext , any , any > ;
64+ markdownCallingJSFileExecutionContext : z . ZodType < MarkdownCallingJSFileExecutionContext , any , any > ;
65+ markdownOtherExecutionContext : z . ZodType < MarkdownOtherExecutionContext , any , any > ;
66+ jsFileExecutionContext : z . ZodType < JSFileExecutionContext , any , any > ;
67+ unknownExecutionContext : z . ZodType < UnknownExecutionContext , any , any > ;
5368 executionContext : z . ZodType < ExecutionContext , any , any > ;
5469 engineExecutionParams : z . ZodType < EngineExecutionParams , any , any > ;
5570 engineExecutionParamsFile : z . ZodType < Omit < EngineExecutionParams , 'code' | 'context' > , any , any > ;
@@ -81,23 +96,49 @@ export class Validators {
8196 ) ;
8297 this . tableElementType = schemaForType < TableElementType > ( ) ( z . union ( [ z . string ( ) , z . number ( ) , z . boolean ( ) , z . null ( ) , z . undefined ( ) ] ) ) ;
8398 this . tableElementBody = schemaForType < TableElementType [ ] [ ] > ( ) ( z . array ( z . array ( this . tableElementType ) ) ) ;
99+ this . markdownCodeBlockExecutionContext = schemaForType < MarkdownCodeBlockExecutionContext > ( ) (
100+ z . object ( {
101+ executionSource : z . literal ( ExecutionSource . MarkdownCodeBlock ) ,
102+ file : this . tFile ,
103+ metadata : this . cachedMetadata . optional ( ) ,
104+ block : this . block . optional ( ) ,
105+ } ) ,
106+ ) ;
107+ this . markdownCallingJSFileExecutionContext = schemaForType < MarkdownCallingJSFileExecutionContext > ( ) (
108+ z . object ( {
109+ executionSource : z . literal ( ExecutionSource . MarkdownCallingJSFile ) ,
110+ file : this . tFile ,
111+ metadata : this . cachedMetadata . optional ( ) ,
112+ jsFile : this . tFile ,
113+ } ) ,
114+ ) ;
115+ this . markdownOtherExecutionContext = schemaForType < MarkdownOtherExecutionContext > ( ) (
116+ z . object ( {
117+ executionSource : z . literal ( ExecutionSource . MarkdownOther ) ,
118+ file : this . tFile ,
119+ metadata : this . cachedMetadata . optional ( ) ,
120+ } ) ,
121+ ) ;
122+ this . jsFileExecutionContext = schemaForType < JSFileExecutionContext > ( ) (
123+ z . object ( {
124+ executionSource : z . literal ( ExecutionSource . JSFile ) ,
125+ jsFile : this . tFile ,
126+ } ) ,
127+ ) ;
128+ this . unknownExecutionContext = schemaForType < UnknownExecutionContext > ( ) (
129+ z . object ( {
130+ executionSource : z . literal ( ExecutionSource . Unknown ) ,
131+ file : this . tFile . optional ( ) ,
132+ } ) ,
133+ ) ;
84134 this . executionContext = schemaForType < ExecutionContext > ( ) (
85135 z . discriminatedUnion ( 'executionSource' , [
86- z . object ( {
87- executionSource : z . literal ( ExecutionSource . MarkdownCodeBlock ) ,
88- file : this . tFile ,
89- metadata : this . cachedMetadata . optional ( ) ,
90- block : this . block . optional ( ) ,
91- } ) ,
92- z . object ( {
93- executionSource : z . literal ( ExecutionSource . JSFile ) ,
94- file : this . tFile ,
95- } ) ,
96- z . object ( {
97- executionSource : z . literal ( ExecutionSource . Unknown ) ,
98- file : this . tFile . optional ( ) ,
99- } ) ,
100- ] ) ,
136+ this . markdownCodeBlockExecutionContext ,
137+ this . markdownCallingJSFileExecutionContext ,
138+ this . markdownOtherExecutionContext ,
139+ this . jsFileExecutionContext ,
140+ this . unknownExecutionContext ,
141+ ] as any ) as z . ZodType < ExecutionContext , any , any > ,
101142 ) ;
102143 this . engineExecutionParams = schemaForType < EngineExecutionParams > ( ) (
103144 z . object ( {
@@ -108,18 +149,18 @@ export class Validators {
108149 contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
109150 } ) ,
110151 ) ;
111- this . engineExecutionParamsFile = schemaForType < Omit < EngineExecutionParams , 'code' | 'context' > > ( ) (
152+ this . engineExecutionParamsFile = schemaForType < ExecuteFileEngineExecutionParams > ( ) (
112153 z . object ( {
113154 component : this . component ,
114155 container : this . htmlElement . optional ( ) ,
115- context : this . executionContext . optional ( ) ,
156+ context : z . union ( [ this . markdownCallingJSFileExecutionContext , this . jsFileExecutionContext ] ) . optional ( ) ,
116157 contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
117158 } ) ,
118159 ) ;
119- this . engineExecutionParamsFileSimple = schemaForType < Omit < EngineExecutionParams , 'code' | 'component' | 'context' > > ( ) (
160+ this . engineExecutionParamsFileSimple = schemaForType < ExecuteFileSimpleEngineExecutionParams > ( ) (
120161 z . object ( {
121162 container : this . htmlElement . optional ( ) ,
122- context : this . executionContext . optional ( ) ,
163+ context : z . union ( [ this . markdownCallingJSFileExecutionContext , this . jsFileExecutionContext ] ) . optional ( ) ,
123164 contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
124165 } ) ,
125166 ) ;
0 commit comments