@smoothbricks/lmao 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +269 -0
- package/dist/allocator.wasm +0 -0
- package/dist/bun/preload.d.ts +11 -0
- package/dist/bun/preload.d.ts.map +1 -0
- package/dist/bun/preload.js +10 -0
- package/dist/bun/trace-preload.d.ts +8 -0
- package/dist/bun/trace-preload.d.ts.map +1 -0
- package/dist/bun/trace-preload.js +12 -0
- package/dist/es.d.ts +8 -0
- package/dist/es.d.ts.map +1 -0
- package/dist/es.js +9 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/lib/JsBufferStrategy.d.ts +49 -0
- package/dist/lib/JsBufferStrategy.d.ts.map +1 -0
- package/dist/lib/JsBufferStrategy.js +60 -0
- package/dist/lib/archive/chunkCompaction.d.ts +15 -0
- package/dist/lib/archive/chunkCompaction.d.ts.map +1 -0
- package/dist/lib/archive/chunkCompaction.js +24 -0
- package/dist/lib/archive/chunkEnvelope.d.ts +21 -0
- package/dist/lib/archive/chunkEnvelope.d.ts.map +1 -0
- package/dist/lib/archive/chunkEnvelope.js +55 -0
- package/dist/lib/archive/chunkRouting.d.ts +10 -0
- package/dist/lib/archive/chunkRouting.d.ts.map +1 -0
- package/dist/lib/archive/chunkRouting.js +47 -0
- package/dist/lib/archive/chunkStats.d.ts +12 -0
- package/dist/lib/archive/chunkStats.d.ts.map +1 -0
- package/dist/lib/archive/chunkStats.js +10 -0
- package/dist/lib/archive/index.d.ts +5 -0
- package/dist/lib/archive/index.d.ts.map +1 -0
- package/dist/lib/archive/index.js +4 -0
- package/dist/lib/arrow/capacityStats.d.ts +9 -0
- package/dist/lib/arrow/capacityStats.d.ts.map +1 -0
- package/dist/lib/arrow/capacityStats.js +231 -0
- package/dist/lib/arrow/dictionaries.d.ts +27 -0
- package/dist/lib/arrow/dictionaries.d.ts.map +1 -0
- package/dist/lib/arrow/dictionaries.js +135 -0
- package/dist/lib/arrow/flechette.d.ts +40 -0
- package/dist/lib/arrow/flechette.d.ts.map +1 -0
- package/dist/lib/arrow/flechette.js +67 -0
- package/dist/lib/arrow/utils.d.ts +38 -0
- package/dist/lib/arrow/utils.d.ts.map +1 -0
- package/dist/lib/arrow/utils.js +112 -0
- package/dist/lib/buffer/Nanoseconds.d.ts +109 -0
- package/dist/lib/buffer/Nanoseconds.d.ts.map +1 -0
- package/dist/lib/buffer/Nanoseconds.js +86 -0
- package/dist/lib/bufferStrategy.d.ts +95 -0
- package/dist/lib/bufferStrategy.d.ts.map +1 -0
- package/dist/lib/bufferStrategy.js +1 -0
- package/dist/lib/capacityTuning.d.ts +50 -0
- package/dist/lib/capacityTuning.d.ts.map +1 -0
- package/dist/lib/capacityTuning.js +65 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts +35 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/evaluatorGenerator.js +199 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +139 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.js +289 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts +115 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/spanLoggerGenerator.js +575 -0
- package/dist/lib/convertToArrow.d.ts +40 -0
- package/dist/lib/convertToArrow.d.ts.map +1 -0
- package/dist/lib/convertToArrow.js +1467 -0
- package/dist/lib/defineOpContext.d.ts +96 -0
- package/dist/lib/defineOpContext.d.ts.map +1 -0
- package/dist/lib/defineOpContext.js +227 -0
- package/dist/lib/errors/Blocked.d.ts +113 -0
- package/dist/lib/errors/Blocked.d.ts.map +1 -0
- package/dist/lib/errors/Blocked.js +68 -0
- package/dist/lib/errors/CodeError.d.ts +101 -0
- package/dist/lib/errors/CodeError.d.ts.map +1 -0
- package/dist/lib/errors/CodeError.js +42 -0
- package/dist/lib/errors/RetriesExhausted.d.ts +67 -0
- package/dist/lib/errors/RetriesExhausted.d.ts.map +1 -0
- package/dist/lib/errors/RetriesExhausted.js +31 -0
- package/dist/lib/errors/Transient.d.ts +115 -0
- package/dist/lib/errors/Transient.d.ts.map +1 -0
- package/dist/lib/errors/Transient.js +54 -0
- package/dist/lib/errors/index.d.ts +14 -0
- package/dist/lib/errors/index.d.ts.map +1 -0
- package/dist/lib/errors/index.js +16 -0
- package/dist/lib/errors/retry-policy.d.ts +60 -0
- package/dist/lib/errors/retry-policy.d.ts.map +1 -0
- package/dist/lib/errors/retry-policy.js +54 -0
- package/dist/lib/flushScheduler.d.ts +162 -0
- package/dist/lib/flushScheduler.d.ts.map +1 -0
- package/dist/lib/flushScheduler.js +388 -0
- package/dist/lib/library.d.ts +149 -0
- package/dist/lib/library.d.ts.map +1 -0
- package/dist/lib/library.js +588 -0
- package/dist/lib/logApi.d.ts +61 -0
- package/dist/lib/logApi.d.ts.map +1 -0
- package/dist/lib/logApi.js +12 -0
- package/dist/lib/logBinding.d.ts +63 -0
- package/dist/lib/logBinding.d.ts.map +1 -0
- package/dist/lib/logBinding.js +1 -0
- package/dist/lib/op.d.ts +105 -0
- package/dist/lib/op.d.ts.map +1 -0
- package/dist/lib/op.js +59 -0
- package/dist/lib/opContext/contextTypes.d.ts +88 -0
- package/dist/lib/opContext/contextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/contextTypes.js +34 -0
- package/dist/lib/opContext/createOpGroup.d.ts +57 -0
- package/dist/lib/opContext/createOpGroup.d.ts.map +1 -0
- package/dist/lib/opContext/createOpGroup.js +341 -0
- package/dist/lib/opContext/defineOp.d.ts +83 -0
- package/dist/lib/opContext/defineOp.d.ts.map +1 -0
- package/dist/lib/opContext/defineOp.js +197 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts +58 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts.map +1 -0
- package/dist/lib/opContext/featureFlagTypes.js +1 -0
- package/dist/lib/opContext/index.d.ts +13 -0
- package/dist/lib/opContext/index.d.ts.map +1 -0
- package/dist/lib/opContext/index.js +15 -0
- package/dist/lib/opContext/opGroupTypes.d.ts +250 -0
- package/dist/lib/opContext/opGroupTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opGroupTypes.js +31 -0
- package/dist/lib/opContext/opTypes.d.ts +48 -0
- package/dist/lib/opContext/opTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opTypes.js +7 -0
- package/dist/lib/opContext/spanContextTypes.d.ts +347 -0
- package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/spanContextTypes.js +1 -0
- package/dist/lib/opContext/types.d.ts +297 -0
- package/dist/lib/opContext/types.d.ts.map +1 -0
- package/dist/lib/opContext/types.js +16 -0
- package/dist/lib/result.d.ts +308 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +359 -0
- package/dist/lib/schema/LogSchema.d.ts +62 -0
- package/dist/lib/schema/LogSchema.d.ts.map +1 -0
- package/dist/lib/schema/LogSchema.js +134 -0
- package/dist/lib/schema/builder.d.ts +12 -0
- package/dist/lib/schema/builder.d.ts.map +1 -0
- package/dist/lib/schema/builder.js +169 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts +60 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts.map +1 -0
- package/dist/lib/schema/defineFeatureFlags.js +29 -0
- package/dist/lib/schema/defineLogSchema.d.ts +87 -0
- package/dist/lib/schema/defineLogSchema.d.ts.map +1 -0
- package/dist/lib/schema/defineLogSchema.js +171 -0
- package/dist/lib/schema/evaluator.d.ts +267 -0
- package/dist/lib/schema/evaluator.d.ts.map +1 -0
- package/dist/lib/schema/evaluator.js +169 -0
- package/dist/lib/schema/extend.d.ts +14 -0
- package/dist/lib/schema/extend.d.ts.map +1 -0
- package/dist/lib/schema/extend.js +51 -0
- package/dist/lib/schema/systemSchema.d.ts +112 -0
- package/dist/lib/schema/systemSchema.d.ts.map +1 -0
- package/dist/lib/schema/systemSchema.js +260 -0
- package/dist/lib/schema/typeGuards.d.ts +52 -0
- package/dist/lib/schema/typeGuards.d.ts.map +1 -0
- package/dist/lib/schema/typeGuards.js +127 -0
- package/dist/lib/schema/types.d.ts +156 -0
- package/dist/lib/schema/types.d.ts.map +1 -0
- package/dist/lib/schema/types.js +4 -0
- package/dist/lib/spanBuffer.d.ts +133 -0
- package/dist/lib/spanBuffer.d.ts.map +1 -0
- package/dist/lib/spanBuffer.js +442 -0
- package/dist/lib/spanBufferHelpers.d.ts +53 -0
- package/dist/lib/spanBufferHelpers.d.ts.map +1 -0
- package/dist/lib/spanBufferHelpers.js +65 -0
- package/dist/lib/spanBufferStats.d.ts +38 -0
- package/dist/lib/spanBufferStats.d.ts.map +1 -0
- package/dist/lib/spanBufferStats.js +1 -0
- package/dist/lib/spanContext.d.ts +141 -0
- package/dist/lib/spanContext.d.ts.map +1 -0
- package/dist/lib/spanContext.js +763 -0
- package/dist/lib/sqlite/index.d.ts +14 -0
- package/dist/lib/sqlite/index.d.ts.map +1 -0
- package/dist/lib/sqlite/index.js +12 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts +24 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-async-writer.js +65 -0
- package/dist/lib/sqlite/sqlite-common.d.ts +37 -0
- package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-common.js +207 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts +25 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-d1.js +67 -0
- package/dist/lib/sqlite/sqlite-db.d.ts +29 -0
- package/dist/lib/sqlite/sqlite-db.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-db.js +1 -0
- package/dist/lib/sqlite/sqlite-node.d.ts +16 -0
- package/dist/lib/sqlite/sqlite-node.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-node.js +68 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts +39 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-writer.js +78 -0
- package/dist/lib/testing/bun-harness.d.ts +150 -0
- package/dist/lib/testing/bun-harness.d.ts.map +1 -0
- package/dist/lib/testing/bun-harness.js +729 -0
- package/dist/lib/testing/extractFacts.d.ts +73 -0
- package/dist/lib/testing/extractFacts.d.ts.map +1 -0
- package/dist/lib/testing/extractFacts.js +237 -0
- package/dist/lib/testing/facts.d.ts +235 -0
- package/dist/lib/testing/facts.d.ts.map +1 -0
- package/dist/lib/testing/facts.js +209 -0
- package/dist/lib/testing/index.d.ts +58 -0
- package/dist/lib/testing/index.d.ts.map +1 -0
- package/dist/lib/testing/index.js +74 -0
- package/dist/lib/testing/queryable-span.d.ts +39 -0
- package/dist/lib/testing/queryable-span.d.ts.map +1 -0
- package/dist/lib/testing/queryable-span.js +58 -0
- package/dist/lib/testing/span-query.d.ts +21 -0
- package/dist/lib/testing/span-query.d.ts.map +1 -0
- package/dist/lib/testing/span-query.js +47 -0
- package/dist/lib/testing/stdio-replay.d.ts +4 -0
- package/dist/lib/testing/stdio-replay.d.ts.map +1 -0
- package/dist/lib/testing/stdio-replay.js +42 -0
- package/dist/lib/testing/trace-query.d.ts +59 -0
- package/dist/lib/testing/trace-query.d.ts.map +1 -0
- package/dist/lib/testing/trace-query.js +462 -0
- package/dist/lib/testing/vitest-harness.d.ts +135 -0
- package/dist/lib/testing/vitest-harness.d.ts.map +1 -0
- package/dist/lib/testing/vitest-harness.js +486 -0
- package/dist/lib/threadId.d.ts +58 -0
- package/dist/lib/threadId.d.ts.map +1 -0
- package/dist/lib/threadId.js +123 -0
- package/dist/lib/traceContext.d.ts +116 -0
- package/dist/lib/traceContext.d.ts.map +1 -0
- package/dist/lib/traceContext.js +37 -0
- package/dist/lib/traceId.d.ts +78 -0
- package/dist/lib/traceId.d.ts.map +1 -0
- package/dist/lib/traceId.js +87 -0
- package/dist/lib/traceRoot.d.ts +133 -0
- package/dist/lib/traceRoot.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.d.ts +75 -0
- package/dist/lib/traceRoot.es.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.js +129 -0
- package/dist/lib/traceRoot.js +19 -0
- package/dist/lib/traceRoot.node.d.ts +77 -0
- package/dist/lib/traceRoot.node.d.ts.map +1 -0
- package/dist/lib/traceRoot.node.js +133 -0
- package/dist/lib/traceRoot.universal.d.ts +3 -0
- package/dist/lib/traceRoot.universal.d.ts.map +1 -0
- package/dist/lib/traceRoot.universal.js +17 -0
- package/dist/lib/tracer.d.ts +296 -0
- package/dist/lib/tracer.d.ts.map +1 -0
- package/dist/lib/tracer.js +346 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts +56 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts.map +1 -0
- package/dist/lib/tracers/ArrayQueueTracer.js +67 -0
- package/dist/lib/tracers/CompositeTracer.d.ts +24 -0
- package/dist/lib/tracers/CompositeTracer.d.ts.map +1 -0
- package/dist/lib/tracers/CompositeTracer.js +57 -0
- package/dist/lib/tracers/NoOpTracer.d.ts +58 -0
- package/dist/lib/tracers/NoOpTracer.d.ts.map +1 -0
- package/dist/lib/tracers/NoOpTracer.js +41 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts +42 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts.map +1 -0
- package/dist/lib/tracers/SQLiteTracer.js +84 -0
- package/dist/lib/tracers/StdioTracer.d.ts +83 -0
- package/dist/lib/tracers/StdioTracer.d.ts.map +1 -0
- package/dist/lib/tracers/StdioTracer.js +270 -0
- package/dist/lib/tracers/TestTracer.d.ts +95 -0
- package/dist/lib/tracers/TestTracer.d.ts.map +1 -0
- package/dist/lib/tracers/TestTracer.js +87 -0
- package/dist/lib/tracers/index.d.ts +12 -0
- package/dist/lib/tracers/index.d.ts.map +1 -0
- package/dist/lib/tracers/index.js +11 -0
- package/dist/lib/types.d.ts +366 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utf8Cache.d.ts +111 -0
- package/dist/lib/utf8Cache.d.ts.map +1 -0
- package/dist/lib/utf8Cache.js +177 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts +88 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -0
- package/dist/lib/wasm/WasmBufferStrategy.js +138 -0
- package/dist/lib/wasm/wasmAllocator.d.ts +109 -0
- package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -0
- package/dist/lib/wasm/wasmAllocator.js +227 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts +123 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -0
- package/dist/lib/wasm/wasmSpanBuffer.js +772 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts +167 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -0
- package/dist/lib/wasm/wasmTraceRoot.js +264 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +8 -0
- package/dist/testing.d.ts +18 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/package.json +193 -0
- package/src/bun/preload.ts +11 -0
- package/src/bun/trace-preload.ts +14 -0
- package/src/es.ts +11 -0
- package/src/index.ts +194 -0
- package/src/lib/JsBufferStrategy.ts +102 -0
- package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +485 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +390 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +647 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +292 -0
- package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +354 -0
- package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +127 -0
- package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +392 -0
- package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +389 -0
- package/src/lib/__tests__/arrow-conversion-algorithms.test.ts +54 -0
- package/src/lib/__tests__/arrow-test-helpers.ts +71 -0
- package/src/lib/__tests__/binary-e2e.test.ts +203 -0
- package/src/lib/__tests__/buffer-overflow-op-api.test.ts +608 -0
- package/src/lib/__tests__/buffer-overflow.test.ts +612 -0
- package/src/lib/__tests__/capacity-tuning.test.ts +544 -0
- package/src/lib/__tests__/effective-schema.test.ts +439 -0
- package/src/lib/__tests__/flechette.test.ts +42 -0
- package/src/lib/__tests__/flushScheduler.test.ts +537 -0
- package/src/lib/__tests__/integration.test.ts +600 -0
- package/src/lib/__tests__/library.test.ts +934 -0
- package/src/lib/__tests__/nested-library-tasks.test.ts +849 -0
- package/src/lib/__tests__/op-context-binding.test.ts +135 -0
- package/src/lib/__tests__/op-metadata.test.ts +198 -0
- package/src/lib/__tests__/op-type-safety.test.ts +71 -0
- package/src/lib/__tests__/package-exports.test.ts +57 -0
- package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +319 -0
- package/src/lib/__tests__/remapped-buffer-view.test.ts +635 -0
- package/src/lib/__tests__/scope-attributes.test.ts +348 -0
- package/src/lib/__tests__/span-lifecycle.test.ts +680 -0
- package/src/lib/__tests__/sync-async-trace.test.ts +435 -0
- package/src/lib/__tests__/test-helpers.ts +318 -0
- package/src/lib/__tests__/timestamp.test.ts +259 -0
- package/src/lib/__tests__/trace-archive-primitives.test.ts +98 -0
- package/src/lib/__tests__/traceContext-type-enforcement.test.ts +271 -0
- package/src/lib/__tests__/tracer.test.ts +211 -0
- package/src/lib/__tests__/type-narrowing.test.ts +137 -0
- package/src/lib/archive/chunkCompaction.ts +44 -0
- package/src/lib/archive/chunkEnvelope.ts +79 -0
- package/src/lib/archive/chunkRouting.ts +70 -0
- package/src/lib/archive/chunkStats.ts +25 -0
- package/src/lib/archive/index.ts +4 -0
- package/src/lib/arrow/capacityStats.ts +340 -0
- package/src/lib/arrow/dictionaries.ts +159 -0
- package/src/lib/arrow/flechette.ts +114 -0
- package/src/lib/arrow/utils.ts +126 -0
- package/src/lib/buffer/Nanoseconds.ts +131 -0
- package/src/lib/bufferStrategy.ts +106 -0
- package/src/lib/capacityTuning.ts +102 -0
- package/src/lib/codegen/__tests__/__snapshots__/evaluatorGenerator.test.ts.snap +160 -0
- package/src/lib/codegen/__tests__/__snapshots__/scopeGenerator.test.ts.snap +196 -0
- package/src/lib/codegen/__tests__/__snapshots__/spanLoggerGenerator.test.ts.snap +1965 -0
- package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +516 -0
- package/src/lib/codegen/__tests__/nullBitmap.test.ts +207 -0
- package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +237 -0
- package/src/lib/codegen/evaluatorGenerator.ts +309 -0
- package/src/lib/codegen/fixedPositionWriterGenerator.ts +444 -0
- package/src/lib/codegen/spanLoggerGenerator.ts +715 -0
- package/src/lib/convertToArrow.ts +1805 -0
- package/src/lib/defineOpContext.ts +398 -0
- package/src/lib/errors/Blocked.ts +165 -0
- package/src/lib/errors/CodeError.ts +132 -0
- package/src/lib/errors/RetriesExhausted.ts +78 -0
- package/src/lib/errors/Transient.ts +168 -0
- package/src/lib/errors/__tests__/Blocked-config.test.ts +152 -0
- package/src/lib/errors/__tests__/Transient.test.ts +129 -0
- package/src/lib/errors/__tests__/retry-policy.test.ts +85 -0
- package/src/lib/errors/index.ts +24 -0
- package/src/lib/errors/retry-policy.ts +87 -0
- package/src/lib/flushScheduler.ts +509 -0
- package/src/lib/library.ts +682 -0
- package/src/lib/logApi.ts +70 -0
- package/src/lib/logBinding.ts +67 -0
- package/src/lib/op.ts +103 -0
- package/src/lib/opContext/__tests__/retry.test.ts +764 -0
- package/src/lib/opContext/contextTypes.ts +130 -0
- package/src/lib/opContext/createOpGroup.ts +456 -0
- package/src/lib/opContext/defineOp.ts +281 -0
- package/src/lib/opContext/featureFlagTypes.ts +54 -0
- package/src/lib/opContext/index.ts +16 -0
- package/src/lib/opContext/opGroupTypes.ts +342 -0
- package/src/lib/opContext/opTypes.ts +80 -0
- package/src/lib/opContext/spanContextTypes.ts +398 -0
- package/src/lib/opContext/types.ts +403 -0
- package/src/lib/result.ts +550 -0
- package/src/lib/schema/LogSchema.ts +153 -0
- package/src/lib/schema/__tests__/defineLogSchema.test.ts +342 -0
- package/src/lib/schema/__tests__/featureFlags.test.ts +443 -0
- package/src/lib/schema/builder.ts +201 -0
- package/src/lib/schema/defineFeatureFlags.ts +91 -0
- package/src/lib/schema/defineLogSchema.ts +291 -0
- package/src/lib/schema/evaluator.ts +404 -0
- package/src/lib/schema/extend.ts +69 -0
- package/src/lib/schema/systemSchema.ts +339 -0
- package/src/lib/schema/typeGuards.ts +163 -0
- package/src/lib/schema/types.ts +265 -0
- package/src/lib/spanBuffer.ts +571 -0
- package/src/lib/spanBufferHelpers.ts +73 -0
- package/src/lib/spanBufferStats.ts +40 -0
- package/src/lib/spanContext.ts +1566 -0
- package/src/lib/sqlite/__tests__/sqlite-common.test.ts +89 -0
- package/src/lib/sqlite/index.ts +26 -0
- package/src/lib/sqlite/sqlite-async-writer.ts +101 -0
- package/src/lib/sqlite/sqlite-common.ts +309 -0
- package/src/lib/sqlite/sqlite-d1.ts +104 -0
- package/src/lib/sqlite/sqlite-db.ts +32 -0
- package/src/lib/sqlite/sqlite-node.ts +83 -0
- package/src/lib/sqlite/sqlite-writer.ts +128 -0
- package/src/lib/testing/TRACE-TESTING.md +100 -0
- package/src/lib/testing/__tests__/bun-harness.test.ts +108 -0
- package/src/lib/testing/__tests__/extractFacts.test.ts +279 -0
- package/src/lib/testing/__tests__/facts.test.ts +324 -0
- package/src/lib/testing/__tests__/vitest-harness.test.ts +32 -0
- package/src/lib/testing/bun-harness.ts +990 -0
- package/src/lib/testing/extractFacts.ts +362 -0
- package/src/lib/testing/facts.ts +470 -0
- package/src/lib/testing/index.ts +141 -0
- package/src/lib/testing/queryable-span.ts +108 -0
- package/src/lib/testing/span-query.ts +65 -0
- package/src/lib/testing/stdio-replay.ts +50 -0
- package/src/lib/testing/trace-query.ts +329 -0
- package/src/lib/testing/vitest-harness.ts +691 -0
- package/src/lib/threadId.ts +135 -0
- package/src/lib/traceContext.ts +182 -0
- package/src/lib/traceId.ts +142 -0
- package/src/lib/traceRoot.es.ts +157 -0
- package/src/lib/traceRoot.node.ts +170 -0
- package/src/lib/traceRoot.ts +154 -0
- package/src/lib/traceRoot.universal.ts +22 -0
- package/src/lib/tracer.ts +896 -0
- package/src/lib/tracers/ArrayQueueTracer.ts +76 -0
- package/src/lib/tracers/CompositeTracer.ts +76 -0
- package/src/lib/tracers/NoOpTracer.ts +73 -0
- package/src/lib/tracers/SQLiteTracer.ts +115 -0
- package/src/lib/tracers/StdioTracer.ts +380 -0
- package/src/lib/tracers/TestTracer.ts +146 -0
- package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +184 -0
- package/src/lib/tracers/__tests__/NoOpTracer.test.ts +204 -0
- package/src/lib/tracers/__tests__/StdioTracer.test.ts +313 -0
- package/src/lib/tracers/__tests__/TestTracer.test.ts +200 -0
- package/src/lib/tracers/index.ts +12 -0
- package/src/lib/types.ts +498 -0
- package/src/lib/utf8Cache.ts +201 -0
- package/src/lib/wasm/WasmBufferStrategy.ts +219 -0
- package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +256 -0
- package/src/lib/wasm/__tests__/wasm-integration.test.ts +476 -0
- package/src/lib/wasm/__tests__/wasmAllocator.test.ts +699 -0
- package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +449 -0
- package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +390 -0
- package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +444 -0
- package/src/lib/wasm/allocator.zig +945 -0
- package/src/lib/wasm/wasmAllocator.ts +469 -0
- package/src/lib/wasm/wasmSpanBuffer.ts +1014 -0
- package/src/lib/wasm/wasmTraceRoot.ts +315 -0
- package/src/node.ts +10 -0
- package/src/testing.ts +18 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level tests for Tracer.trace() required/optional property enforcement
|
|
3
|
+
*
|
|
4
|
+
* These tests verify that TypeScript properly enforces required vs optional
|
|
5
|
+
* properties in Tracer.trace() based on the ctx type definition.
|
|
6
|
+
*
|
|
7
|
+
* Per spec 01l_module_builder_pattern.md (updated for Op-centric API):
|
|
8
|
+
* - Properties with `null as Type` in ctx are REQUIRED in trace() options
|
|
9
|
+
* - Properties with `undefined as Type | undefined` are OPTIONAL in trace() options
|
|
10
|
+
* - Properties with values are optional with defaults
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, it } from 'bun:test';
|
|
14
|
+
// Must import test-helpers first to initialize timestamp implementation
|
|
15
|
+
import './test-helpers.js';
|
|
16
|
+
import { S } from '@smoothbricks/arrow-builder';
|
|
17
|
+
import { defineOpContext } from '../defineOpContext.js';
|
|
18
|
+
import { defineLogSchema } from '../schema/defineLogSchema.js';
|
|
19
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
20
|
+
import { createTestTracerOptions } from './test-helpers.js';
|
|
21
|
+
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// Test Factory Definitions
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
// Factory with required and optional ctx properties
|
|
27
|
+
const testCtxDefaults: {
|
|
28
|
+
env: { apiTimeout: number; region: string } | null;
|
|
29
|
+
requestId: string | null;
|
|
30
|
+
userId: string | undefined;
|
|
31
|
+
} = {
|
|
32
|
+
env: null,
|
|
33
|
+
requestId: null,
|
|
34
|
+
userId: undefined,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const testFactory = defineOpContext({
|
|
38
|
+
logSchema: defineLogSchema({
|
|
39
|
+
userId: S.category(),
|
|
40
|
+
}),
|
|
41
|
+
ctx: testCtxDefaults,
|
|
42
|
+
}); // Create a tracer for testing with proper type
|
|
43
|
+
const { trace: testTrace } = new TestTracer(testFactory, { ...createTestTracerOptions() });
|
|
44
|
+
|
|
45
|
+
// =============================================================================
|
|
46
|
+
// Type Enforcement Tests
|
|
47
|
+
// =============================================================================
|
|
48
|
+
|
|
49
|
+
describe('Tracer.trace Type Enforcement', () => {
|
|
50
|
+
it('should accept all required properties', async () => {
|
|
51
|
+
// This should compile without errors
|
|
52
|
+
const result = await testTrace(
|
|
53
|
+
'test-span',
|
|
54
|
+
{
|
|
55
|
+
env: { apiTimeout: 5000, region: 'us-east-1' },
|
|
56
|
+
requestId: 'req-123',
|
|
57
|
+
// userId is optional, can be omitted
|
|
58
|
+
},
|
|
59
|
+
(ctx) => {
|
|
60
|
+
expect(ctx).toBeDefined();
|
|
61
|
+
if (ctx.env === null) {
|
|
62
|
+
throw new Error('env should be populated from trace overrides');
|
|
63
|
+
}
|
|
64
|
+
expect(ctx.env.region).toBe('us-east-1');
|
|
65
|
+
expect(ctx.requestId).toBe('req-123');
|
|
66
|
+
return 'done';
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(result).toBe('done');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should accept optional properties', async () => {
|
|
74
|
+
// This should compile without errors
|
|
75
|
+
const result = await testTrace(
|
|
76
|
+
'test-span',
|
|
77
|
+
{
|
|
78
|
+
env: { apiTimeout: 5000, region: 'us-east-1' },
|
|
79
|
+
requestId: 'req-123',
|
|
80
|
+
userId: 'user-456', // Optional property provided
|
|
81
|
+
},
|
|
82
|
+
(ctx) => {
|
|
83
|
+
expect(ctx).toBeDefined();
|
|
84
|
+
expect(ctx.userId).toBe('user-456');
|
|
85
|
+
return 'done';
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(result).toBe('done');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Note: Type-level tests for missing properties would require @ts-expect-error
|
|
93
|
+
// but the exact error message depends on TypeScript version.
|
|
94
|
+
// The important thing is that the API enforces required properties at the type level.
|
|
95
|
+
it('should require env and requestId (compile-time check)', async () => {
|
|
96
|
+
// This test documents that missing required properties cause compile errors
|
|
97
|
+
// We test by providing all required properties and verifying runtime behavior
|
|
98
|
+
const result = await testTrace(
|
|
99
|
+
'test-span',
|
|
100
|
+
{
|
|
101
|
+
env: { apiTimeout: 5000, region: 'us-east-1' },
|
|
102
|
+
requestId: 'req-123',
|
|
103
|
+
},
|
|
104
|
+
(ctx) => {
|
|
105
|
+
expect(ctx.env).toEqual({ apiTimeout: 5000, region: 'us-east-1' });
|
|
106
|
+
expect(ctx.requestId).toBe('req-123');
|
|
107
|
+
expect(ctx.userId).toBeUndefined();
|
|
108
|
+
return 'done';
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(result).toBe('done');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// =============================================================================
|
|
117
|
+
// Extra Type Flow Tests
|
|
118
|
+
// =============================================================================
|
|
119
|
+
|
|
120
|
+
describe('Context Type Flow Through Factory', () => {
|
|
121
|
+
it('should preserve ctx type through defineOpContext', async () => {
|
|
122
|
+
const defaults: { required: string | null; optional: number | undefined } = {
|
|
123
|
+
required: null,
|
|
124
|
+
optional: undefined,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const factory = defineOpContext({
|
|
128
|
+
logSchema: defineLogSchema({}),
|
|
129
|
+
ctx: defaults,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
133
|
+
|
|
134
|
+
// Type should be preserved - required is required, optional is optional
|
|
135
|
+
const result = await trace(
|
|
136
|
+
'test-span',
|
|
137
|
+
{
|
|
138
|
+
required: 'value',
|
|
139
|
+
// optional can be omitted
|
|
140
|
+
},
|
|
141
|
+
(ctx) => {
|
|
142
|
+
expect(ctx.required).toBe('value');
|
|
143
|
+
return 'done';
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(result).toBe('done');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should work without ctx property', async () => {
|
|
151
|
+
// When ctx is not provided, no user context is available
|
|
152
|
+
const factory = defineOpContext({
|
|
153
|
+
logSchema: defineLogSchema({}),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
157
|
+
|
|
158
|
+
// Should accept empty options or no options
|
|
159
|
+
const result = await trace('test-span', (ctx) => {
|
|
160
|
+
expect(ctx).toBeDefined();
|
|
161
|
+
return 'done';
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(result).toBe('done');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// =============================================================================
|
|
169
|
+
// Reserved Keys Enforcement Tests
|
|
170
|
+
// =============================================================================
|
|
171
|
+
|
|
172
|
+
describe('Reserved Keys Enforcement', () => {
|
|
173
|
+
// Reserved context props are: buffer, tag, log, scope, setScope, ok, err, span, ff, deps
|
|
174
|
+
|
|
175
|
+
it('should throw at runtime for buffer reserved key', () => {
|
|
176
|
+
const invalidCtx: Record<string, unknown> = {
|
|
177
|
+
buffer: 'should-fail',
|
|
178
|
+
};
|
|
179
|
+
expect(() =>
|
|
180
|
+
defineOpContext({
|
|
181
|
+
logSchema: defineLogSchema({}),
|
|
182
|
+
ctx: invalidCtx,
|
|
183
|
+
}),
|
|
184
|
+
).toThrow(/reserved/i);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should throw at runtime for span reserved key', () => {
|
|
188
|
+
const invalidCtx: Record<string, unknown> = {
|
|
189
|
+
span: () => {},
|
|
190
|
+
};
|
|
191
|
+
expect(() =>
|
|
192
|
+
defineOpContext({
|
|
193
|
+
logSchema: defineLogSchema({}),
|
|
194
|
+
ctx: invalidCtx,
|
|
195
|
+
}),
|
|
196
|
+
).toThrow(/reserved/i);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should throw at runtime for ff reserved key', () => {
|
|
200
|
+
const invalidCtx: Record<string, unknown> = {
|
|
201
|
+
ff: {},
|
|
202
|
+
};
|
|
203
|
+
expect(() =>
|
|
204
|
+
defineOpContext({
|
|
205
|
+
logSchema: defineLogSchema({}),
|
|
206
|
+
ctx: invalidCtx,
|
|
207
|
+
}),
|
|
208
|
+
).toThrow(/reserved/i);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should throw at runtime for tag reserved key', () => {
|
|
212
|
+
const invalidCtx: Record<string, unknown> = {
|
|
213
|
+
tag: {},
|
|
214
|
+
};
|
|
215
|
+
expect(() =>
|
|
216
|
+
defineOpContext({
|
|
217
|
+
logSchema: defineLogSchema({}),
|
|
218
|
+
ctx: invalidCtx,
|
|
219
|
+
}),
|
|
220
|
+
).toThrow(/reserved/i);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should throw at runtime for log reserved key', () => {
|
|
224
|
+
const invalidCtx: Record<string, unknown> = {
|
|
225
|
+
log: {},
|
|
226
|
+
};
|
|
227
|
+
expect(() =>
|
|
228
|
+
defineOpContext({
|
|
229
|
+
logSchema: defineLogSchema({}),
|
|
230
|
+
ctx: invalidCtx,
|
|
231
|
+
}),
|
|
232
|
+
).toThrow(/reserved/i);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should throw at runtime for ok reserved key', () => {
|
|
236
|
+
const invalidCtx: Record<string, unknown> = {
|
|
237
|
+
ok: () => {},
|
|
238
|
+
};
|
|
239
|
+
expect(() =>
|
|
240
|
+
defineOpContext({
|
|
241
|
+
logSchema: defineLogSchema({}),
|
|
242
|
+
ctx: invalidCtx,
|
|
243
|
+
}),
|
|
244
|
+
).toThrow(/reserved/i);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('should throw at runtime for err reserved key', () => {
|
|
248
|
+
const invalidCtx: Record<string, unknown> = {
|
|
249
|
+
err: () => {},
|
|
250
|
+
};
|
|
251
|
+
expect(() =>
|
|
252
|
+
defineOpContext({
|
|
253
|
+
logSchema: defineLogSchema({}),
|
|
254
|
+
ctx: invalidCtx,
|
|
255
|
+
}),
|
|
256
|
+
).toThrow(/reserved/i);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should throw for underscore-prefixed properties', () => {
|
|
260
|
+
// Properties starting with _ are reserved for internal use
|
|
261
|
+
const invalidCtx: Record<string, unknown> = {
|
|
262
|
+
_internal: 'should-fail',
|
|
263
|
+
};
|
|
264
|
+
expect(() =>
|
|
265
|
+
defineOpContext({
|
|
266
|
+
logSchema: defineLogSchema({}),
|
|
267
|
+
ctx: invalidCtx,
|
|
268
|
+
}),
|
|
269
|
+
).toThrow(/reserved/i);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracer tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for the Tracer class - the entry point for creating traces.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, it } from 'bun:test';
|
|
8
|
+
// Must import test-helpers first to initialize timestamp implementation
|
|
9
|
+
import './test-helpers.js';
|
|
10
|
+
import { convertSpanTreeToArrowTable } from '../convertToArrow.js';
|
|
11
|
+
import { defineOpContext } from '../defineOpContext.js';
|
|
12
|
+
import { S } from '../schema/builder.js';
|
|
13
|
+
import { defineLogSchema } from '../schema/defineLogSchema.js';
|
|
14
|
+
import { createTraceId } from '../traceId.js';
|
|
15
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
16
|
+
import { createTestTracerOptions } from './test-helpers.js';
|
|
17
|
+
|
|
18
|
+
// Test schema
|
|
19
|
+
const testSchema = defineLogSchema({
|
|
20
|
+
userId: S.category(),
|
|
21
|
+
requestId: S.category(),
|
|
22
|
+
method: S.enum(['GET', 'POST', 'PUT', 'DELETE']),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Test environment type
|
|
26
|
+
interface TestEnv {
|
|
27
|
+
API_KEY: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const requiredEnvCtx: { env: TestEnv | null } = {
|
|
31
|
+
env: null,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const requiredRequestAndEnvCtx: { requestId: string | null; env: TestEnv | null } = {
|
|
35
|
+
requestId: null,
|
|
36
|
+
env: null,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const envAndConfigCtx: { env: TestEnv | null; config: { timeout: number } } = {
|
|
40
|
+
env: null,
|
|
41
|
+
config: { timeout: 5000 },
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe('Tracer', () => {
|
|
45
|
+
describe('basic functionality', () => {
|
|
46
|
+
it('should create a trace and return the body result', async () => {
|
|
47
|
+
const factory = defineOpContext({
|
|
48
|
+
logSchema: testSchema,
|
|
49
|
+
ctx: requiredEnvCtx,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const tracer = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
53
|
+
const { trace } = tracer;
|
|
54
|
+
|
|
55
|
+
const result = await trace('test-trace', { env: { API_KEY: 'test' } }, async (ctx) => {
|
|
56
|
+
ctx.tag.userId('user-123');
|
|
57
|
+
ctx.tag.method('GET');
|
|
58
|
+
return { success: true, data: 'hello' };
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(result).toEqual({ success: true, data: 'hello' });
|
|
62
|
+
expect(tracer.rootBuffers.length).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should collect multiple traces in rootBuffers', async () => {
|
|
66
|
+
const factory = defineOpContext({
|
|
67
|
+
logSchema: testSchema,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const tracer = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
71
|
+
const { trace } = tracer;
|
|
72
|
+
|
|
73
|
+
await trace('trace-1', async (ctx) => {
|
|
74
|
+
ctx.tag.userId('user-1');
|
|
75
|
+
return 'result-1';
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await trace('trace-2', async (ctx) => {
|
|
79
|
+
ctx.tag.userId('user-2');
|
|
80
|
+
return 'result-2';
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(tracer.rootBuffers.length).toBe(2);
|
|
84
|
+
|
|
85
|
+
// Convert each buffer to Arrow table to verify data
|
|
86
|
+
const table1 = convertSpanTreeToArrowTable(tracer.rootBuffers[0]);
|
|
87
|
+
const table2 = convertSpanTreeToArrowTable(tracer.rootBuffers[1]);
|
|
88
|
+
|
|
89
|
+
expect(table1.numRows).toBeGreaterThan(0);
|
|
90
|
+
expect(table2.numRows).toBeGreaterThan(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should handle errors and re-throw', async () => {
|
|
94
|
+
const factory = defineOpContext({
|
|
95
|
+
logSchema: testSchema,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const tracer = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
99
|
+
const { trace } = tracer;
|
|
100
|
+
|
|
101
|
+
const error = new Error('test error');
|
|
102
|
+
|
|
103
|
+
await expect(
|
|
104
|
+
trace('error-trace', async () => {
|
|
105
|
+
throw error;
|
|
106
|
+
}),
|
|
107
|
+
).rejects.toThrow('test error');
|
|
108
|
+
|
|
109
|
+
// Buffer should still be registered for flushing
|
|
110
|
+
expect(tracer.rootBuffers.length).toBe(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should accept optional trace ID', async () => {
|
|
114
|
+
const factory = defineOpContext({
|
|
115
|
+
logSchema: testSchema,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
119
|
+
|
|
120
|
+
const customTraceId = createTraceId('custom-trace-id-12345');
|
|
121
|
+
|
|
122
|
+
await trace('trace-with-id', { trace_id: customTraceId }, async (ctx) => {
|
|
123
|
+
// Access the trace ID from buffer
|
|
124
|
+
expect(ctx.buffer.trace_id).toBe(customTraceId);
|
|
125
|
+
return 'done';
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should accept trace_id combined with userCtx overrides', async () => {
|
|
130
|
+
const factory = defineOpContext({
|
|
131
|
+
logSchema: testSchema,
|
|
132
|
+
ctx: requiredRequestAndEnvCtx,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
136
|
+
const customTraceId = createTraceId('combined-override-test');
|
|
137
|
+
|
|
138
|
+
await trace(
|
|
139
|
+
'combined-overrides',
|
|
140
|
+
{ trace_id: customTraceId, requestId: 'req-123', env: { API_KEY: 'test' } },
|
|
141
|
+
async (ctx) => {
|
|
142
|
+
// Both trace_id and userCtx properties should be available
|
|
143
|
+
if (ctx.env === null) {
|
|
144
|
+
throw new Error('env should be provided in trace overrides');
|
|
145
|
+
}
|
|
146
|
+
expect(ctx.buffer.trace_id).toBe(customTraceId);
|
|
147
|
+
expect(ctx.requestId).toBe('req-123');
|
|
148
|
+
expect(ctx.env.API_KEY).toBe('test');
|
|
149
|
+
return 'done';
|
|
150
|
+
},
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should merge ctx defaults with overrides', async () => {
|
|
155
|
+
const factory = defineOpContext({
|
|
156
|
+
logSchema: testSchema,
|
|
157
|
+
ctx: envAndConfigCtx,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
161
|
+
|
|
162
|
+
await trace('ctx-test', { env: { API_KEY: 'secret' } }, async (ctx) => {
|
|
163
|
+
if (ctx.env === null) {
|
|
164
|
+
throw new Error('env should be provided in trace overrides');
|
|
165
|
+
}
|
|
166
|
+
// env should be from overrides
|
|
167
|
+
expect(ctx.env.API_KEY).toBe('secret');
|
|
168
|
+
// config should use default
|
|
169
|
+
expect(ctx.config.timeout).toBe(5000);
|
|
170
|
+
return 'done';
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Can override config too
|
|
174
|
+
await trace('ctx-test-2', { env: { API_KEY: 'key2' }, config: { timeout: 10000 } }, async (ctx) => {
|
|
175
|
+
expect(ctx.config.timeout).toBe(10000);
|
|
176
|
+
return 'done';
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('overload signatures', () => {
|
|
182
|
+
it('should work without overrides (name, fn)', async () => {
|
|
183
|
+
const factory = defineOpContext({
|
|
184
|
+
logSchema: testSchema,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
188
|
+
|
|
189
|
+
const result = await trace('simple', async () => {
|
|
190
|
+
return 42;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(result).toBe(42);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should work with overrides (name, overrides, fn)', async () => {
|
|
197
|
+
const factory = defineOpContext({
|
|
198
|
+
logSchema: testSchema,
|
|
199
|
+
ctx: { value: 0 },
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const { trace } = new TestTracer(factory, { ...createTestTracerOptions() });
|
|
203
|
+
|
|
204
|
+
const result = await trace('with-overrides', { value: 100 }, async (ctx) => {
|
|
205
|
+
return ctx.value;
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(result).toBe(100);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for TypeScript type narrowing with FluentResult
|
|
3
|
+
* Ensures that result.success properly narrows types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from 'bun:test';
|
|
7
|
+
import { defineOpContext } from '../defineOpContext.js';
|
|
8
|
+
import { defineCodeError } from '../result.js';
|
|
9
|
+
import { S } from '../schema/builder.js';
|
|
10
|
+
import { defineLogSchema } from '../schema/defineLogSchema.js';
|
|
11
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
12
|
+
import { createTestTracerOptions } from './test-helpers.js';
|
|
13
|
+
|
|
14
|
+
// Error code factories for tests
|
|
15
|
+
const TEST_ERROR = defineCodeError('TEST_ERROR')<{ field: string; reason: string }>();
|
|
16
|
+
const VALIDATION_ERROR = defineCodeError('VALIDATION_ERROR')<{ message: string }>();
|
|
17
|
+
|
|
18
|
+
const testSchema = defineLogSchema({
|
|
19
|
+
userId: S.category(),
|
|
20
|
+
customField: S.category(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Create op context factory
|
|
24
|
+
const opContext = defineOpContext({
|
|
25
|
+
logSchema: testSchema,
|
|
26
|
+
ctx: {
|
|
27
|
+
requestId: undefined as string | undefined,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const { defineOp } = opContext;
|
|
32
|
+
|
|
33
|
+
// Create a properly typed tracer - new API passes opContext directly
|
|
34
|
+
function createTestTracer() {
|
|
35
|
+
return new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('Type Narrowing with FluentResult', () => {
|
|
39
|
+
it('should properly narrow success result type', async () => {
|
|
40
|
+
const { trace } = createTestTracer();
|
|
41
|
+
|
|
42
|
+
const testOp = defineOp('testOp', async (ctx) => {
|
|
43
|
+
const result = ctx.ok({ id: 123, name: 'test' });
|
|
44
|
+
|
|
45
|
+
// Type narrowing should work with FluentResult
|
|
46
|
+
if (result.success) {
|
|
47
|
+
// result.value should be accessible and typed correctly
|
|
48
|
+
const value = result.value;
|
|
49
|
+
expect(value.id).toBe(123);
|
|
50
|
+
expect(value.name).toBe('test');
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return ctx.ok(null);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const output = await trace('testOp', testOp);
|
|
58
|
+
expect(output.success).toBe(true);
|
|
59
|
+
if (output.success) {
|
|
60
|
+
expect(output.value).toEqual({ id: 123, name: 'test' });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should properly narrow error result type', async () => {
|
|
65
|
+
const { trace } = createTestTracer();
|
|
66
|
+
|
|
67
|
+
const testOp = defineOp('testOp', async (ctx) => {
|
|
68
|
+
const result = ctx.err(TEST_ERROR({ field: 'email', reason: 'invalid' }));
|
|
69
|
+
|
|
70
|
+
// Type narrowing should work with FluentResult
|
|
71
|
+
if (!result.success) {
|
|
72
|
+
// result.error should be accessible and typed correctly
|
|
73
|
+
const error = result.error;
|
|
74
|
+
expect(error.code).toBe('TEST_ERROR');
|
|
75
|
+
expect(error.field).toBe('email');
|
|
76
|
+
expect(error.reason).toBe('invalid');
|
|
77
|
+
return ctx.ok(error.code);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return ctx.ok(null);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const output = await trace('testOp', testOp);
|
|
84
|
+
expect(output.success).toBe(true);
|
|
85
|
+
if (output.success) {
|
|
86
|
+
expect(output.value).toBe('TEST_ERROR');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should support chaining before type check', async () => {
|
|
91
|
+
const { trace } = createTestTracer();
|
|
92
|
+
|
|
93
|
+
const testOp = defineOp('testOp', async (ctx) => {
|
|
94
|
+
const result = ctx.ok({ id: 456 }).with({ userId: 'user1' }).message('Success');
|
|
95
|
+
|
|
96
|
+
// Type narrowing should still work after chaining
|
|
97
|
+
if (result.success) {
|
|
98
|
+
expect(result.value.id).toBe(456);
|
|
99
|
+
return ctx.ok(result.value.id);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return ctx.ok(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const output = await trace('testOp', testOp);
|
|
106
|
+
expect(output.success).toBe(true);
|
|
107
|
+
if (output.success) {
|
|
108
|
+
expect(output.value).toBe(456);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should handle error result with chaining', async () => {
|
|
113
|
+
const { trace } = createTestTracer();
|
|
114
|
+
|
|
115
|
+
const testOp = defineOp('testOp', async (ctx) => {
|
|
116
|
+
const result = ctx
|
|
117
|
+
.err(VALIDATION_ERROR({ message: 'Invalid input' }))
|
|
118
|
+
.with({ userId: 'user1' })
|
|
119
|
+
.message('Validation failed');
|
|
120
|
+
|
|
121
|
+
// Type narrowing should work after chaining
|
|
122
|
+
if (!result.success) {
|
|
123
|
+
expect(result.error.code).toBe('VALIDATION_ERROR');
|
|
124
|
+
expect(result.error.message).toBe('Invalid input');
|
|
125
|
+
return ctx.ok(result.error.code);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return ctx.ok('OK');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const output = await trace('testOp', testOp);
|
|
132
|
+
expect(output.success).toBe(true);
|
|
133
|
+
if (output.success) {
|
|
134
|
+
expect(output.value).toBe('VALIDATION_ERROR');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TraceChunkEnvelope } from './chunkEnvelope.js';
|
|
2
|
+
|
|
3
|
+
export interface CompactionWindow {
|
|
4
|
+
readonly started_at_ms: number;
|
|
5
|
+
readonly ended_at_ms: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CompactedChunkSet {
|
|
9
|
+
readonly compaction_id: string;
|
|
10
|
+
readonly source_set_hash: string;
|
|
11
|
+
readonly source_chunk_ids: readonly string[];
|
|
12
|
+
readonly source_chunk_count: number;
|
|
13
|
+
readonly total_rows: number;
|
|
14
|
+
readonly window: CompactionWindow;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function compactTraceChunks(chunks: readonly TraceChunkEnvelope[], window: CompactionWindow): CompactedChunkSet {
|
|
18
|
+
const sourceChunkIds = [...new Set(chunks.map((chunk) => chunk.chunk_id))].sort();
|
|
19
|
+
const totalRows = chunks.reduce((sum, chunk) => sum + chunk.row_count, 0);
|
|
20
|
+
const source_set_hash = hashDeterministic(sourceChunkIds.join('|'));
|
|
21
|
+
const compaction_id = `compact_${hashDeterministic(`${source_set_hash}:${window.started_at_ms}:${window.ended_at_ms}`)}`;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
compaction_id,
|
|
25
|
+
source_set_hash,
|
|
26
|
+
source_chunk_ids: sourceChunkIds,
|
|
27
|
+
source_chunk_count: sourceChunkIds.length,
|
|
28
|
+
total_rows: totalRows,
|
|
29
|
+
window,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function hashDeterministic(input: string): string {
|
|
34
|
+
let hash = 0xcbf29ce484222325n;
|
|
35
|
+
const prime = 0x100000001b3n;
|
|
36
|
+
const mod = 0xffffffffffffffffn;
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < input.length; i++) {
|
|
39
|
+
hash ^= BigInt(input.charCodeAt(i));
|
|
40
|
+
hash = (hash * prime) & mod;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return hash.toString(16).padStart(16, '0');
|
|
44
|
+
}
|