1
+ import { MapStore , ReadableAtom } from "nanostores" ;
2
+
3
+ /**
4
+ * Represents a log entry for a Python execution.
5
+ * @interface
6
+ */
1
7
interface PyLog {
2
- id : string
8
+ /**
9
+ * Unique identifier for the log entry.
10
+ * @type {string }
11
+ */
12
+ id : string ;
13
+
14
+ /**
15
+ * Array of standard output messages.
16
+ * @type {Array<string> }
17
+ */
3
18
stdOut : Array < string > ;
19
+
20
+ /**
21
+ * Array of standard error messages.
22
+ * @type {Array<string> }
23
+ */
4
24
stdErr : Array < string > ;
25
+
26
+ /**
27
+ * Exception message, if any occurred during the execution.
28
+ * @type {string }
29
+ */
5
30
exception : string ;
6
31
}
7
32
33
+ /**
34
+ * Represents a log entry for the installation process of Python packages.
35
+ * @interface
36
+ */
8
37
interface PyInstallLog {
38
+ /**
39
+ * The current stage of the installation process.
40
+ * @type {number }
41
+ */
9
42
stage : number ;
43
+
44
+ /**
45
+ * Message related to the current stage of the installation process.
46
+ * @type {string }
47
+ */
10
48
msg : string ;
11
49
}
12
50
13
- export { PyLog , PyInstallLog }
51
+ /**
52
+ * Interface for a Python runner object.
53
+ * @interface
54
+ */
55
+ interface PyRunner {
56
+ /**
57
+ * Method to load Python packages.
58
+ * @param {Array<string> } [pyoPackages] - Optional array of Python packages to load.
59
+ * @param {Array<string> } [packages] - Optional array of additional packages to load.
60
+ * @param {string } [initCode] - Optional initialization code to run.
61
+ * @param {string } [transformCode] - Optional transformation code to run.
62
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
63
+ */
64
+ load : PyLoadMethod ;
65
+
66
+ /**
67
+ * Method to run a Python script synchronously.
68
+ * @param {string } script - The Python script to run.
69
+ * @param {string } [namespace] - Optional namespace for the script.
70
+ * @param {string } [id] - Optional identifier for the script execution.
71
+ * @param {Record<string, any> } [context] - Optional context for the script execution.
72
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
73
+ */
74
+ run : PyRunMethod ;
75
+
76
+ /**
77
+ * Method to run a Python script asynchronously.
78
+ * @param {string } script - The Python script to run.
79
+ * @param {string } [namespace] - Optional namespace for the script.
80
+ * @param {string } [id] - Optional identifier for the script execution.
81
+ * @param {Record<string, any> } [context] - Optional context for the script execution.
82
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
83
+ */
84
+ runAsync : PyRunAsyncMethod ;
85
+
86
+ /**
87
+ * Method to clear a namespace.
88
+ * @param {string } namespace - The namespace to clear.
89
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
90
+ */
91
+ clear : PyClearMethod ;
92
+
93
+ /**
94
+ * Store for installation logs.
95
+ * @type {MapStore<PyInstallLog> }
96
+ */
97
+ installLog : MapStore < PyInstallLog > ;
98
+
99
+ /**
100
+ * Store for execution logs.
101
+ * @type {MapStore<PyLog> }
102
+ */
103
+ log : MapStore < PyLog > ;
104
+
105
+ /**
106
+ * Atom representing whether the runner is currently executing a script.
107
+ * @type {ReadableAtom<boolean> }
108
+ */
109
+ isExecuting : ReadableAtom < boolean > ;
110
+
111
+ /**
112
+ * Atom representing whether the runner is ready to execute scripts.
113
+ * @type {ReadableAtom<boolean> }
114
+ */
115
+ isReady : ReadableAtom < boolean > ;
116
+ }
117
+
118
+ /**
119
+ * Type for the `load` method of the PyRunner interface.
120
+ * @typedef {function } PyLoadMethod
121
+ * @param {Array<string> } [pyoPackages] - Optional array of Python packages to load.
122
+ * @param {Array<string> } [packages] - Optional array of additional packages to load.
123
+ * @param {string } [initCode] - Optional initialization code to run.
124
+ * @param {string } [transformCode] - Optional transformation code to run.
125
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
126
+ */
127
+ type PyLoadMethod = (
128
+ pyoPackages ?: Array < string > ,
129
+ packages ?: Array < string > ,
130
+ initCode ?: string ,
131
+ transformCode ?: string
132
+ ) => Promise < { results : any , error : any } > ;
133
+
134
+ /**
135
+ * Type for the `run` method of the PyRunner interface.
136
+ * @typedef {function } PyRunMethod
137
+ * @param {string } script - The Python script to run.
138
+ * @param {string } [namespace] - Optional namespace for the script.
139
+ * @param {string } [id] - Optional identifier for the script execution.
140
+ * @param {Record<string, any> } [context] - Optional context for the script execution.
141
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
142
+ */
143
+ type PyRunMethod = (
144
+ script : string ,
145
+ namespace ?: string ,
146
+ id ?: string ,
147
+ context ?: Record < string , any >
148
+ ) => Promise < { results : any , error : any } > ;
149
+
150
+ /**
151
+ * Type for the `runAsync` method of the PyRunner interface.
152
+ * @typedef {function } PyRunAsyncMethod
153
+ * @param {string } script - The Python script to run.
154
+ * @param {string } [namespace] - Optional namespace for the script.
155
+ * @param {string } [id] - Optional identifier for the script execution.
156
+ * @param {Record<string, any> } [context] - Optional context for the script execution.
157
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
158
+ */
159
+ type PyRunAsyncMethod = (
160
+ script : string ,
161
+ namespace ?: string ,
162
+ id ?: string ,
163
+ context ?: Record < string , any >
164
+ ) => Promise < { results : any , error : any } > ;
165
+
166
+ /**
167
+ * Type for the `clear` method of the PyRunner interface.
168
+ * @typedef {function } PyClearMethod
169
+ * @param {string } namespace - The namespace to clear.
170
+ * @returns {Promise<{ results: any, error: any }> } A promise that resolves with the results or rejects with an error.
171
+ */
172
+ type PyClearMethod = ( namespace : string ) => Promise < { results : any , error : any } > ;
173
+
174
+ /**
175
+ * Export the PyRunner interface and related types.
176
+ * @type {PyRunner }
177
+ */
178
+ export {
179
+ PyRunner ,
180
+ PyLog ,
181
+ PyInstallLog ,
182
+ PyRunMethod ,
183
+ PyRunAsyncMethod ,
184
+ PyClearMethod ,
185
+ PyLoadMethod ,
186
+ } ;
0 commit comments