(
code: string,
options?: ExecutionOptions,
caller?: AbortSignal
)
| 93 | } |
| 94 | |
| 95 | async execute<T = Record<string, unknown>>( |
| 96 | code: string, |
| 97 | options?: ExecutionOptions, |
| 98 | caller?: AbortSignal |
| 99 | ): Promise<ExecutionResult<T>> { |
| 100 | const source = this.source; |
| 101 | if (!source) throw new Error('No data loaded. Please call source() first.'); |
| 102 | |
| 103 | const signal = this.operationSignal(caller); |
| 104 | throwIfAborted(signal); |
| 105 | const validated = await this.dialect.validateDSL(code, signal); |
| 106 | const limits = { |
| 107 | maxRows: z.number().int().positive().parse(maxRows(options)), |
| 108 | maxResultBytes: maxResultBytes(options), |
| 109 | }; |
| 110 | |
| 111 | const maxBuffer = limits.maxResultBytes + 1024 * 1024; |
| 112 | const response = await this.runScript(executionCode(validated, source, limits), maxBuffer, 'execution', signal); |
| 113 | const result = resultSchema.parse(response); |
| 114 | // Row fields are chosen by the caller's query; the envelope is runtime-validated above. |
| 115 | return executionResult(result.data as T[], result.schema, limits, result.truncatedBy); |
| 116 | } |
| 117 | |
| 118 | private operationSignal(signal?: AbortSignal): AbortSignal { |
| 119 | return signal ? AbortSignal.any([signal, this.lifetime.signal]) : this.lifetime.signal; |
no test coverage detected