1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
3
3
import { API } from 'jsEngine/api/API' ;
4
+ import type { ExecuteFileEngineExecutionParams , ExecuteFileSimpleEngineExecutionParams } from 'jsEngine/api/Internal' ;
4
5
import { AbstractMarkdownElement } from 'jsEngine/api/markdown/AbstractMarkdownElement' ;
5
6
import type { TableElementType } from 'jsEngine/api/markdown/AbstractMarkdownElementContainer' ;
6
7
import type {
@@ -14,7 +15,16 @@ import type {
14
15
YesNoPromptOptions ,
15
16
} from 'jsEngine/api/PromptAPI' ;
16
17
import 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' ;
18
28
import { ExecutionSource } from 'jsEngine/engine/JsExecution' ;
19
29
import { MessageType } from 'jsEngine/messages/MessageManager' ;
20
30
import { ErrorLevel , JSEngineValidationError } from 'jsEngine/utils/Errors' ;
@@ -50,6 +60,11 @@ export class Validators {
50
60
block : z . ZodType < Block , any , any > ;
51
61
tableElementType : z . ZodType < TableElementType , any , any > ;
52
62
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 > ;
53
68
executionContext : z . ZodType < ExecutionContext , any , any > ;
54
69
engineExecutionParams : z . ZodType < EngineExecutionParams , any , any > ;
55
70
engineExecutionParamsFile : z . ZodType < Omit < EngineExecutionParams , 'code' | 'context' > , any , any > ;
@@ -81,23 +96,49 @@ export class Validators {
81
96
) ;
82
97
this . tableElementType = schemaForType < TableElementType > ( ) ( z . union ( [ z . string ( ) , z . number ( ) , z . boolean ( ) , z . null ( ) , z . undefined ( ) ] ) ) ;
83
98
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
+ ) ;
84
134
this . executionContext = schemaForType < ExecutionContext > ( ) (
85
135
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 > ,
101
142
) ;
102
143
this . engineExecutionParams = schemaForType < EngineExecutionParams > ( ) (
103
144
z . object ( {
@@ -108,18 +149,18 @@ export class Validators {
108
149
contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
109
150
} ) ,
110
151
) ;
111
- this . engineExecutionParamsFile = schemaForType < Omit < EngineExecutionParams , 'code' | 'context' > > ( ) (
152
+ this . engineExecutionParamsFile = schemaForType < ExecuteFileEngineExecutionParams > ( ) (
112
153
z . object ( {
113
154
component : this . component ,
114
155
container : this . htmlElement . optional ( ) ,
115
- context : this . executionContext . optional ( ) ,
156
+ context : z . union ( [ this . markdownCallingJSFileExecutionContext , this . jsFileExecutionContext ] ) . optional ( ) ,
116
157
contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
117
158
} ) ,
118
159
) ;
119
- this . engineExecutionParamsFileSimple = schemaForType < Omit < EngineExecutionParams , 'code' | 'component' | 'context' > > ( ) (
160
+ this . engineExecutionParamsFileSimple = schemaForType < ExecuteFileSimpleEngineExecutionParams > ( ) (
120
161
z . object ( {
121
162
container : this . htmlElement . optional ( ) ,
122
- context : this . executionContext . optional ( ) ,
163
+ context : z . union ( [ this . markdownCallingJSFileExecutionContext , this . jsFileExecutionContext ] ) . optional ( ) ,
123
164
contextOverrides : z . record ( z . unknown ( ) ) . optional ( ) ,
124
165
} ) ,
125
166
) ;
0 commit comments