@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,600 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for schema integration patterns
|
|
3
|
+
*
|
|
4
|
+
* Tests the full integration of:
|
|
5
|
+
* - Op context definition with defineOpContext()
|
|
6
|
+
* - TraceContext creation with Tracer (destructuring pattern)
|
|
7
|
+
* - Op wrappers with span context
|
|
8
|
+
* - Feature flag evaluation and analytics
|
|
9
|
+
* - Typed tag attribute API
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, expect, it } from 'bun:test';
|
|
13
|
+
// Must import test-helpers first to initialize timestamp implementation
|
|
14
|
+
import './test-helpers.js';
|
|
15
|
+
import { defineOpContext } from '../defineOpContext.js';
|
|
16
|
+
import { defineCodeError } from '../result.js';
|
|
17
|
+
import { S } from '../schema/builder.js';
|
|
18
|
+
import { defineFeatureFlags } from '../schema/defineFeatureFlags.js';
|
|
19
|
+
import { defineLogSchema } from '../schema/defineLogSchema.js';
|
|
20
|
+
import { InMemoryFlagEvaluator } from '../schema/evaluator.js';
|
|
21
|
+
import { TestTracer } from '../tracers/TestTracer.js';
|
|
22
|
+
import { createTestTracerOptions } from './test-helpers.js';
|
|
23
|
+
|
|
24
|
+
// Error code factories for tests
|
|
25
|
+
const VALIDATION_ERROR = defineCodeError('VALIDATION_ERROR')<{ field: string }>();
|
|
26
|
+
const VALIDATION_FAILED = defineCodeError('VALIDATION_FAILED')<{ error: unknown }>();
|
|
27
|
+
const USER_EXISTS = defineCodeError('USER_EXISTS')<{ email: string }>();
|
|
28
|
+
|
|
29
|
+
describe('Schema Integration Patterns', () => {
|
|
30
|
+
// Define log schema for DB operations
|
|
31
|
+
// Using the three string types per specs/lmao/01a_trace_schema_system.md:
|
|
32
|
+
// - S.enum: Known values at compile time
|
|
33
|
+
// - S.category: Values that often repeat
|
|
34
|
+
// - S.text: Unique values
|
|
35
|
+
const dbSchema = defineLogSchema({
|
|
36
|
+
requestId: S.category(), // Category: request IDs repeat within traces
|
|
37
|
+
userId: S.category(), // Category: user IDs repeat across operations
|
|
38
|
+
duration: S.number(),
|
|
39
|
+
httpStatus: S.number(),
|
|
40
|
+
operation: S.enum(['SELECT', 'INSERT', 'UPDATE', 'DELETE']), // Enum: known DB operations
|
|
41
|
+
query: S.text(), // Text: SQL queries are mostly unique
|
|
42
|
+
region: S.category(), // Category: AWS regions have limited cardinality
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Define feature flags
|
|
46
|
+
const featureFlags = defineFeatureFlags({
|
|
47
|
+
advancedValidation: S.boolean().default(false).sync(),
|
|
48
|
+
maxRetries: S.number().default(3).sync(),
|
|
49
|
+
experimentalFeature: S.boolean().default(false).async(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Environment config type
|
|
53
|
+
type EnvConfig = {
|
|
54
|
+
awsRegion: string;
|
|
55
|
+
maxConnections: number;
|
|
56
|
+
databaseUrl: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Environment config
|
|
60
|
+
const environmentConfig: EnvConfig = {
|
|
61
|
+
awsRegion: 'us-east-1',
|
|
62
|
+
maxConnections: 100,
|
|
63
|
+
databaseUrl: 'postgresql://localhost:5432/test',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Create a shared op context for tests (without feature flags)
|
|
67
|
+
const opContext = defineOpContext({
|
|
68
|
+
logSchema: dbSchema,
|
|
69
|
+
ctx: {
|
|
70
|
+
requestId: undefined as string | undefined,
|
|
71
|
+
userId: undefined as string | undefined,
|
|
72
|
+
env: undefined as EnvConfig | undefined,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const { defineOp } = opContext;
|
|
77
|
+
|
|
78
|
+
// Create an op context WITH feature flags
|
|
79
|
+
const opContextWithFlags = defineOpContext({
|
|
80
|
+
logSchema: dbSchema,
|
|
81
|
+
flags: featureFlags.schema,
|
|
82
|
+
ctx: {
|
|
83
|
+
requestId: undefined as string | undefined,
|
|
84
|
+
userId: undefined as string | undefined,
|
|
85
|
+
env: undefined as EnvConfig | undefined,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const { defineOp: defineOpWithFlags } = opContextWithFlags;
|
|
90
|
+
|
|
91
|
+
// Create a flag evaluator with test values
|
|
92
|
+
const flagEvaluator = new InMemoryFlagEvaluator(featureFlags.schema, {
|
|
93
|
+
advancedValidation: true,
|
|
94
|
+
maxRetries: 5,
|
|
95
|
+
experimentalFeature: false,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('Tracer API', () => {
|
|
99
|
+
it('should create trace context with environment via Tracer', async () => {
|
|
100
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
101
|
+
|
|
102
|
+
// Use function overload to test user context properties
|
|
103
|
+
const result = await trace(
|
|
104
|
+
'check-ctx',
|
|
105
|
+
{ requestId: 'req-123', userId: 'user-456', env: environmentConfig },
|
|
106
|
+
async (ctx) => {
|
|
107
|
+
expect(ctx.requestId).toBe('req-123');
|
|
108
|
+
expect(ctx.userId).toBe('user-456');
|
|
109
|
+
// TraceId is W3C format (32 hex chars) via generateTraceId from traceId.ts
|
|
110
|
+
expect(ctx.buffer.trace_id).toMatch(/^[a-f0-9]{32}$/);
|
|
111
|
+
expect(ctx.env).toBe(environmentConfig);
|
|
112
|
+
return { checked: true };
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
expect(result.checked).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should provide access to environment config as plain properties', async () => {
|
|
119
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
120
|
+
|
|
121
|
+
const result = await trace('check-env', { requestId: 'req-123', env: environmentConfig }, async (ctx) => {
|
|
122
|
+
expect(ctx.env?.awsRegion).toBe('us-east-1');
|
|
123
|
+
expect(ctx.env?.maxConnections).toBe(100);
|
|
124
|
+
expect(ctx.env?.databaseUrl).toBe('postgresql://localhost:5432/test');
|
|
125
|
+
return { checked: true };
|
|
126
|
+
});
|
|
127
|
+
expect(result.checked).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('defineOp', () => {
|
|
132
|
+
it('should create op that provides span context', () => {
|
|
133
|
+
const testOp = defineOp('test-task', async (ctx) => {
|
|
134
|
+
expect(ctx.log).toBeDefined();
|
|
135
|
+
expect(ctx.ok).toBeFunction();
|
|
136
|
+
expect(ctx.err).toBeFunction();
|
|
137
|
+
expect(ctx.span).toBeFunction();
|
|
138
|
+
return ctx.ok({ success: true });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(testOp).toBeDefined();
|
|
142
|
+
// Op is an object with fn method and metadata property
|
|
143
|
+
expect(testOp.metadata.package_name).toBeDefined();
|
|
144
|
+
expect(typeof testOp.fn).toBe('function');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should execute op with Tracer (destructuring pattern)', async () => {
|
|
148
|
+
const testOp = defineOp('test-task', async (ctx) => {
|
|
149
|
+
expect(ctx.log).toBeDefined();
|
|
150
|
+
expect(ctx.ok).toBeFunction();
|
|
151
|
+
expect(ctx.err).toBeFunction();
|
|
152
|
+
expect(ctx.span).toBeFunction();
|
|
153
|
+
return ctx.ok({ success: true });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
157
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
158
|
+
|
|
159
|
+
const result = await trace('test-task', testOp);
|
|
160
|
+
expect(result.success).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('Feature Flag Integration', () => {
|
|
165
|
+
it('should create trace context with feature flags', async () => {
|
|
166
|
+
const testOp = defineOpWithFlags('check-ff', async (ctx) => {
|
|
167
|
+
expect(ctx.ff).toBeDefined();
|
|
168
|
+
expect(ctx.buffer.trace_id).toMatch(/^[a-f0-9]{32}$/);
|
|
169
|
+
return ctx.ok({ checked: true });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
173
|
+
|
|
174
|
+
const result = await trace('check-ff', { requestId: 'req-123', env: environmentConfig }, testOp);
|
|
175
|
+
expect(result.success).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should access sync feature flags as properties', async () => {
|
|
179
|
+
const testOp = defineOpWithFlags('test-ff', async (ctx) => {
|
|
180
|
+
// Sync flags return FlagContext wrappers when truthy (undefined when falsy)
|
|
181
|
+
// Access .value to get the actual flag value
|
|
182
|
+
const validationFlag = ctx.ff.advancedValidation;
|
|
183
|
+
const retriesFlag = ctx.ff.maxRetries;
|
|
184
|
+
|
|
185
|
+
if (!validationFlag || !retriesFlag) {
|
|
186
|
+
throw new Error('Expected sync feature flags to be available in test fixture');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
expect(validationFlag.value).toBe(true);
|
|
190
|
+
expect(retriesFlag.value).toBe(5);
|
|
191
|
+
|
|
192
|
+
return ctx.ok({ validated: true });
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
196
|
+
|
|
197
|
+
const result = await trace('test-ff', { requestId: 'req-123', env: environmentConfig }, testOp);
|
|
198
|
+
expect(result.success).toBe(true);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should access async feature flags via get()', async () => {
|
|
202
|
+
const testOp = defineOpWithFlags('test-async-ff', async (ctx) => {
|
|
203
|
+
// Async flags use ctx.ff.get('flagName')
|
|
204
|
+
// Returns FlagContext when truthy, undefined when falsy
|
|
205
|
+
const experimentalFlag = await ctx.ff.get('experimentalFeature');
|
|
206
|
+
|
|
207
|
+
// Flag is false, so should be undefined (falsy pattern)
|
|
208
|
+
expect(experimentalFlag).toBeUndefined();
|
|
209
|
+
|
|
210
|
+
return ctx.ok({ experimental: false });
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
214
|
+
|
|
215
|
+
const result = await trace('test-async-ff', { requestId: 'req-123', env: environmentConfig }, testOp);
|
|
216
|
+
expect(result.success).toBe(true);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should track feature flag usage', async () => {
|
|
220
|
+
const testOp = defineOpWithFlags('test-ff-tracking', async (ctx) => {
|
|
221
|
+
// Access flag first
|
|
222
|
+
const validationFlag = ctx.ff.advancedValidation;
|
|
223
|
+
|
|
224
|
+
if (validationFlag) {
|
|
225
|
+
// track() creates ff-usage entries and returns fluent entry for tagging
|
|
226
|
+
validationFlag.track().operation('SELECT').duration(5);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return ctx.ok({ tracked: true });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
233
|
+
|
|
234
|
+
const result = await trace('test-ff-tracking', { requestId: 'req-123', env: environmentConfig }, testOp);
|
|
235
|
+
expect(result.success).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should use feature flags in conditional logic', async () => {
|
|
239
|
+
const testOp = defineOpWithFlags('conditional-logic', async (ctx) => {
|
|
240
|
+
// Natural truthy/falsy pattern - flag is undefined when disabled
|
|
241
|
+
if (ctx.ff.advancedValidation) {
|
|
242
|
+
ctx.log.info('Advanced validation enabled');
|
|
243
|
+
ctx.tag.operation('SELECT'); // Validation query
|
|
244
|
+
} else {
|
|
245
|
+
ctx.log.info('Basic validation only');
|
|
246
|
+
ctx.tag.operation('INSERT'); // Skip validation
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Number flags also work with truthy pattern
|
|
250
|
+
const retries = ctx.ff.maxRetries;
|
|
251
|
+
if (retries) {
|
|
252
|
+
ctx.tag.duration(retries.value * 100); // Use retry count for timeout
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return ctx.ok({ validated: !!ctx.ff.advancedValidation });
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
259
|
+
|
|
260
|
+
const result = await trace('conditional-logic', { requestId: 'req-123', env: environmentConfig }, testOp);
|
|
261
|
+
expect(result.success).toBe(true);
|
|
262
|
+
if (result.success) {
|
|
263
|
+
expect(result.value.validated).toBe(true);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('Method Chaining', () => {
|
|
269
|
+
it('should chain multiple tag methods fluently and write to buffers', async () => {
|
|
270
|
+
const testOp = defineOp('test-chaining', async (ctx) => {
|
|
271
|
+
// Each method returns the tag object for chaining
|
|
272
|
+
const result = ctx.tag
|
|
273
|
+
.requestId('req-001')
|
|
274
|
+
.userId('user-001')
|
|
275
|
+
.operation('SELECT')
|
|
276
|
+
.duration(10.5)
|
|
277
|
+
.httpStatus(200)
|
|
278
|
+
.region('us-west-2')
|
|
279
|
+
.query('SELECT * FROM users WHERE id = ?');
|
|
280
|
+
|
|
281
|
+
// Verify we can still chain after the chain
|
|
282
|
+
expect(result).toBeDefined();
|
|
283
|
+
expect(typeof result.requestId).toBe('function');
|
|
284
|
+
|
|
285
|
+
return ctx.ok({ chained: true });
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
289
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
290
|
+
|
|
291
|
+
const result = await trace('test-chaining', testOp);
|
|
292
|
+
expect(result.success).toBe(true);
|
|
293
|
+
|
|
294
|
+
// Note: Buffer writes are happening in memory to Arrow columnar format
|
|
295
|
+
// Each tag method call writes to the appropriate attribute column
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should chain with() method and continue chaining', async () => {
|
|
299
|
+
const testOp = defineOp('test-with-chaining', async (ctx) => {
|
|
300
|
+
// with() returns the tag object, allowing continued chaining
|
|
301
|
+
ctx.tag
|
|
302
|
+
.with({
|
|
303
|
+
requestId: 'req-002',
|
|
304
|
+
userId: 'user-002',
|
|
305
|
+
})
|
|
306
|
+
.operation('INSERT')
|
|
307
|
+
.duration(15.2)
|
|
308
|
+
.with({
|
|
309
|
+
httpStatus: 201,
|
|
310
|
+
region: 'eu-west-1',
|
|
311
|
+
})
|
|
312
|
+
.query('INSERT INTO users VALUES (...)');
|
|
313
|
+
|
|
314
|
+
return ctx.ok({ chained: true });
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
318
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
319
|
+
|
|
320
|
+
const result = await trace('test-with-chaining', testOp);
|
|
321
|
+
expect(result.success).toBe(true);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should support real-world chaining pattern: orderId and amount', async () => {
|
|
325
|
+
const testOp = defineOp('process-order', async (ctx, orderId: string, amount: number) => {
|
|
326
|
+
// Example from requirements: ctx.tag.orderId(order.id).amount(order.total)
|
|
327
|
+
// Using available attributes to simulate
|
|
328
|
+
ctx.tag
|
|
329
|
+
.requestId(orderId)
|
|
330
|
+
.userId(ctx.userId || 'guest')
|
|
331
|
+
.duration(amount)
|
|
332
|
+
.operation('INSERT')
|
|
333
|
+
.httpStatus(201);
|
|
334
|
+
|
|
335
|
+
return ctx.ok({ orderId, amount });
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
339
|
+
|
|
340
|
+
// Use trace_fn to wrap the op invocation with args
|
|
341
|
+
const result = await trace(
|
|
342
|
+
'process-order',
|
|
343
|
+
{ requestId: 'req-003', userId: 'user-003', env: environmentConfig },
|
|
344
|
+
async (ctx) => testOp.fn(ctx, 'order-789', 149.99),
|
|
345
|
+
);
|
|
346
|
+
expect(result.success).toBe(true);
|
|
347
|
+
if (result.success) {
|
|
348
|
+
expect(result.value.orderId).toBe('order-789');
|
|
349
|
+
expect(result.value.amount).toBe(149.99);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
describe('Op Integration', () => {
|
|
355
|
+
it('should provide typed tag attribute API with method chaining', async () => {
|
|
356
|
+
const testOp = defineOp('test-task', async (ctx) => {
|
|
357
|
+
// Method chaining - each method returns the tag object
|
|
358
|
+
ctx.tag.requestId('req-123').userId('user-456').operation('INSERT').duration(12.5).httpStatus(200);
|
|
359
|
+
|
|
360
|
+
// Can also chain after with()
|
|
361
|
+
ctx.tag
|
|
362
|
+
.with({
|
|
363
|
+
requestId: 'req-456',
|
|
364
|
+
userId: 'user-789',
|
|
365
|
+
})
|
|
366
|
+
.operation('SELECT')
|
|
367
|
+
.duration(8.3);
|
|
368
|
+
|
|
369
|
+
// Single calls still work
|
|
370
|
+
ctx.tag.httpStatus(201);
|
|
371
|
+
|
|
372
|
+
return ctx.ok({ success: true });
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
376
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
377
|
+
|
|
378
|
+
const result = await trace('test-task', testOp);
|
|
379
|
+
expect(result.success).toBe(true);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should provide message logging methods', async () => {
|
|
383
|
+
const testOp = defineOp('test-task', async (ctx) => {
|
|
384
|
+
ctx.log.info('Info message');
|
|
385
|
+
ctx.log.debug('Debug message');
|
|
386
|
+
ctx.log.warn('Warning message');
|
|
387
|
+
ctx.log.error('Error message');
|
|
388
|
+
// Note: ctx.log.message() was removed - use level-specific methods instead
|
|
389
|
+
ctx.log.info('Custom message');
|
|
390
|
+
|
|
391
|
+
return ctx.ok({ success: true });
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
395
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
396
|
+
|
|
397
|
+
const result = await trace('test-task', testOp);
|
|
398
|
+
expect(result.success).toBe(true);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should provide ok/err result helpers', async () => {
|
|
402
|
+
const successOp = defineOp('success-task', async (ctx) => {
|
|
403
|
+
return ctx.ok({ data: 'result' });
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const errorOp = defineOp('error-task', async (ctx) => {
|
|
407
|
+
return ctx.err(VALIDATION_ERROR({ field: 'email' }));
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
411
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
412
|
+
|
|
413
|
+
const successResult = await trace('success-task', successOp);
|
|
414
|
+
expect(successResult.success).toBe(true);
|
|
415
|
+
if (successResult.success) {
|
|
416
|
+
expect(successResult.value).toEqual({ data: 'result' });
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const errorResult = await trace('error-task', errorOp);
|
|
420
|
+
expect(errorResult.success).toBe(false);
|
|
421
|
+
if (!errorResult.success) {
|
|
422
|
+
expect(errorResult.error.code).toBe('VALIDATION_ERROR');
|
|
423
|
+
expect(errorResult.error.field).toBe('email');
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('should support child spans with chained tag methods', async () => {
|
|
428
|
+
const testOp = defineOp('parent-task', async (ctx) => {
|
|
429
|
+
// Parent span with chained tags
|
|
430
|
+
ctx.tag.requestId('req-123').operation('INSERT').duration(50.0);
|
|
431
|
+
|
|
432
|
+
const childResult = await ctx.span('child-task', async (childCtx) => {
|
|
433
|
+
// Child span with chained tags - tag is on childCtx directly, not on childCtx.log
|
|
434
|
+
childCtx.tag.operation('SELECT').query('SELECT * FROM users').duration(5.2).httpStatus(200);
|
|
435
|
+
|
|
436
|
+
return childCtx.ok({ found: true });
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
expect(childResult.success).toBe(true);
|
|
440
|
+
if (childResult.success) {
|
|
441
|
+
expect(childResult.value.found).toBe(true);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return ctx.ok({ success: true });
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// ✅ CORRECT PATTERN - Destructure trace from Tracer
|
|
448
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
449
|
+
|
|
450
|
+
const result = await trace('parent-task', testOp);
|
|
451
|
+
expect(result.success).toBe(true);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
describe('Method Chaining Examples', () => {
|
|
456
|
+
it('should support various chaining patterns', async () => {
|
|
457
|
+
const processOrder = defineOp('process-order', async (ctx, orderId: string, _amount: number) => {
|
|
458
|
+
// Example from requirements: ctx.tag.orderId(order.id).amount(order.total)
|
|
459
|
+
ctx.tag
|
|
460
|
+
.requestId(ctx.requestId || 'unknown')
|
|
461
|
+
.userId(ctx.userId || 'anonymous')
|
|
462
|
+
.operation('INSERT');
|
|
463
|
+
|
|
464
|
+
// Chaining with with()
|
|
465
|
+
ctx.tag.with({ region: 'us-east-1', httpStatus: 200 }).duration(25.5).query('INSERT INTO orders VALUES (...)');
|
|
466
|
+
|
|
467
|
+
return ctx.ok({ orderId, processed: true });
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
471
|
+
|
|
472
|
+
const result = await trace(
|
|
473
|
+
'process-order',
|
|
474
|
+
{ requestId: 'req-999', userId: 'user-123', env: environmentConfig },
|
|
475
|
+
async (ctx) => processOrder.fn(ctx, 'order-456', 99.99),
|
|
476
|
+
);
|
|
477
|
+
expect(result.success).toBe(true);
|
|
478
|
+
if (result.success) {
|
|
479
|
+
expect(result.value.orderId).toBe('order-456');
|
|
480
|
+
expect(result.value.processed).toBe(true);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('should demonstrate complete integration with chaining and feature flags', async () => {
|
|
485
|
+
// Define op with extensive chaining and feature flag usage
|
|
486
|
+
const createUser = defineOpWithFlags('create-user', async (ctx, userData: { email: string; name: string }) => {
|
|
487
|
+
// Feature flag conditional - natural truthy pattern
|
|
488
|
+
if (ctx.ff.advancedValidation) {
|
|
489
|
+
ctx.log.info('Using advanced validation');
|
|
490
|
+
ctx.ff.advancedValidation.track();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Environment access and chained tags
|
|
494
|
+
ctx.tag
|
|
495
|
+
.requestId(ctx.requestId || 'unknown')
|
|
496
|
+
.userId(userData.email)
|
|
497
|
+
.region((ctx.env?.awsRegion ?? 'unknown') as string)
|
|
498
|
+
.operation('INSERT');
|
|
499
|
+
|
|
500
|
+
// Child span with chaining - tag is on childCtx directly, not on childCtx.log
|
|
501
|
+
const validation = await ctx.span('validate-user', async (childCtx) => {
|
|
502
|
+
childCtx.tag
|
|
503
|
+
.operation('SELECT')
|
|
504
|
+
.query('SELECT COUNT(*) FROM users WHERE email = ?')
|
|
505
|
+
.duration(12.5)
|
|
506
|
+
.httpStatus(200);
|
|
507
|
+
|
|
508
|
+
// Simulate validation
|
|
509
|
+
const existingUser = false;
|
|
510
|
+
|
|
511
|
+
if (existingUser) {
|
|
512
|
+
return childCtx.err(USER_EXISTS({ email: userData.email }));
|
|
513
|
+
}
|
|
514
|
+
return childCtx.ok({ valid: true });
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
if (!validation.success) {
|
|
518
|
+
return ctx.err(VALIDATION_FAILED({ error: validation.error }));
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Complete operation with chained tags
|
|
522
|
+
ctx.tag.duration(50.3).httpStatus(201);
|
|
523
|
+
|
|
524
|
+
return ctx.ok({ id: 'user-123', ...userData });
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const { trace } = new TestTracer(opContextWithFlags, { ...createTestTracerOptions(), flagEvaluator });
|
|
528
|
+
|
|
529
|
+
const result = await trace(
|
|
530
|
+
'create-user',
|
|
531
|
+
{ requestId: 'req-123', userId: 'user-456', env: environmentConfig },
|
|
532
|
+
async (ctx) =>
|
|
533
|
+
createUser.fn(ctx, {
|
|
534
|
+
email: 'test@example.com',
|
|
535
|
+
name: 'Test User',
|
|
536
|
+
}),
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
expect(result.success).toBe(true);
|
|
540
|
+
if (result.success) {
|
|
541
|
+
expect(result.value.id).toBe('user-123');
|
|
542
|
+
expect(result.value.email).toBe('test@example.com');
|
|
543
|
+
expect(result.value.name).toBe('Test User');
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
describe('Prototype-based Context Inheritance', () => {
|
|
549
|
+
it('should preserve user properties in parent spans', async () => {
|
|
550
|
+
let parentRequestId: string | undefined;
|
|
551
|
+
let parentUserId: string | undefined;
|
|
552
|
+
|
|
553
|
+
const testOp = defineOp('parent-task', async (ctx) => {
|
|
554
|
+
// Capture parent context properties
|
|
555
|
+
parentRequestId = ctx.requestId;
|
|
556
|
+
parentUserId = ctx.userId;
|
|
557
|
+
|
|
558
|
+
await ctx.span('child-task', async (childCtx) => {
|
|
559
|
+
return childCtx.ok({ done: true });
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
return ctx.ok({ success: true });
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
566
|
+
|
|
567
|
+
await trace(
|
|
568
|
+
'parent-task',
|
|
569
|
+
{ requestId: 'req-inherit-test', userId: 'user-inherit-test', env: environmentConfig },
|
|
570
|
+
testOp,
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
// Verify properties are available in parent span
|
|
574
|
+
expect(parentRequestId).toBe('req-inherit-test');
|
|
575
|
+
expect(parentUserId).toBe('user-inherit-test');
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it('should preserve env config in parent and child spans', async () => {
|
|
579
|
+
let parentEnv: EnvConfig | undefined;
|
|
580
|
+
|
|
581
|
+
const testOp = defineOp('parent-task', async (ctx) => {
|
|
582
|
+
parentEnv = ctx.env;
|
|
583
|
+
|
|
584
|
+
await ctx.span('child-task', async (childCtx) => {
|
|
585
|
+
return childCtx.ok({ done: true });
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
return ctx.ok({ success: true });
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
const { trace } = new TestTracer(opContext, { ...createTestTracerOptions() });
|
|
592
|
+
|
|
593
|
+
await trace('parent-task', { requestId: 'req-env-test', env: environmentConfig }, testOp);
|
|
594
|
+
|
|
595
|
+
// Verify env is same object reference (not copied)
|
|
596
|
+
expect(parentEnv).toBe(environmentConfig);
|
|
597
|
+
expect(parentEnv?.awsRegion).toBe('us-east-1');
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
});
|