this repo has no description
1/**
2 * OCaml Worker Client TypeScript Declarations
3 */
4
5export interface InitConfig {
6 /** Findlib packages to require */
7 findlib_requires: string[];
8 /** URL to dynamic CMIs for stdlib */
9 stdlib_dcs?: string;
10 /** URL to findlib_index.json file */
11 findlib_index?: string;
12}
13
14export interface Position {
15 /** Character number */
16 pos_cnum: number;
17 /** Line number */
18 pos_lnum: number;
19 /** Beginning of line offset */
20 pos_bol: number;
21}
22
23export interface Location {
24 /** Start position */
25 loc_start: Position;
26 /** End position */
27 loc_end: Position;
28}
29
30export interface MimeVal {
31 /** MIME type */
32 mime_type: string;
33 /** Data content */
34 data: string;
35}
36
37export interface Output {
38 /** Cell identifier */
39 cell_id: number;
40 /** Standard output */
41 stdout: string;
42 /** Standard error */
43 stderr: string;
44 /** OCaml pretty-printed output */
45 caml_ppf: string;
46 /** MIME values */
47 mime_vals: MimeVal[];
48}
49
50export interface CompletionEntry {
51 /** Completion name */
52 name: string;
53 /** Kind (Value, Module, Type, etc.) */
54 kind: string;
55 /** Description */
56 desc: string;
57 /** Additional info */
58 info: string;
59 /** Whether deprecated */
60 deprecated: boolean;
61}
62
63export interface Completions {
64 /** Cell identifier */
65 cell_id: number;
66 /** Completions data */
67 completions: {
68 /** Start position */
69 from: number;
70 /** End position */
71 to: number;
72 /** Completion entries */
73 entries: CompletionEntry[];
74 };
75}
76
77export interface Error {
78 /** Error kind */
79 kind: string;
80 /** Error location */
81 loc: Location;
82 /** Main error message */
83 main: string;
84 /** Sub-messages */
85 sub: string[];
86 /** Error source */
87 source: string;
88}
89
90export interface ErrorList {
91 /** Cell identifier */
92 cell_id: number;
93 /** Errors */
94 errors: Error[];
95}
96
97export interface TypeInfo {
98 /** Type location */
99 loc: Location;
100 /** Type string */
101 type_str: string;
102 /** Tail position info */
103 tail: string;
104}
105
106export interface TypesResult {
107 /** Cell identifier */
108 cell_id: number;
109 /** Type information */
110 types: TypeInfo[];
111}
112
113export interface EnvResult {
114 /** Environment ID */
115 env_id: string;
116}
117
118export interface OutputAt {
119 /** Cell identifier */
120 cell_id: number;
121 /** Character position after phrase (pos_cnum) */
122 loc: number;
123 /** OCaml pretty-printed output for this phrase */
124 caml_ppf: string;
125 /** MIME values for this phrase */
126 mime_vals: MimeVal[];
127}
128
129export interface WidgetUpdateMessage {
130 type: string;
131 widget_id: string;
132 view: any;
133}
134
135export interface WidgetClearMessage {
136 type: string;
137 widget_id: string;
138}
139
140export interface OcamlWorkerOptions {
141 /** Timeout in milliseconds (default: 30000) */
142 timeout?: number;
143 /** Callback for incremental output after each phrase */
144 onOutputAt?: (output: OutputAt) => void;
145 /** Callback for widget view updates */
146 onWidgetUpdate?: (msg: WidgetUpdateMessage) => void;
147 /** Callback for widget clear events */
148 onWidgetClear?: (msg: WidgetClearMessage) => void;
149}
150
151export class OcamlWorker {
152 /**
153 * Create a new OCaml worker client.
154 * @param workerUrl - URL to the worker script
155 * @param options - Options
156 */
157 constructor(workerUrl: string, options?: OcamlWorkerOptions);
158
159 /**
160 * Initialize the worker.
161 * @param config - Initialization configuration
162 */
163 init(config: InitConfig): Promise<void>;
164
165 /**
166 * Wait for the worker to be ready.
167 */
168 waitReady(): Promise<void>;
169
170 /**
171 * Evaluate OCaml code.
172 * @param code - OCaml code to evaluate
173 * @param envId - Environment ID (default: 'default')
174 */
175 eval(code: string, envId?: string): Promise<Output>;
176
177 /**
178 * Get completions at a position.
179 * @param source - Source code
180 * @param position - Cursor position (character offset)
181 * @param envId - Environment ID (default: 'default')
182 */
183 complete(source: string, position: number, envId?: string): Promise<Completions>;
184
185 /**
186 * Get type information at a position.
187 * @param source - Source code
188 * @param position - Cursor position (character offset)
189 * @param envId - Environment ID (default: 'default')
190 */
191 typeAt(source: string, position: number, envId?: string): Promise<TypesResult>;
192
193 /**
194 * Get errors for source code.
195 * @param source - Source code
196 * @param envId - Environment ID (default: 'default')
197 */
198 errors(source: string, envId?: string): Promise<ErrorList>;
199
200 /**
201 * Create a new execution environment.
202 * @param envId - Environment ID
203 */
204 createEnv(envId: string): Promise<EnvResult>;
205
206 /**
207 * Destroy an execution environment.
208 * @param envId - Environment ID
209 */
210 destroyEnv(envId: string): Promise<EnvResult>;
211
212 /**
213 * Send a widget event to the worker.
214 * @param widgetId - Widget identifier
215 * @param handlerId - Handler identifier within the widget
216 * @param eventType - DOM event type (e.g., 'input', 'click')
217 * @param value - Input value if applicable
218 */
219 sendWidgetEvent(widgetId: string, handlerId: string, eventType: string, value?: string | null): void;
220
221 /**
222 * Terminate the worker.
223 */
224 terminate(): void;
225}
226
227export default OcamlWorker;