MCPcopy Create free account
hub / github.com/antvis/AVA / validateDSL

Method validateDSL

src/query/python.ts:51–69  ·  view source on GitHub ↗
(code: string, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

49 }
50
51 async validateDSL(code: string, signal?: AbortSignal): Promise<string> {
52 throwIfAborted(signal);
53 if (!code.trim()) throw new Error('Python query must contain code');
54 if (code.includes('\0')) throw new Error('Python query contains a NUL character');
55 // Compile in the execution environment without running the user's code or loading source data.
56 // https://docs.python.org/3/library/functions.html#compile
57 const script = `import json
58compile(json.loads(${JSON.stringify(JSON.stringify(code))}), '<ava-query>', 'exec')
59print('{"data":[],"schema":[],"rowCount":0}')
60`;
61 if (this.execute) {
62 await (signal ? this.execute(script, signal) : this.execute(script));
63 } else {
64 const { createPythonExecutor } = await import('../interpreter/python/util/execute');
65 await createPythonExecutor(30_000)(script, 64 * 1024, signal);
66 }
67 throwIfAborted(signal);
68 return code;
69 }
70}

Callers

nothing calls this directly

Calls 3

throwIfAbortedFunction · 0.90
createPythonExecutorFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected