Spaces:
Running
Running
Download source/teaql-ts/src/core/sql-diagnostic-event.ts from teaql/browser-sqlite-playground: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/teaql/browser-sqlite-playground/resolve/main/source/teaql-ts/src/core/sql-diagnostic-event.ts
- Command line
-
hf download hf://spaces/teaql/browser-sqlite-playground/source/teaql-ts/src/core/sql-diagnostic-event.ts
-
curl -L -o sql-diagnostic-event.ts https://huggingface.co/spaces/teaql/browser-sqlite-playground/resolve/main/source/teaql-ts/src/core/sql-diagnostic-event.ts
1.56 kB
| import type { RuntimeDiagnosticEvent, RuntimeExecutionCorrelation } from './telemetry'; | |
| import type { SQLExecutionMetadata } from '../sql/core'; | |
| /** Does not spread metadata, parameters, rows, audit payloads or entity IDs. */ | |
| export function sqlDiagnosticEvent(metadata: SQLExecutionMetadata, | |
| correlation?: RuntimeExecutionCorrelation): RuntimeDiagnosticEvent { | |
| if (metadata.logMode !== 'masked') throw new Error('Telemetry requires safe SQL projection'); | |
| const nodes = (frames: readonly { kind: string; name: string; detail?: string }[] = []) => | |
| JSON.stringify(frames.map(frame => ({ kind: frame.kind, name: frame.name, detail: frame.detail ?? '' }))); | |
| return Object.freeze({ body: 'TeaQL SQL execution', correlation, | |
| attributes: Object.freeze({ | |
| 'teaql.trace_chain': nodes(metadata.traceChain), | |
| 'teaql.trace_path': nodes(metadata.tracePath), | |
| 'teaql.mutation_lineage': nodes(metadata.mutationLineage), | |
| 'teaql.intent.comment': metadata.comment ?? metadata.auditReason ?? '', | |
| 'teaql.intent.purpose': metadata.purpose ?? '', | |
| 'teaql.sql.debug': metadata.debugSQL, | |
| 'teaql.sql.log_mode': metadata.logMode, | |
| 'teaql.sql.operation': metadata.operation, | |
| 'teaql.sql.outcome': metadata.executionOutcome ?? 'unknown', | |
| 'teaql.sql.elapsed_us': metadata.elapsedMicros, | |
| ...(metadata.resultCount === undefined ? {} : { 'teaql.sql.result_count': metadata.resultCount }), | |
| ...(metadata.affectedRows === undefined ? {} : { 'teaql.sql.affected_rows': metadata.affectedRows }), | |
| }) }); | |
| } | |