@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,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpGroup Creation - Class-based architecture for Phase 2
|
|
3
|
+
*
|
|
4
|
+
* Creates OpGroups as class instances with ops as own properties.
|
|
5
|
+
* Enables V8 hidden class optimization and cleaner API (`.opName` not `.ops.opName`).
|
|
6
|
+
*
|
|
7
|
+
* Why class-based:
|
|
8
|
+
* - Private fields (#columnMapping) don't affect hidden class (truly hidden, no enumeration)
|
|
9
|
+
* - Ops as own properties enable direct access and predictable object shape
|
|
10
|
+
* - prefix()/mapColumns() create new instances with same SpanBufferClass (shared stats)
|
|
11
|
+
* - Only remappedViewClass differs between original and prefixed op instances
|
|
12
|
+
*
|
|
13
|
+
* Internal properties (_logSchema, _flags, etc.) are prefixed with underscore to avoid
|
|
14
|
+
* collision with user-defined op names. Public interfaces hide these from intellisense.
|
|
15
|
+
*
|
|
16
|
+
* @module opContext/createOpGroup
|
|
17
|
+
*/
|
|
18
|
+
import { generateRemappedBufferViewClass } from '../library.js';
|
|
19
|
+
import { Op } from '../op.js';
|
|
20
|
+
import { SYSTEM_SCHEMA_FIELD_NAMES } from '../schema/systemSchema.js';
|
|
21
|
+
import { validateOpName } from './opGroupTypes.js';
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// INTERNAL HELPERS
|
|
24
|
+
// =============================================================================
|
|
25
|
+
function getSchemaFields(fieldsSchema) {
|
|
26
|
+
return fieldsSchema.fields;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create reverse mapping for RemappedBufferView.
|
|
30
|
+
* Input: clean -> prefixed mapping (e.g., { status: 'http_status' })
|
|
31
|
+
* Output: prefixed -> clean mapping (e.g., { http_status: 'status' })
|
|
32
|
+
*
|
|
33
|
+
* Why reverse: RemappedBufferView wraps child buffer at registration time.
|
|
34
|
+
* Arrow conversion asks for 'http_status', view needs to find 'status' in raw buffer.
|
|
35
|
+
*/
|
|
36
|
+
function createReverseMapping(mapping) {
|
|
37
|
+
const reverse = {};
|
|
38
|
+
for (const [cleanName, prefixedName] of Object.entries(mapping)) {
|
|
39
|
+
if (typeof prefixedName === 'string') {
|
|
40
|
+
reverse[prefixedName] = cleanName;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return reverse;
|
|
44
|
+
}
|
|
45
|
+
function isOpInstance(value) {
|
|
46
|
+
return value instanceof Op;
|
|
47
|
+
}
|
|
48
|
+
function copyOpsWithView(source, target, remappedViewClass) {
|
|
49
|
+
for (const [key, value] of Object.entries(source)) {
|
|
50
|
+
if (isOpInstance(value)) {
|
|
51
|
+
target[key] = new Op(value.metadata, value.SpanBufferClass, value.fn, remappedViewClass, value._opContextBinding);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function assertGroupCarriesOps(group, ops) {
|
|
56
|
+
for (const name of Object.keys(ops)) {
|
|
57
|
+
if (!isOpInstance(group[name])) {
|
|
58
|
+
throw new TypeError(`Expected OpGroup to expose op '${name}' as an Op instance`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function cloneOpsWithView(source, remappedViewClass) {
|
|
63
|
+
const cloned = {};
|
|
64
|
+
copyOpsWithView(source, cloned, remappedViewClass);
|
|
65
|
+
assertGroupCarriesOps(cloned, source);
|
|
66
|
+
return cloned;
|
|
67
|
+
}
|
|
68
|
+
function prefixContributedSchema(fields, prefix) {
|
|
69
|
+
const result = {};
|
|
70
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
71
|
+
result[`${prefix}_${key}`] = value;
|
|
72
|
+
}
|
|
73
|
+
assertMappedSchema(result);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function assertMappedSchema(value) {
|
|
77
|
+
for (const schema of Object.values(value)) {
|
|
78
|
+
if (typeof schema !== 'object' || schema === null) {
|
|
79
|
+
throw new TypeError('Mapped schema must contain schema metadata objects');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build a prefix mapping for all schema fields
|
|
85
|
+
*
|
|
86
|
+
* Why prefix all fields: Ensures no column name collisions when wiring multiple libraries.
|
|
87
|
+
* Each library's columns become `${prefix}_${field}` in app schema.
|
|
88
|
+
*
|
|
89
|
+
* @param fieldNames - The field names from the schema
|
|
90
|
+
* @param prefix - The prefix to apply
|
|
91
|
+
* @returns Column mapping where each field becomes `${prefix}_${field}`
|
|
92
|
+
*/
|
|
93
|
+
function buildPrefixMapping(fieldNames, prefix) {
|
|
94
|
+
const mapping = {};
|
|
95
|
+
for (const name of fieldNames) {
|
|
96
|
+
// Skip system columns - they should NOT be prefixed
|
|
97
|
+
if (SYSTEM_SCHEMA_FIELD_NAMES.has(name))
|
|
98
|
+
continue;
|
|
99
|
+
mapping[name] = `${prefix}_${name}`;
|
|
100
|
+
}
|
|
101
|
+
return mapping;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Apply a prefix to an existing mapping
|
|
105
|
+
*
|
|
106
|
+
* For each entry in the mapping:
|
|
107
|
+
* - If mapped to a string, prefix that string: 'status' -> 'http_status'
|
|
108
|
+
* - If mapped to null (dropped), keep as null
|
|
109
|
+
*
|
|
110
|
+
* Why: Enables chaining `.prefix('http').prefix('api')` to build composite prefixes.
|
|
111
|
+
*
|
|
112
|
+
* @param mapping - Existing column mapping
|
|
113
|
+
* @param prefix - Prefix to apply
|
|
114
|
+
* @returns New mapping with prefixed target names
|
|
115
|
+
*/
|
|
116
|
+
function prefixMapping(mapping, prefix) {
|
|
117
|
+
const result = {};
|
|
118
|
+
for (const [key, value] of Object.entries(mapping)) {
|
|
119
|
+
if (value === null) {
|
|
120
|
+
result[key] = null;
|
|
121
|
+
}
|
|
122
|
+
else if (typeof value === 'string') {
|
|
123
|
+
result[key] = `${prefix}_${value}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build the contributed schema object from the original schema and mapping
|
|
130
|
+
*
|
|
131
|
+
* The contributed schema reflects what columns this group adds to the app's schema
|
|
132
|
+
* after mapping is applied.
|
|
133
|
+
*
|
|
134
|
+
* Why track contributed schema: Type system needs to know what columns are available
|
|
135
|
+
* after prefix/mapping transformations for compile-time safety.
|
|
136
|
+
*
|
|
137
|
+
* @param fields - Original schema fields
|
|
138
|
+
* @param mapping - Column mapping
|
|
139
|
+
* @returns The contributed schema with renamed keys
|
|
140
|
+
*/
|
|
141
|
+
function buildContributedSchema(fields, mapping) {
|
|
142
|
+
const result = {};
|
|
143
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
144
|
+
const mappedName = mapping[key];
|
|
145
|
+
if (mappedName === null) {
|
|
146
|
+
// Dropped column - not included in contributed schema
|
|
147
|
+
}
|
|
148
|
+
else if (typeof mappedName === 'string') {
|
|
149
|
+
// Explicitly mapped - use the mapped name
|
|
150
|
+
result[mappedName] = value;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Not in mapping - keep original name
|
|
154
|
+
result[key] = value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
assertMappedSchema(result);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validate all op names in a record.
|
|
162
|
+
* Throws if any name starts with underscore or is a reserved name.
|
|
163
|
+
*/
|
|
164
|
+
function validateAllOpNames(ops) {
|
|
165
|
+
for (const name of Object.keys(ops)) {
|
|
166
|
+
validateOpName(name);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// =============================================================================
|
|
170
|
+
// OP GROUP CLASS - Phase 2 Architecture
|
|
171
|
+
// =============================================================================
|
|
172
|
+
/**
|
|
173
|
+
* OpGroup class - Holds ops as own properties with private field for mapping state.
|
|
174
|
+
*
|
|
175
|
+
* Why class-based:
|
|
176
|
+
* 1. Private fields don't pollute object shape (no hidden class impact)
|
|
177
|
+
* 2. Ops spread as own properties for direct access (`.request` not `.ops.request`)
|
|
178
|
+
* 3. Prototype methods (prefix/mapColumns) shared across instances
|
|
179
|
+
* 4. Same SpanBufferClass preserved across prefix() calls (shared schema + stats)
|
|
180
|
+
* 5. Only remappedViewClass differs between original and prefixed ops
|
|
181
|
+
*
|
|
182
|
+
* Structure enables V8 optimization:
|
|
183
|
+
* - All OpGroup instances with same ops have same hidden class
|
|
184
|
+
* - Private fields invisible to property enumeration
|
|
185
|
+
* - Method dispatch via prototype (no per-instance copies)
|
|
186
|
+
*
|
|
187
|
+
* Internal properties use underscore prefix (_logSchema, _flags) to avoid
|
|
188
|
+
* collision with user-defined op names.
|
|
189
|
+
*/
|
|
190
|
+
class OpGroupImpl {
|
|
191
|
+
_logSchema;
|
|
192
|
+
_flags;
|
|
193
|
+
// Private field - truly hidden, doesn't affect hidden class or enumeration
|
|
194
|
+
#columnMapping;
|
|
195
|
+
#ops;
|
|
196
|
+
constructor(_logSchema, _flags, ops, columnMapping) {
|
|
197
|
+
this._logSchema = _logSchema;
|
|
198
|
+
this._flags = _flags;
|
|
199
|
+
this.#columnMapping = columnMapping ?? {};
|
|
200
|
+
this.#ops = ops;
|
|
201
|
+
// Validate op names before spreading
|
|
202
|
+
validateAllOpNames(ops);
|
|
203
|
+
// Spread ops onto this instance as own properties
|
|
204
|
+
// Why spread: Enables direct access (ctx.deps.http.request)
|
|
205
|
+
for (const [name, op] of Object.entries(ops)) {
|
|
206
|
+
this[name] = op;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
prefix(p) {
|
|
210
|
+
// Apply prefix to the current mapping
|
|
211
|
+
// Check if mapping is non-empty (empty object {} is truthy but has no entries)
|
|
212
|
+
const hasMapping = this.#columnMapping && Object.keys(this.#columnMapping).length > 0;
|
|
213
|
+
const newMapping = hasMapping
|
|
214
|
+
? prefixMapping(this.#columnMapping, p)
|
|
215
|
+
: buildPrefixMapping(this._logSchema._columnNames, p);
|
|
216
|
+
// Generate RemappedBufferView for this prefix
|
|
217
|
+
// Why reverse mapping: Arrow conversion asks for 'http_status', needs to find 'status'
|
|
218
|
+
const reverseMapping = createReverseMapping(newMapping);
|
|
219
|
+
const remappedViewClass = generateRemappedBufferViewClass(reverseMapping);
|
|
220
|
+
// Create new OpGroup with prefixed ops
|
|
221
|
+
const newGroup = new MappedOpGroupImpl(this._logSchema, this._flags, cloneOpsWithView(this.#ops, remappedViewClass), newMapping, prefixContributedSchema(getSchemaFields(this._logSchema), p));
|
|
222
|
+
assertGroupCarriesOps(newGroup, this.#ops);
|
|
223
|
+
return newGroup;
|
|
224
|
+
}
|
|
225
|
+
mapColumns(mapping) {
|
|
226
|
+
// Override/extend the existing mapping with new mapping
|
|
227
|
+
const newMapping = { ...this.#columnMapping, ...mapping };
|
|
228
|
+
// Generate RemappedBufferView for this mapping
|
|
229
|
+
const reverseMapping = createReverseMapping(newMapping);
|
|
230
|
+
const remappedViewClass = generateRemappedBufferViewClass(reverseMapping);
|
|
231
|
+
// Build contributed schema from original fields with new mapping
|
|
232
|
+
const newContributed = buildContributedSchema(getSchemaFields(this._logSchema), newMapping);
|
|
233
|
+
// Create new OpGroup with mapped ops
|
|
234
|
+
const newGroup = new MappedOpGroupImpl(this._logSchema, this._flags, cloneOpsWithView(this.#ops, remappedViewClass), newMapping, newContributed);
|
|
235
|
+
assertGroupCarriesOps(newGroup, this.#ops);
|
|
236
|
+
return newGroup;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// =============================================================================
|
|
240
|
+
// MAPPED OP GROUP CLASS
|
|
241
|
+
// =============================================================================
|
|
242
|
+
/**
|
|
243
|
+
* MappedOpGroup class - OpGroup with column mapping applied.
|
|
244
|
+
*
|
|
245
|
+
* Why separate class: TypeScript needs distinct type for mapped groups
|
|
246
|
+
* to track contributedSchema type parameter.
|
|
247
|
+
*
|
|
248
|
+
* Internal properties use underscore prefix to avoid collision with op names.
|
|
249
|
+
*/
|
|
250
|
+
class MappedOpGroupImpl {
|
|
251
|
+
_logSchema;
|
|
252
|
+
_flags;
|
|
253
|
+
_columnMapping;
|
|
254
|
+
_contributedSchema;
|
|
255
|
+
#columnMapping;
|
|
256
|
+
#ops;
|
|
257
|
+
constructor(_logSchema, _flags, ops, _columnMapping, _contributedSchema) {
|
|
258
|
+
this._logSchema = _logSchema;
|
|
259
|
+
this._flags = _flags;
|
|
260
|
+
this._columnMapping = _columnMapping;
|
|
261
|
+
this._contributedSchema = _contributedSchema;
|
|
262
|
+
this.#columnMapping = _columnMapping;
|
|
263
|
+
this.#ops = ops;
|
|
264
|
+
// Validate op names before spreading
|
|
265
|
+
validateAllOpNames(ops);
|
|
266
|
+
// Spread ops onto this instance
|
|
267
|
+
for (const [name, op] of Object.entries(ops)) {
|
|
268
|
+
this[name] = op;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
prefix(p) {
|
|
272
|
+
// Apply prefix to the current mapping's target names
|
|
273
|
+
const newMapping = prefixMapping(this.#columnMapping, p);
|
|
274
|
+
// Generate RemappedBufferView
|
|
275
|
+
const reverseMapping = createReverseMapping(newMapping);
|
|
276
|
+
const remappedViewClass = generateRemappedBufferViewClass(reverseMapping);
|
|
277
|
+
// Build new contributed schema by prefixing current contributed schema
|
|
278
|
+
const newContributed = prefixContributedSchema(this._contributedSchema, p);
|
|
279
|
+
// Create new MappedOpGroup
|
|
280
|
+
const newGroup = new MappedOpGroupImpl(this._logSchema, this._flags, cloneOpsWithView(this.#ops, remappedViewClass), newMapping, newContributed);
|
|
281
|
+
assertGroupCarriesOps(newGroup, this.#ops);
|
|
282
|
+
return newGroup;
|
|
283
|
+
}
|
|
284
|
+
mapColumns(mapping) {
|
|
285
|
+
// Override/extend the existing mapping
|
|
286
|
+
const newMapping = { ...this.#columnMapping, ...mapping };
|
|
287
|
+
// Generate RemappedBufferView
|
|
288
|
+
const reverseMapping = createReverseMapping(newMapping);
|
|
289
|
+
const remappedViewClass = generateRemappedBufferViewClass(reverseMapping);
|
|
290
|
+
// Build contributed schema from current contributed fields so chained maps stay typed to the public surface.
|
|
291
|
+
const newContributed = buildContributedSchema(this._contributedSchema, mapping);
|
|
292
|
+
// Create new MappedOpGroup
|
|
293
|
+
const newGroup = new MappedOpGroupImpl(this._logSchema, this._flags, cloneOpsWithView(this.#ops, remappedViewClass), newMapping, newContributed);
|
|
294
|
+
assertGroupCarriesOps(newGroup, this.#ops);
|
|
295
|
+
return newGroup;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// =============================================================================
|
|
299
|
+
// OP GROUP CREATION
|
|
300
|
+
// =============================================================================
|
|
301
|
+
/**
|
|
302
|
+
* Create an OpGroup from a schema, flags, and ops
|
|
303
|
+
*
|
|
304
|
+
* Why class-based: V8 hidden class optimization - all OpGroups with same ops
|
|
305
|
+
* have same object shape (private fields don't affect hidden class).
|
|
306
|
+
*
|
|
307
|
+
* The ops passed to this function already have a SpanBufferClass attached.
|
|
308
|
+
* All ops in the same context share the SAME SpanBufferClass instance, which carries:
|
|
309
|
+
* - Static schema property (shared by all instances)
|
|
310
|
+
* - Static stats property (shared mutable stats for self-tuning)
|
|
311
|
+
*
|
|
312
|
+
* The returned OpGroup can be:
|
|
313
|
+
* - Used directly as a dependency (ops accessible via ctx.deps.name.opName)
|
|
314
|
+
* - Prefixed with `.prefix('http')` to namespace all columns
|
|
315
|
+
* - Mapped with `.mapColumns({ query: 'query', _internal: null })` for fine control
|
|
316
|
+
*
|
|
317
|
+
* @param logSchema - The LogSchema defining columns for this group's ops
|
|
318
|
+
* @param flags - Feature flag schema
|
|
319
|
+
* @param ops - Record of Op instances belonging to this group
|
|
320
|
+
* @returns OpGroup with prefix() and mapColumns() methods, ops as own properties
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const httpOps = createOpGroup(httpLogSchema, httpFlags, {
|
|
325
|
+
* fetch: fetchOp,
|
|
326
|
+
* post: postOp,
|
|
327
|
+
* });
|
|
328
|
+
*
|
|
329
|
+
* // Direct access (Phase 2):
|
|
330
|
+
* await ctx.deps.http.fetch(url);
|
|
331
|
+
*
|
|
332
|
+
* // Wire with prefix:
|
|
333
|
+
* deps: { http: httpOps.prefix('http') }
|
|
334
|
+
* // Columns become: http_status, http_url, http_duration, etc.
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
export function createOpGroup(logSchema, flags, ops) {
|
|
338
|
+
const group = new OpGroupImpl(logSchema, flags, ops);
|
|
339
|
+
assertGroupCarriesOps(group, ops);
|
|
340
|
+
return group;
|
|
341
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Op Definition Functions
|
|
3
|
+
*
|
|
4
|
+
* Factory functions for defining Ops and OpGroups. These are used internally
|
|
5
|
+
* by OpContextFactory to create type-safe Op definitions.
|
|
6
|
+
*
|
|
7
|
+
* @module opContext/defineOp
|
|
8
|
+
*/
|
|
9
|
+
import type { OpGroup, OpGroupOps } from './opGroupTypes.js';
|
|
10
|
+
import type { Op, OpFn, OpMetadata, OpsFromRecord } from './opTypes.js';
|
|
11
|
+
import type { OpContext } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create OpMetadata with pre-encoded entries for Arrow dictionary building.
|
|
14
|
+
* Uses global interner to deduplicate UTF-8 bytes across all Ops with same strings.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createOpMetadata(name: string, package_name: string, package_file: string, git_sha: string, line: number): OpMetadata;
|
|
17
|
+
/**
|
|
18
|
+
* Default metadata values for Ops when not injected by transformer.
|
|
19
|
+
* These are placeholder values that will be replaced at compile time.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_METADATA: OpMetadata;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts metadata from stack trace when transformer is not installed.
|
|
24
|
+
* Provides useful debugging info (file path, line number) even without build-time injection.
|
|
25
|
+
*
|
|
26
|
+
* Stack frame format varies by runtime:
|
|
27
|
+
* - V8 (Node/Chrome): " at functionName (file:///path/to/file.ts:10:5)"
|
|
28
|
+
* - V8 anonymous: " at file:///path/to/file.ts:10:5"
|
|
29
|
+
* - JSC (Safari): "functionName@file:///path/to/file.ts:10:5"
|
|
30
|
+
*
|
|
31
|
+
* @param skipFrames - Number of stack frames to skip (to get caller's location)
|
|
32
|
+
* @returns OpMetadata with extracted file path and line number
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractMetadataFromStack(skipFrames?: number): OpMetadata;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration using OpContext bundle.
|
|
37
|
+
* Simplifies factory config by carrying all context types in one parameter.
|
|
38
|
+
*/
|
|
39
|
+
interface DefineOpFactoryConfig<Ctx extends OpContext> {
|
|
40
|
+
readonly logSchema: Ctx['logSchema'];
|
|
41
|
+
readonly flags: Ctx['flags'];
|
|
42
|
+
/** WHY: threaded to Op._opContextBinding so downstream can extract schema */
|
|
43
|
+
readonly opContextBinding?: import('./types.js').OpContextBinding;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Factory function type for creating OpGroups.
|
|
47
|
+
* Used by createDefineOps to delegate OpGroup creation.
|
|
48
|
+
*/
|
|
49
|
+
type CreateOpGroupFn<Ctx extends OpContext> = <Ops extends OpGroupOps<Ctx>>(logSchema: Ctx['logSchema'], flags: Ctx['flags'], ops: Ops) => OpGroup<Ctx, Ops>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a defineOp function bound to a specific factory config.
|
|
52
|
+
*
|
|
53
|
+
* The returned function creates Op objects with:
|
|
54
|
+
* - metadata: includes name + merged with defaults
|
|
55
|
+
* - SpanBufferClass: from getSpanBufferClass(logSchema) - has static schema + stats
|
|
56
|
+
* - fn(ctx, ...args): the user function to execute
|
|
57
|
+
* - remappedViewClass: undefined for original ops (set by .prefix() method)
|
|
58
|
+
*
|
|
59
|
+
* @template Ctx - Bundled OpContext (logSchema, flags, deps, userCtx)
|
|
60
|
+
* @param factoryConfig - Configuration containing logSchema and flags
|
|
61
|
+
* @returns A defineOp function for creating Op instances
|
|
62
|
+
*/
|
|
63
|
+
export declare function createDefineOp<Ctx extends OpContext>(factoryConfig: DefineOpFactoryConfig<Ctx>): <Args extends unknown[], S, E>(name: string, fn: OpFn<Ctx, Args, S, E>, metadata?: Partial<OpMetadata>) => Op<Ctx, Args, S, E>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a defineOps function bound to a specific factory config.
|
|
66
|
+
*
|
|
67
|
+
* The returned function:
|
|
68
|
+
* - Iterates over Object.entries(definitions)
|
|
69
|
+
* - For each [name, def]:
|
|
70
|
+
* - If def is an Op instance, use it as-is
|
|
71
|
+
* - Else wrap with defineOpImpl(name, def)
|
|
72
|
+
* - Stores all ops in a record
|
|
73
|
+
* - Creates OpGroup using createOpGroup(logSchema, flags, ops)
|
|
74
|
+
* - Returns Object.assign(opGroup, ops) to get both OpGroup methods and individual ops
|
|
75
|
+
*
|
|
76
|
+
* @template Ctx - Bundled OpContext (logSchema, flags, deps, userCtx)
|
|
77
|
+
* @param factoryConfig - Configuration containing logSchema and flags
|
|
78
|
+
* @param createOpGroup - Factory function for creating OpGroups
|
|
79
|
+
* @returns A defineOps function for creating OpGroups
|
|
80
|
+
*/
|
|
81
|
+
export declare function createDefineOps<Ctx extends OpContext>(factoryConfig: DefineOpFactoryConfig<Ctx>, createOpGroup: CreateOpGroupFn<Ctx>): <Defs extends Record<string, Op<Ctx, unknown[], unknown, unknown> | OpFn<Ctx, unknown[], unknown, unknown>>>(definitions: Defs & ThisType<OpsFromRecord<Ctx, Defs>>) => OpGroup<Ctx, OpsFromRecord<Ctx, Defs>>;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=defineOp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineOp.d.ts","sourceRoot":"","sources":["../../../src/lib/opContext/defineOp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAM5C;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACX,UAAU,CAYZ;AAMD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,UAA4E,CAAC;AAM5G;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,SAAI,GAAG,UAAU,CA6DnE;AAMD;;;GAGG;AACH,UAAU,qBAAqB,CAAC,GAAG,SAAS,SAAS;IACnD,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,YAAY,EAAE,gBAAgB,CAAC;CACnE;AAED;;;GAGG;AACH,KAAK,eAAe,CAAC,GAAG,SAAS,SAAS,IAAI,CAAC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EACxE,SAAS,EAAE,GAAG,CAAC,WAAW,CAAC,EAC3B,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EACnB,GAAG,EAAE,GAAG,KACL,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAMvB;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,GAAG,SAAS,SAAS,EAClD,aAAa,EAAE,qBAAqB,CAAC,GAAG,CAAC,GACxC,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,KAC3B,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CA0BvB;AAyBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,GAAG,SAAS,SAAS,EACnD,aAAa,EAAE,qBAAqB,CAAC,GAAG,CAAC,EACzC,aAAa,EAAE,eAAe,CAAC,GAAG,CAAC,GAClC,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,EAC5G,WAAW,EAAE,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KACnD,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CA0B1C"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Op Definition Functions
|
|
3
|
+
*
|
|
4
|
+
* Factory functions for defining Ops and OpGroups. These are used internally
|
|
5
|
+
* by OpContextFactory to create type-safe Op definitions.
|
|
6
|
+
*
|
|
7
|
+
* @module opContext/defineOp
|
|
8
|
+
*/
|
|
9
|
+
import { intern, PreEncodedEntry } from '@smoothbricks/arrow-builder';
|
|
10
|
+
import { Op as OpClass } from '../op.js';
|
|
11
|
+
import { getSpanBufferClass } from '../spanBuffer.js';
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// METADATA HELPERS
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Create OpMetadata with pre-encoded entries for Arrow dictionary building.
|
|
17
|
+
* Uses global interner to deduplicate UTF-8 bytes across all Ops with same strings.
|
|
18
|
+
*/
|
|
19
|
+
export function createOpMetadata(name, package_name, package_file, git_sha, line) {
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
package_name,
|
|
23
|
+
package_file,
|
|
24
|
+
git_sha,
|
|
25
|
+
line,
|
|
26
|
+
// Use global interner for deduplication - same package_name across Ops shares UTF-8 bytes
|
|
27
|
+
package_name_entry: new PreEncodedEntry(package_name, intern(package_name)),
|
|
28
|
+
package_file_entry: new PreEncodedEntry(package_file, intern(package_file)),
|
|
29
|
+
git_sha_entry: new PreEncodedEntry(git_sha, intern(git_sha)),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// DEFAULT METADATA
|
|
34
|
+
// =============================================================================
|
|
35
|
+
/**
|
|
36
|
+
* Default metadata values for Ops when not injected by transformer.
|
|
37
|
+
* These are placeholder values that will be replaced at compile time.
|
|
38
|
+
*/
|
|
39
|
+
export const DEFAULT_METADATA = createOpMetadata('unknown', 'unknown', 'unknown', 'unknown', 0);
|
|
40
|
+
// =============================================================================
|
|
41
|
+
// STACK TRACE METADATA EXTRACTION
|
|
42
|
+
// =============================================================================
|
|
43
|
+
/**
|
|
44
|
+
* Extracts metadata from stack trace when transformer is not installed.
|
|
45
|
+
* Provides useful debugging info (file path, line number) even without build-time injection.
|
|
46
|
+
*
|
|
47
|
+
* Stack frame format varies by runtime:
|
|
48
|
+
* - V8 (Node/Chrome): " at functionName (file:///path/to/file.ts:10:5)"
|
|
49
|
+
* - V8 anonymous: " at file:///path/to/file.ts:10:5"
|
|
50
|
+
* - JSC (Safari): "functionName@file:///path/to/file.ts:10:5"
|
|
51
|
+
*
|
|
52
|
+
* @param skipFrames - Number of stack frames to skip (to get caller's location)
|
|
53
|
+
* @returns OpMetadata with extracted file path and line number
|
|
54
|
+
*/
|
|
55
|
+
export function extractMetadataFromStack(skipFrames = 2) {
|
|
56
|
+
const err = new Error();
|
|
57
|
+
const stack = err.stack;
|
|
58
|
+
if (!stack) {
|
|
59
|
+
return DEFAULT_METADATA;
|
|
60
|
+
}
|
|
61
|
+
const lines = stack.split('\n');
|
|
62
|
+
// Skip "Error" line + specified frames to get to caller
|
|
63
|
+
// Frame 0: Error
|
|
64
|
+
// Frame 1: extractMetadataFromStack
|
|
65
|
+
// Frame 2: defineOpImpl (or caller)
|
|
66
|
+
// Frame 3: actual defineOp call site
|
|
67
|
+
const targetFrame = lines[skipFrames + 1];
|
|
68
|
+
if (!targetFrame) {
|
|
69
|
+
return DEFAULT_METADATA;
|
|
70
|
+
}
|
|
71
|
+
// Try V8 format: " at functionName (file:///path/to/file.ts:10:5)"
|
|
72
|
+
// or anonymous: " at file:///path/to/file.ts:10:5"
|
|
73
|
+
let match = targetFrame.match(/at\s+(?:.*?\s+\()?(.+?):(\d+):\d+\)?$/);
|
|
74
|
+
// Try JSC format: "functionName@file:///path/to/file.ts:10:5"
|
|
75
|
+
if (!match) {
|
|
76
|
+
match = targetFrame.match(/@(.+?):(\d+):\d+$/);
|
|
77
|
+
}
|
|
78
|
+
if (!match) {
|
|
79
|
+
return DEFAULT_METADATA;
|
|
80
|
+
}
|
|
81
|
+
let filePath = match[1];
|
|
82
|
+
const lineNumber = Number.parseInt(match[2], 10);
|
|
83
|
+
// Clean up file:// protocol if present
|
|
84
|
+
if (filePath.startsWith('file://')) {
|
|
85
|
+
filePath = filePath.slice(7);
|
|
86
|
+
}
|
|
87
|
+
// Extract package name from path (last directory component before src/)
|
|
88
|
+
// e.g., "/path/to/my-package/src/ops.ts" -> "my-package"
|
|
89
|
+
let packageName = 'unknown';
|
|
90
|
+
const srcIndex = filePath.lastIndexOf('/src/');
|
|
91
|
+
if (srcIndex > 0) {
|
|
92
|
+
const beforeSrc = filePath.slice(0, srcIndex);
|
|
93
|
+
const lastSlash = beforeSrc.lastIndexOf('/');
|
|
94
|
+
if (lastSlash >= 0) {
|
|
95
|
+
packageName = beforeSrc.slice(lastSlash + 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Fallback: use filename without extension
|
|
100
|
+
const lastSlash = filePath.lastIndexOf('/');
|
|
101
|
+
const fileName = lastSlash >= 0 ? filePath.slice(lastSlash + 1) : filePath;
|
|
102
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
103
|
+
packageName = dotIndex > 0 ? fileName.slice(0, dotIndex) : fileName;
|
|
104
|
+
}
|
|
105
|
+
return createOpMetadata('unknown', packageName, filePath, 'runtime', lineNumber);
|
|
106
|
+
}
|
|
107
|
+
// =============================================================================
|
|
108
|
+
// CREATE DEFINE OP
|
|
109
|
+
// =============================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Creates a defineOp function bound to a specific factory config.
|
|
112
|
+
*
|
|
113
|
+
* The returned function creates Op objects with:
|
|
114
|
+
* - metadata: includes name + merged with defaults
|
|
115
|
+
* - SpanBufferClass: from getSpanBufferClass(logSchema) - has static schema + stats
|
|
116
|
+
* - fn(ctx, ...args): the user function to execute
|
|
117
|
+
* - remappedViewClass: undefined for original ops (set by .prefix() method)
|
|
118
|
+
*
|
|
119
|
+
* @template Ctx - Bundled OpContext (logSchema, flags, deps, userCtx)
|
|
120
|
+
* @param factoryConfig - Configuration containing logSchema and flags
|
|
121
|
+
* @returns A defineOp function for creating Op instances
|
|
122
|
+
*/
|
|
123
|
+
export function createDefineOp(factoryConfig) {
|
|
124
|
+
// Why get class from schema: Class has static schema + stats shared by all instances
|
|
125
|
+
const SpanBufferClass = getSpanBufferClass(factoryConfig.logSchema);
|
|
126
|
+
return function defineOpImpl(name, fn, metadata) {
|
|
127
|
+
// When transformer is not installed, extract metadata from stack trace
|
|
128
|
+
// This provides useful file/line info for debugging even without build-time injection
|
|
129
|
+
// skipFrames=3: Error -> extractMetadataFromStack -> defineOpImpl -> caller
|
|
130
|
+
const baseMetadata = metadata?.package_file ? DEFAULT_METADATA : extractMetadataFromStack(3);
|
|
131
|
+
// Use name from: 1) explicit metadata.name (transformer), 2) defineOp('name', fn), 3) baseMetadata
|
|
132
|
+
const finalMetadata = { ...baseMetadata, ...metadata, name: metadata?.name ?? name };
|
|
133
|
+
// Use the Op class which handles all span/buffer management:
|
|
134
|
+
// - Creates SpanBuffer for the op
|
|
135
|
+
// - Registers child buffers with parent
|
|
136
|
+
// - Sets _opMetadata and _callsiteMetadata
|
|
137
|
+
// - Writes span-start/span-ok/span-err entries
|
|
138
|
+
// - Handles exceptions with span-exception
|
|
139
|
+
// Why SpanBufferClass: All ops from same defineOpContext share this class for stats coordination
|
|
140
|
+
// Why undefined for remappedViewClass: Only prefixed ops need remapping - set by .prefix() method
|
|
141
|
+
return new OpClass(finalMetadata, SpanBufferClass, fn, undefined, factoryConfig.opContextBinding);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// =============================================================================
|
|
145
|
+
// CREATE DEFINE OPS
|
|
146
|
+
// =============================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Type guard to check if a definition is an existing Op instance.
|
|
149
|
+
*/
|
|
150
|
+
function isOp(def) {
|
|
151
|
+
return def instanceof OpClass;
|
|
152
|
+
}
|
|
153
|
+
function hasAllDefinedOps(definitions, ops) {
|
|
154
|
+
for (const name in definitions) {
|
|
155
|
+
if (!(name in ops)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates a defineOps function bound to a specific factory config.
|
|
163
|
+
*
|
|
164
|
+
* The returned function:
|
|
165
|
+
* - Iterates over Object.entries(definitions)
|
|
166
|
+
* - For each [name, def]:
|
|
167
|
+
* - If def is an Op instance, use it as-is
|
|
168
|
+
* - Else wrap with defineOpImpl(name, def)
|
|
169
|
+
* - Stores all ops in a record
|
|
170
|
+
* - Creates OpGroup using createOpGroup(logSchema, flags, ops)
|
|
171
|
+
* - Returns Object.assign(opGroup, ops) to get both OpGroup methods and individual ops
|
|
172
|
+
*
|
|
173
|
+
* @template Ctx - Bundled OpContext (logSchema, flags, deps, userCtx)
|
|
174
|
+
* @param factoryConfig - Configuration containing logSchema and flags
|
|
175
|
+
* @param createOpGroup - Factory function for creating OpGroups
|
|
176
|
+
* @returns A defineOps function for creating OpGroups
|
|
177
|
+
*/
|
|
178
|
+
export function createDefineOps(factoryConfig, createOpGroup) {
|
|
179
|
+
// Get the defineOp function for wrapping raw functions
|
|
180
|
+
const defineOp = createDefineOp(factoryConfig);
|
|
181
|
+
return function defineOpsImpl(definitions) {
|
|
182
|
+
// Build the ops record by processing each definition.
|
|
183
|
+
// Keep the runtime container broad, then narrow once we've populated every key.
|
|
184
|
+
const ops = {};
|
|
185
|
+
for (const name in definitions) {
|
|
186
|
+
const def = definitions[name];
|
|
187
|
+
ops[name] = isOp(def) ? def : defineOp(name, def);
|
|
188
|
+
}
|
|
189
|
+
if (!hasAllDefinedOps(definitions, ops)) {
|
|
190
|
+
throw new Error('defineOps failed to normalize all op definitions');
|
|
191
|
+
}
|
|
192
|
+
// Create the OpGroup
|
|
193
|
+
const opGroup = createOpGroup(factoryConfig.logSchema, factoryConfig.flags, ops);
|
|
194
|
+
// Return OpGroup merged with individual ops for direct access
|
|
195
|
+
return Object.assign(opGroup, ops);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature Flag Types for Op-Centric API
|
|
3
|
+
*
|
|
4
|
+
* This module contains type definitions for feature flags used in the Op-centric API.
|
|
5
|
+
* Feature flags allow for runtime toggling of functionality with type-safe evaluation.
|
|
6
|
+
*
|
|
7
|
+
* Key concepts:
|
|
8
|
+
* - FeatureFlagSchema: Defines what flags exist and their types
|
|
9
|
+
* - BoundFeatureFlags: Typed accessor for flag values bound to a span context
|
|
10
|
+
*
|
|
11
|
+
* For the FlagEvaluator interface (getSync/getAsync/forContext), see:
|
|
12
|
+
* - packages/lmao/src/lib/schema/evaluator.ts
|
|
13
|
+
*/
|
|
14
|
+
import type { FluentLogEntry } from '../codegen/spanLoggerGenerator.js';
|
|
15
|
+
import type { LogSchema } from '../schema/LogSchema.js';
|
|
16
|
+
import type { FeatureFlagDefinition } from '../schema/types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Feature flag schema - defines what flags are available and their types
|
|
19
|
+
*/
|
|
20
|
+
export interface FeatureFlagSchema {
|
|
21
|
+
[key: string]: FeatureFlagDefinition<string | number | boolean>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Feature flag accessor bound to a span context
|
|
25
|
+
* Provides typed getters for each defined flag
|
|
26
|
+
*
|
|
27
|
+
* Access patterns:
|
|
28
|
+
* - Sync flags: `ctx.ff.myFlag` returns `{ value: T, track(context?): FluentLogEntry } | undefined`
|
|
29
|
+
* - Async flags: `await ctx.ff.get('myFlag')` returns `{ value: T, track(context?): FluentLogEntry } | undefined`
|
|
30
|
+
*
|
|
31
|
+
* Returns `undefined` when flag is false/disabled.
|
|
32
|
+
* Returns wrapper object when flag is truthy/enabled, with `.track()` for usage analytics.
|
|
33
|
+
*/
|
|
34
|
+
export type BoundFeatureFlags<FF extends FeatureFlagSchema> = {
|
|
35
|
+
readonly [K in keyof FF]: FF[K] extends FeatureFlagDefinition<infer V, 'sync'> ? {
|
|
36
|
+
value: V;
|
|
37
|
+
track(context?: {
|
|
38
|
+
action?: string;
|
|
39
|
+
outcome?: string;
|
|
40
|
+
}): FluentLogEntry<LogSchema>;
|
|
41
|
+
} | undefined : FF[K] extends FeatureFlagDefinition<infer V, 'async'> ? {
|
|
42
|
+
value: V;
|
|
43
|
+
track(context?: {
|
|
44
|
+
action?: string;
|
|
45
|
+
outcome?: string;
|
|
46
|
+
}): FluentLogEntry<LogSchema>;
|
|
47
|
+
} | undefined : never;
|
|
48
|
+
} & {
|
|
49
|
+
/** Get async flag value. Returns undefined when false, FlagContext when truthy. */
|
|
50
|
+
get(flag: string): Promise<{
|
|
51
|
+
value: unknown;
|
|
52
|
+
track(context?: {
|
|
53
|
+
action?: string;
|
|
54
|
+
outcome?: string;
|
|
55
|
+
}): FluentLogEntry<LogSchema>;
|
|
56
|
+
} | undefined>;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=featureFlagTypes.d.ts.map
|