({ body, metadata, signal })
| 467 | } |
| 468 | return { |
| 469 | async deliver({ body, metadata, signal }) { |
| 470 | /** |
| 471 | * Bind the original line bytes — not `JSON.stringify(JSON.parse(line))` — |
| 472 | * so JSON numbers outside the JS safe-integer range (e.g. Snowflake |
| 473 | * NUMBER columns past 2^53-1) survive into VARIANT intact. We still |
| 474 | * parse each line so a malformed payload fails fast at the runner. |
| 475 | */ |
| 476 | const text = body.toString('utf8') |
| 477 | const rows: string[] = [] |
| 478 | const lines = text.split(/\r?\n/) |
| 479 | for (let i = 0; i < lines.length; i++) { |
| 480 | const line = lines[i] |
| 481 | if (line.length === 0) continue |
| 482 | try { |
| 483 | JSON.parse(line) |
| 484 | } catch (error) { |
| 485 | throw new Error( |
| 486 | `Snowflake NDJSON parse failed at line ${i + 1}: ${toError(error).message}` |
| 487 | ) |
| 488 | } |
| 489 | rows.push(line) |
| 490 | } |
| 491 | if (rows.length === 0) { |
| 492 | return { |
| 493 | locator: `snowflake://${config.account}/${config.database}.${config.schema}.${config.table}#${metadata.runId}-${metadata.sequence}`, |
| 494 | } |
| 495 | } |
| 496 | await executeStatement({ |
| 497 | config, |
| 498 | getJwt, |
| 499 | statement: buildStatement(config, rows.length), |
| 500 | bindings: rows, |
| 501 | signal, |
| 502 | }) |
| 503 | logger.debug('Snowflake chunk delivered', { |
| 504 | account: config.account, |
| 505 | table: `${config.database}.${config.schema}.${config.table}`, |
| 506 | rows: rows.length, |
| 507 | }) |
| 508 | return { |
| 509 | locator: `snowflake://${config.account}/${config.database}.${config.schema}.${config.table}#${metadata.runId}-${metadata.sequence}`, |
| 510 | } |
| 511 | }, |
| 512 | async close() {}, |
| 513 | } |
| 514 | }, |
nothing calls this directly
no test coverage detected