(code: string, options?: ExecutionOptions)
| 88 | } |
| 89 | |
| 90 | async execute<T = Record<string, unknown>>(code: string, options?: ExecutionOptions): Promise<ExecutionResult<T>> { |
| 91 | if (!this.source) throw new Error('No data loaded. Please call source() first.'); |
| 92 | |
| 93 | const validated = await this.dialect.validateDSL(code); |
| 94 | const limits = { |
| 95 | maxRows: z.number().int().positive().parse(maxRows(options)), |
| 96 | maxResultBytes: maxResultBytes(options), |
| 97 | }; |
| 98 | |
| 99 | // Bound client waiting; the executor must terminate remote work on timeout. |
| 100 | const maxBuffer = limits.maxResultBytes + 1024 * 1024; |
| 101 | const response = await runWithTimeout( |
| 102 | this.executor(executionCode(validated, this.source, limits), maxBuffer), |
| 103 | this.timeoutMs, |
| 104 | { |
| 105 | onTimeout: () => new Error(`Python execution timed out after ${this.timeoutMs}ms`), |
| 106 | } |
| 107 | ); |
| 108 | const result = resultSchema.parse(response); |
| 109 | // Row fields are chosen by the caller's query; the envelope is runtime-validated above. |
| 110 | return executionResult(result.data as T[], result.schema, limits, result.truncatedBy); |
| 111 | } |
| 112 | |
| 113 | private async metadata(code: string): Promise<Record<string, unknown>[]> { |
| 114 | const result = await this.execute(code, { maxRows: 10_000 }); |
no test coverage detected