@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.
Files changed (447) hide show
  1. package/README.md +269 -0
  2. package/dist/allocator.wasm +0 -0
  3. package/dist/bun/preload.d.ts +11 -0
  4. package/dist/bun/preload.d.ts.map +1 -0
  5. package/dist/bun/preload.js +10 -0
  6. package/dist/bun/trace-preload.d.ts +8 -0
  7. package/dist/bun/trace-preload.d.ts.map +1 -0
  8. package/dist/bun/trace-preload.js +12 -0
  9. package/dist/es.d.ts +8 -0
  10. package/dist/es.d.ts.map +1 -0
  11. package/dist/es.js +9 -0
  12. package/dist/index.d.ts +41 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +84 -0
  15. package/dist/lib/JsBufferStrategy.d.ts +49 -0
  16. package/dist/lib/JsBufferStrategy.d.ts.map +1 -0
  17. package/dist/lib/JsBufferStrategy.js +60 -0
  18. package/dist/lib/archive/chunkCompaction.d.ts +15 -0
  19. package/dist/lib/archive/chunkCompaction.d.ts.map +1 -0
  20. package/dist/lib/archive/chunkCompaction.js +24 -0
  21. package/dist/lib/archive/chunkEnvelope.d.ts +21 -0
  22. package/dist/lib/archive/chunkEnvelope.d.ts.map +1 -0
  23. package/dist/lib/archive/chunkEnvelope.js +55 -0
  24. package/dist/lib/archive/chunkRouting.d.ts +10 -0
  25. package/dist/lib/archive/chunkRouting.d.ts.map +1 -0
  26. package/dist/lib/archive/chunkRouting.js +47 -0
  27. package/dist/lib/archive/chunkStats.d.ts +12 -0
  28. package/dist/lib/archive/chunkStats.d.ts.map +1 -0
  29. package/dist/lib/archive/chunkStats.js +10 -0
  30. package/dist/lib/archive/index.d.ts +5 -0
  31. package/dist/lib/archive/index.d.ts.map +1 -0
  32. package/dist/lib/archive/index.js +4 -0
  33. package/dist/lib/arrow/capacityStats.d.ts +9 -0
  34. package/dist/lib/arrow/capacityStats.d.ts.map +1 -0
  35. package/dist/lib/arrow/capacityStats.js +231 -0
  36. package/dist/lib/arrow/dictionaries.d.ts +27 -0
  37. package/dist/lib/arrow/dictionaries.d.ts.map +1 -0
  38. package/dist/lib/arrow/dictionaries.js +135 -0
  39. package/dist/lib/arrow/flechette.d.ts +40 -0
  40. package/dist/lib/arrow/flechette.d.ts.map +1 -0
  41. package/dist/lib/arrow/flechette.js +67 -0
  42. package/dist/lib/arrow/utils.d.ts +38 -0
  43. package/dist/lib/arrow/utils.d.ts.map +1 -0
  44. package/dist/lib/arrow/utils.js +112 -0
  45. package/dist/lib/buffer/Nanoseconds.d.ts +109 -0
  46. package/dist/lib/buffer/Nanoseconds.d.ts.map +1 -0
  47. package/dist/lib/buffer/Nanoseconds.js +86 -0
  48. package/dist/lib/bufferStrategy.d.ts +95 -0
  49. package/dist/lib/bufferStrategy.d.ts.map +1 -0
  50. package/dist/lib/bufferStrategy.js +1 -0
  51. package/dist/lib/capacityTuning.d.ts +50 -0
  52. package/dist/lib/capacityTuning.d.ts.map +1 -0
  53. package/dist/lib/capacityTuning.js +65 -0
  54. package/dist/lib/codegen/evaluatorGenerator.d.ts +35 -0
  55. package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -0
  56. package/dist/lib/codegen/evaluatorGenerator.js +199 -0
  57. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +139 -0
  58. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -0
  59. package/dist/lib/codegen/fixedPositionWriterGenerator.js +289 -0
  60. package/dist/lib/codegen/spanLoggerGenerator.d.ts +115 -0
  61. package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -0
  62. package/dist/lib/codegen/spanLoggerGenerator.js +575 -0
  63. package/dist/lib/convertToArrow.d.ts +40 -0
  64. package/dist/lib/convertToArrow.d.ts.map +1 -0
  65. package/dist/lib/convertToArrow.js +1467 -0
  66. package/dist/lib/defineOpContext.d.ts +96 -0
  67. package/dist/lib/defineOpContext.d.ts.map +1 -0
  68. package/dist/lib/defineOpContext.js +227 -0
  69. package/dist/lib/errors/Blocked.d.ts +113 -0
  70. package/dist/lib/errors/Blocked.d.ts.map +1 -0
  71. package/dist/lib/errors/Blocked.js +68 -0
  72. package/dist/lib/errors/CodeError.d.ts +101 -0
  73. package/dist/lib/errors/CodeError.d.ts.map +1 -0
  74. package/dist/lib/errors/CodeError.js +42 -0
  75. package/dist/lib/errors/RetriesExhausted.d.ts +67 -0
  76. package/dist/lib/errors/RetriesExhausted.d.ts.map +1 -0
  77. package/dist/lib/errors/RetriesExhausted.js +31 -0
  78. package/dist/lib/errors/Transient.d.ts +115 -0
  79. package/dist/lib/errors/Transient.d.ts.map +1 -0
  80. package/dist/lib/errors/Transient.js +54 -0
  81. package/dist/lib/errors/index.d.ts +14 -0
  82. package/dist/lib/errors/index.d.ts.map +1 -0
  83. package/dist/lib/errors/index.js +16 -0
  84. package/dist/lib/errors/retry-policy.d.ts +60 -0
  85. package/dist/lib/errors/retry-policy.d.ts.map +1 -0
  86. package/dist/lib/errors/retry-policy.js +54 -0
  87. package/dist/lib/flushScheduler.d.ts +162 -0
  88. package/dist/lib/flushScheduler.d.ts.map +1 -0
  89. package/dist/lib/flushScheduler.js +388 -0
  90. package/dist/lib/library.d.ts +149 -0
  91. package/dist/lib/library.d.ts.map +1 -0
  92. package/dist/lib/library.js +588 -0
  93. package/dist/lib/logApi.d.ts +61 -0
  94. package/dist/lib/logApi.d.ts.map +1 -0
  95. package/dist/lib/logApi.js +12 -0
  96. package/dist/lib/logBinding.d.ts +63 -0
  97. package/dist/lib/logBinding.d.ts.map +1 -0
  98. package/dist/lib/logBinding.js +1 -0
  99. package/dist/lib/op.d.ts +105 -0
  100. package/dist/lib/op.d.ts.map +1 -0
  101. package/dist/lib/op.js +59 -0
  102. package/dist/lib/opContext/contextTypes.d.ts +88 -0
  103. package/dist/lib/opContext/contextTypes.d.ts.map +1 -0
  104. package/dist/lib/opContext/contextTypes.js +34 -0
  105. package/dist/lib/opContext/createOpGroup.d.ts +57 -0
  106. package/dist/lib/opContext/createOpGroup.d.ts.map +1 -0
  107. package/dist/lib/opContext/createOpGroup.js +341 -0
  108. package/dist/lib/opContext/defineOp.d.ts +83 -0
  109. package/dist/lib/opContext/defineOp.d.ts.map +1 -0
  110. package/dist/lib/opContext/defineOp.js +197 -0
  111. package/dist/lib/opContext/featureFlagTypes.d.ts +58 -0
  112. package/dist/lib/opContext/featureFlagTypes.d.ts.map +1 -0
  113. package/dist/lib/opContext/featureFlagTypes.js +1 -0
  114. package/dist/lib/opContext/index.d.ts +13 -0
  115. package/dist/lib/opContext/index.d.ts.map +1 -0
  116. package/dist/lib/opContext/index.js +15 -0
  117. package/dist/lib/opContext/opGroupTypes.d.ts +250 -0
  118. package/dist/lib/opContext/opGroupTypes.d.ts.map +1 -0
  119. package/dist/lib/opContext/opGroupTypes.js +31 -0
  120. package/dist/lib/opContext/opTypes.d.ts +48 -0
  121. package/dist/lib/opContext/opTypes.d.ts.map +1 -0
  122. package/dist/lib/opContext/opTypes.js +7 -0
  123. package/dist/lib/opContext/spanContextTypes.d.ts +347 -0
  124. package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -0
  125. package/dist/lib/opContext/spanContextTypes.js +1 -0
  126. package/dist/lib/opContext/types.d.ts +297 -0
  127. package/dist/lib/opContext/types.d.ts.map +1 -0
  128. package/dist/lib/opContext/types.js +16 -0
  129. package/dist/lib/result.d.ts +308 -0
  130. package/dist/lib/result.d.ts.map +1 -0
  131. package/dist/lib/result.js +359 -0
  132. package/dist/lib/schema/LogSchema.d.ts +62 -0
  133. package/dist/lib/schema/LogSchema.d.ts.map +1 -0
  134. package/dist/lib/schema/LogSchema.js +134 -0
  135. package/dist/lib/schema/builder.d.ts +12 -0
  136. package/dist/lib/schema/builder.d.ts.map +1 -0
  137. package/dist/lib/schema/builder.js +169 -0
  138. package/dist/lib/schema/defineFeatureFlags.d.ts +60 -0
  139. package/dist/lib/schema/defineFeatureFlags.d.ts.map +1 -0
  140. package/dist/lib/schema/defineFeatureFlags.js +29 -0
  141. package/dist/lib/schema/defineLogSchema.d.ts +87 -0
  142. package/dist/lib/schema/defineLogSchema.d.ts.map +1 -0
  143. package/dist/lib/schema/defineLogSchema.js +171 -0
  144. package/dist/lib/schema/evaluator.d.ts +267 -0
  145. package/dist/lib/schema/evaluator.d.ts.map +1 -0
  146. package/dist/lib/schema/evaluator.js +169 -0
  147. package/dist/lib/schema/extend.d.ts +14 -0
  148. package/dist/lib/schema/extend.d.ts.map +1 -0
  149. package/dist/lib/schema/extend.js +51 -0
  150. package/dist/lib/schema/systemSchema.d.ts +112 -0
  151. package/dist/lib/schema/systemSchema.d.ts.map +1 -0
  152. package/dist/lib/schema/systemSchema.js +260 -0
  153. package/dist/lib/schema/typeGuards.d.ts +52 -0
  154. package/dist/lib/schema/typeGuards.d.ts.map +1 -0
  155. package/dist/lib/schema/typeGuards.js +127 -0
  156. package/dist/lib/schema/types.d.ts +156 -0
  157. package/dist/lib/schema/types.d.ts.map +1 -0
  158. package/dist/lib/schema/types.js +4 -0
  159. package/dist/lib/spanBuffer.d.ts +133 -0
  160. package/dist/lib/spanBuffer.d.ts.map +1 -0
  161. package/dist/lib/spanBuffer.js +442 -0
  162. package/dist/lib/spanBufferHelpers.d.ts +53 -0
  163. package/dist/lib/spanBufferHelpers.d.ts.map +1 -0
  164. package/dist/lib/spanBufferHelpers.js +65 -0
  165. package/dist/lib/spanBufferStats.d.ts +38 -0
  166. package/dist/lib/spanBufferStats.d.ts.map +1 -0
  167. package/dist/lib/spanBufferStats.js +1 -0
  168. package/dist/lib/spanContext.d.ts +141 -0
  169. package/dist/lib/spanContext.d.ts.map +1 -0
  170. package/dist/lib/spanContext.js +763 -0
  171. package/dist/lib/sqlite/index.d.ts +14 -0
  172. package/dist/lib/sqlite/index.d.ts.map +1 -0
  173. package/dist/lib/sqlite/index.js +12 -0
  174. package/dist/lib/sqlite/sqlite-async-writer.d.ts +24 -0
  175. package/dist/lib/sqlite/sqlite-async-writer.d.ts.map +1 -0
  176. package/dist/lib/sqlite/sqlite-async-writer.js +65 -0
  177. package/dist/lib/sqlite/sqlite-common.d.ts +37 -0
  178. package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -0
  179. package/dist/lib/sqlite/sqlite-common.js +207 -0
  180. package/dist/lib/sqlite/sqlite-d1.d.ts +25 -0
  181. package/dist/lib/sqlite/sqlite-d1.d.ts.map +1 -0
  182. package/dist/lib/sqlite/sqlite-d1.js +67 -0
  183. package/dist/lib/sqlite/sqlite-db.d.ts +29 -0
  184. package/dist/lib/sqlite/sqlite-db.d.ts.map +1 -0
  185. package/dist/lib/sqlite/sqlite-db.js +1 -0
  186. package/dist/lib/sqlite/sqlite-node.d.ts +16 -0
  187. package/dist/lib/sqlite/sqlite-node.d.ts.map +1 -0
  188. package/dist/lib/sqlite/sqlite-node.js +68 -0
  189. package/dist/lib/sqlite/sqlite-writer.d.ts +39 -0
  190. package/dist/lib/sqlite/sqlite-writer.d.ts.map +1 -0
  191. package/dist/lib/sqlite/sqlite-writer.js +78 -0
  192. package/dist/lib/testing/bun-harness.d.ts +150 -0
  193. package/dist/lib/testing/bun-harness.d.ts.map +1 -0
  194. package/dist/lib/testing/bun-harness.js +729 -0
  195. package/dist/lib/testing/extractFacts.d.ts +73 -0
  196. package/dist/lib/testing/extractFacts.d.ts.map +1 -0
  197. package/dist/lib/testing/extractFacts.js +237 -0
  198. package/dist/lib/testing/facts.d.ts +235 -0
  199. package/dist/lib/testing/facts.d.ts.map +1 -0
  200. package/dist/lib/testing/facts.js +209 -0
  201. package/dist/lib/testing/index.d.ts +58 -0
  202. package/dist/lib/testing/index.d.ts.map +1 -0
  203. package/dist/lib/testing/index.js +74 -0
  204. package/dist/lib/testing/queryable-span.d.ts +39 -0
  205. package/dist/lib/testing/queryable-span.d.ts.map +1 -0
  206. package/dist/lib/testing/queryable-span.js +58 -0
  207. package/dist/lib/testing/span-query.d.ts +21 -0
  208. package/dist/lib/testing/span-query.d.ts.map +1 -0
  209. package/dist/lib/testing/span-query.js +47 -0
  210. package/dist/lib/testing/stdio-replay.d.ts +4 -0
  211. package/dist/lib/testing/stdio-replay.d.ts.map +1 -0
  212. package/dist/lib/testing/stdio-replay.js +42 -0
  213. package/dist/lib/testing/trace-query.d.ts +59 -0
  214. package/dist/lib/testing/trace-query.d.ts.map +1 -0
  215. package/dist/lib/testing/trace-query.js +462 -0
  216. package/dist/lib/testing/vitest-harness.d.ts +135 -0
  217. package/dist/lib/testing/vitest-harness.d.ts.map +1 -0
  218. package/dist/lib/testing/vitest-harness.js +486 -0
  219. package/dist/lib/threadId.d.ts +58 -0
  220. package/dist/lib/threadId.d.ts.map +1 -0
  221. package/dist/lib/threadId.js +123 -0
  222. package/dist/lib/traceContext.d.ts +116 -0
  223. package/dist/lib/traceContext.d.ts.map +1 -0
  224. package/dist/lib/traceContext.js +37 -0
  225. package/dist/lib/traceId.d.ts +78 -0
  226. package/dist/lib/traceId.d.ts.map +1 -0
  227. package/dist/lib/traceId.js +87 -0
  228. package/dist/lib/traceRoot.d.ts +133 -0
  229. package/dist/lib/traceRoot.d.ts.map +1 -0
  230. package/dist/lib/traceRoot.es.d.ts +75 -0
  231. package/dist/lib/traceRoot.es.d.ts.map +1 -0
  232. package/dist/lib/traceRoot.es.js +129 -0
  233. package/dist/lib/traceRoot.js +19 -0
  234. package/dist/lib/traceRoot.node.d.ts +77 -0
  235. package/dist/lib/traceRoot.node.d.ts.map +1 -0
  236. package/dist/lib/traceRoot.node.js +133 -0
  237. package/dist/lib/traceRoot.universal.d.ts +3 -0
  238. package/dist/lib/traceRoot.universal.d.ts.map +1 -0
  239. package/dist/lib/traceRoot.universal.js +17 -0
  240. package/dist/lib/tracer.d.ts +296 -0
  241. package/dist/lib/tracer.d.ts.map +1 -0
  242. package/dist/lib/tracer.js +346 -0
  243. package/dist/lib/tracers/ArrayQueueTracer.d.ts +56 -0
  244. package/dist/lib/tracers/ArrayQueueTracer.d.ts.map +1 -0
  245. package/dist/lib/tracers/ArrayQueueTracer.js +67 -0
  246. package/dist/lib/tracers/CompositeTracer.d.ts +24 -0
  247. package/dist/lib/tracers/CompositeTracer.d.ts.map +1 -0
  248. package/dist/lib/tracers/CompositeTracer.js +57 -0
  249. package/dist/lib/tracers/NoOpTracer.d.ts +58 -0
  250. package/dist/lib/tracers/NoOpTracer.d.ts.map +1 -0
  251. package/dist/lib/tracers/NoOpTracer.js +41 -0
  252. package/dist/lib/tracers/SQLiteTracer.d.ts +42 -0
  253. package/dist/lib/tracers/SQLiteTracer.d.ts.map +1 -0
  254. package/dist/lib/tracers/SQLiteTracer.js +84 -0
  255. package/dist/lib/tracers/StdioTracer.d.ts +83 -0
  256. package/dist/lib/tracers/StdioTracer.d.ts.map +1 -0
  257. package/dist/lib/tracers/StdioTracer.js +270 -0
  258. package/dist/lib/tracers/TestTracer.d.ts +95 -0
  259. package/dist/lib/tracers/TestTracer.d.ts.map +1 -0
  260. package/dist/lib/tracers/TestTracer.js +87 -0
  261. package/dist/lib/tracers/index.d.ts +12 -0
  262. package/dist/lib/tracers/index.d.ts.map +1 -0
  263. package/dist/lib/tracers/index.js +11 -0
  264. package/dist/lib/types.d.ts +366 -0
  265. package/dist/lib/types.d.ts.map +1 -0
  266. package/dist/lib/types.js +1 -0
  267. package/dist/lib/utf8Cache.d.ts +111 -0
  268. package/dist/lib/utf8Cache.d.ts.map +1 -0
  269. package/dist/lib/utf8Cache.js +177 -0
  270. package/dist/lib/wasm/WasmBufferStrategy.d.ts +88 -0
  271. package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -0
  272. package/dist/lib/wasm/WasmBufferStrategy.js +138 -0
  273. package/dist/lib/wasm/wasmAllocator.d.ts +109 -0
  274. package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -0
  275. package/dist/lib/wasm/wasmAllocator.js +227 -0
  276. package/dist/lib/wasm/wasmSpanBuffer.d.ts +123 -0
  277. package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -0
  278. package/dist/lib/wasm/wasmSpanBuffer.js +772 -0
  279. package/dist/lib/wasm/wasmTraceRoot.d.ts +167 -0
  280. package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -0
  281. package/dist/lib/wasm/wasmTraceRoot.js +264 -0
  282. package/dist/node.d.ts +7 -0
  283. package/dist/node.d.ts.map +1 -0
  284. package/dist/node.js +8 -0
  285. package/dist/testing.d.ts +18 -0
  286. package/dist/testing.d.ts.map +1 -0
  287. package/dist/testing.js +17 -0
  288. package/package.json +193 -0
  289. package/src/bun/preload.ts +11 -0
  290. package/src/bun/trace-preload.ts +14 -0
  291. package/src/es.ts +11 -0
  292. package/src/index.ts +194 -0
  293. package/src/lib/JsBufferStrategy.ts +102 -0
  294. package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +485 -0
  295. package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +390 -0
  296. package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +647 -0
  297. package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +292 -0
  298. package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +354 -0
  299. package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +127 -0
  300. package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +392 -0
  301. package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +389 -0
  302. package/src/lib/__tests__/arrow-conversion-algorithms.test.ts +54 -0
  303. package/src/lib/__tests__/arrow-test-helpers.ts +71 -0
  304. package/src/lib/__tests__/binary-e2e.test.ts +203 -0
  305. package/src/lib/__tests__/buffer-overflow-op-api.test.ts +608 -0
  306. package/src/lib/__tests__/buffer-overflow.test.ts +612 -0
  307. package/src/lib/__tests__/capacity-tuning.test.ts +544 -0
  308. package/src/lib/__tests__/effective-schema.test.ts +439 -0
  309. package/src/lib/__tests__/flechette.test.ts +42 -0
  310. package/src/lib/__tests__/flushScheduler.test.ts +537 -0
  311. package/src/lib/__tests__/integration.test.ts +600 -0
  312. package/src/lib/__tests__/library.test.ts +934 -0
  313. package/src/lib/__tests__/nested-library-tasks.test.ts +849 -0
  314. package/src/lib/__tests__/op-context-binding.test.ts +135 -0
  315. package/src/lib/__tests__/op-metadata.test.ts +198 -0
  316. package/src/lib/__tests__/op-type-safety.test.ts +71 -0
  317. package/src/lib/__tests__/package-exports.test.ts +57 -0
  318. package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +319 -0
  319. package/src/lib/__tests__/remapped-buffer-view.test.ts +635 -0
  320. package/src/lib/__tests__/scope-attributes.test.ts +348 -0
  321. package/src/lib/__tests__/span-lifecycle.test.ts +680 -0
  322. package/src/lib/__tests__/sync-async-trace.test.ts +435 -0
  323. package/src/lib/__tests__/test-helpers.ts +318 -0
  324. package/src/lib/__tests__/timestamp.test.ts +259 -0
  325. package/src/lib/__tests__/trace-archive-primitives.test.ts +98 -0
  326. package/src/lib/__tests__/traceContext-type-enforcement.test.ts +271 -0
  327. package/src/lib/__tests__/tracer.test.ts +211 -0
  328. package/src/lib/__tests__/type-narrowing.test.ts +137 -0
  329. package/src/lib/archive/chunkCompaction.ts +44 -0
  330. package/src/lib/archive/chunkEnvelope.ts +79 -0
  331. package/src/lib/archive/chunkRouting.ts +70 -0
  332. package/src/lib/archive/chunkStats.ts +25 -0
  333. package/src/lib/archive/index.ts +4 -0
  334. package/src/lib/arrow/capacityStats.ts +340 -0
  335. package/src/lib/arrow/dictionaries.ts +159 -0
  336. package/src/lib/arrow/flechette.ts +114 -0
  337. package/src/lib/arrow/utils.ts +126 -0
  338. package/src/lib/buffer/Nanoseconds.ts +131 -0
  339. package/src/lib/bufferStrategy.ts +106 -0
  340. package/src/lib/capacityTuning.ts +102 -0
  341. package/src/lib/codegen/__tests__/__snapshots__/evaluatorGenerator.test.ts.snap +160 -0
  342. package/src/lib/codegen/__tests__/__snapshots__/scopeGenerator.test.ts.snap +196 -0
  343. package/src/lib/codegen/__tests__/__snapshots__/spanLoggerGenerator.test.ts.snap +1965 -0
  344. package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +516 -0
  345. package/src/lib/codegen/__tests__/nullBitmap.test.ts +207 -0
  346. package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +237 -0
  347. package/src/lib/codegen/evaluatorGenerator.ts +309 -0
  348. package/src/lib/codegen/fixedPositionWriterGenerator.ts +444 -0
  349. package/src/lib/codegen/spanLoggerGenerator.ts +715 -0
  350. package/src/lib/convertToArrow.ts +1805 -0
  351. package/src/lib/defineOpContext.ts +398 -0
  352. package/src/lib/errors/Blocked.ts +165 -0
  353. package/src/lib/errors/CodeError.ts +132 -0
  354. package/src/lib/errors/RetriesExhausted.ts +78 -0
  355. package/src/lib/errors/Transient.ts +168 -0
  356. package/src/lib/errors/__tests__/Blocked-config.test.ts +152 -0
  357. package/src/lib/errors/__tests__/Transient.test.ts +129 -0
  358. package/src/lib/errors/__tests__/retry-policy.test.ts +85 -0
  359. package/src/lib/errors/index.ts +24 -0
  360. package/src/lib/errors/retry-policy.ts +87 -0
  361. package/src/lib/flushScheduler.ts +509 -0
  362. package/src/lib/library.ts +682 -0
  363. package/src/lib/logApi.ts +70 -0
  364. package/src/lib/logBinding.ts +67 -0
  365. package/src/lib/op.ts +103 -0
  366. package/src/lib/opContext/__tests__/retry.test.ts +764 -0
  367. package/src/lib/opContext/contextTypes.ts +130 -0
  368. package/src/lib/opContext/createOpGroup.ts +456 -0
  369. package/src/lib/opContext/defineOp.ts +281 -0
  370. package/src/lib/opContext/featureFlagTypes.ts +54 -0
  371. package/src/lib/opContext/index.ts +16 -0
  372. package/src/lib/opContext/opGroupTypes.ts +342 -0
  373. package/src/lib/opContext/opTypes.ts +80 -0
  374. package/src/lib/opContext/spanContextTypes.ts +398 -0
  375. package/src/lib/opContext/types.ts +403 -0
  376. package/src/lib/result.ts +550 -0
  377. package/src/lib/schema/LogSchema.ts +153 -0
  378. package/src/lib/schema/__tests__/defineLogSchema.test.ts +342 -0
  379. package/src/lib/schema/__tests__/featureFlags.test.ts +443 -0
  380. package/src/lib/schema/builder.ts +201 -0
  381. package/src/lib/schema/defineFeatureFlags.ts +91 -0
  382. package/src/lib/schema/defineLogSchema.ts +291 -0
  383. package/src/lib/schema/evaluator.ts +404 -0
  384. package/src/lib/schema/extend.ts +69 -0
  385. package/src/lib/schema/systemSchema.ts +339 -0
  386. package/src/lib/schema/typeGuards.ts +163 -0
  387. package/src/lib/schema/types.ts +265 -0
  388. package/src/lib/spanBuffer.ts +571 -0
  389. package/src/lib/spanBufferHelpers.ts +73 -0
  390. package/src/lib/spanBufferStats.ts +40 -0
  391. package/src/lib/spanContext.ts +1566 -0
  392. package/src/lib/sqlite/__tests__/sqlite-common.test.ts +89 -0
  393. package/src/lib/sqlite/index.ts +26 -0
  394. package/src/lib/sqlite/sqlite-async-writer.ts +101 -0
  395. package/src/lib/sqlite/sqlite-common.ts +309 -0
  396. package/src/lib/sqlite/sqlite-d1.ts +104 -0
  397. package/src/lib/sqlite/sqlite-db.ts +32 -0
  398. package/src/lib/sqlite/sqlite-node.ts +83 -0
  399. package/src/lib/sqlite/sqlite-writer.ts +128 -0
  400. package/src/lib/testing/TRACE-TESTING.md +100 -0
  401. package/src/lib/testing/__tests__/bun-harness.test.ts +108 -0
  402. package/src/lib/testing/__tests__/extractFacts.test.ts +279 -0
  403. package/src/lib/testing/__tests__/facts.test.ts +324 -0
  404. package/src/lib/testing/__tests__/vitest-harness.test.ts +32 -0
  405. package/src/lib/testing/bun-harness.ts +990 -0
  406. package/src/lib/testing/extractFacts.ts +362 -0
  407. package/src/lib/testing/facts.ts +470 -0
  408. package/src/lib/testing/index.ts +141 -0
  409. package/src/lib/testing/queryable-span.ts +108 -0
  410. package/src/lib/testing/span-query.ts +65 -0
  411. package/src/lib/testing/stdio-replay.ts +50 -0
  412. package/src/lib/testing/trace-query.ts +329 -0
  413. package/src/lib/testing/vitest-harness.ts +691 -0
  414. package/src/lib/threadId.ts +135 -0
  415. package/src/lib/traceContext.ts +182 -0
  416. package/src/lib/traceId.ts +142 -0
  417. package/src/lib/traceRoot.es.ts +157 -0
  418. package/src/lib/traceRoot.node.ts +170 -0
  419. package/src/lib/traceRoot.ts +154 -0
  420. package/src/lib/traceRoot.universal.ts +22 -0
  421. package/src/lib/tracer.ts +896 -0
  422. package/src/lib/tracers/ArrayQueueTracer.ts +76 -0
  423. package/src/lib/tracers/CompositeTracer.ts +76 -0
  424. package/src/lib/tracers/NoOpTracer.ts +73 -0
  425. package/src/lib/tracers/SQLiteTracer.ts +115 -0
  426. package/src/lib/tracers/StdioTracer.ts +380 -0
  427. package/src/lib/tracers/TestTracer.ts +146 -0
  428. package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +184 -0
  429. package/src/lib/tracers/__tests__/NoOpTracer.test.ts +204 -0
  430. package/src/lib/tracers/__tests__/StdioTracer.test.ts +313 -0
  431. package/src/lib/tracers/__tests__/TestTracer.test.ts +200 -0
  432. package/src/lib/tracers/index.ts +12 -0
  433. package/src/lib/types.ts +498 -0
  434. package/src/lib/utf8Cache.ts +201 -0
  435. package/src/lib/wasm/WasmBufferStrategy.ts +219 -0
  436. package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +256 -0
  437. package/src/lib/wasm/__tests__/wasm-integration.test.ts +476 -0
  438. package/src/lib/wasm/__tests__/wasmAllocator.test.ts +699 -0
  439. package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +449 -0
  440. package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +390 -0
  441. package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +444 -0
  442. package/src/lib/wasm/allocator.zig +945 -0
  443. package/src/lib/wasm/wasmAllocator.ts +469 -0
  444. package/src/lib/wasm/wasmSpanBuffer.ts +1014 -0
  445. package/src/lib/wasm/wasmTraceRoot.ts +315 -0
  446. package/src/node.ts +10 -0
  447. package/src/testing.ts +18 -0
@@ -0,0 +1,588 @@
1
+ /**
2
+ * Library Prefix/Remapping Utilities
3
+ *
4
+ * WHY: Libraries need to write clean, domain-focused code (ctx.tag.status(200))
5
+ * while avoiding naming conflicts when composed with other libraries.
6
+ *
7
+ * HOW: At composition time (cold path), we generate a remapped SpanLogger class
8
+ * that exposes clean method names but writes to prefixed buffer columns.
9
+ *
10
+ * Per specs/lmao/01e_library_integration_pattern.md:
11
+ * - Libraries define clean schemas without prefixes (status, method, url)
12
+ * - Prefixing happens at composition time (http_status, http_method, http_url)
13
+ * - Zero hot path overhead - all remapping done via code generation at module creation
14
+ *
15
+ * WHAT: This module provides:
16
+ * - prefixSchema() - Rename schema fields with prefix
17
+ * - createPrefixMapping() - Build clean→prefixed name mapping
18
+ * - generateRemappedBufferViewClass() - Generate view for Arrow conversion
19
+ * - generateRemappedSpanLoggerClass() - Generate class with clean methods, prefixed writes
20
+ * - createRemappedSpanLoggerClass() - Compile and cache SpanLogger classes
21
+ */
22
+ import { isRecord } from '@smoothbricks/validation';
23
+ import { ENTRY_TYPE_DEBUG, ENTRY_TYPE_ERROR, ENTRY_TYPE_INFO, ENTRY_TYPE_TRACE, ENTRY_TYPE_WARN, } from './schema/systemSchema.js';
24
+ import { getEnumValues, getSchemaType } from './schema/typeGuards.js';
25
+ import { LogSchema } from './schema/types.js';
26
+ function isSchemaField(value) {
27
+ return isRecord(value);
28
+ }
29
+ function isRemappedBufferViewClass(value) {
30
+ if (typeof value !== 'function') {
31
+ return false;
32
+ }
33
+ const prototype = Reflect.get(value, 'prototype');
34
+ return (typeof prototype === 'object' &&
35
+ prototype !== null &&
36
+ typeof Reflect.get(prototype, 'getColumnIfAllocated') === 'function' &&
37
+ typeof Reflect.get(prototype, 'getNullsIfAllocated') === 'function');
38
+ }
39
+ function isRemappedSpanLoggerClass(value) {
40
+ if (typeof value !== 'function') {
41
+ return false;
42
+ }
43
+ const prototype = Reflect.get(value, 'prototype');
44
+ return (typeof prototype === 'object' &&
45
+ prototype !== null &&
46
+ typeof Reflect.get(prototype, 'with') === 'function' &&
47
+ typeof Reflect.get(prototype, 'info') === 'function' &&
48
+ typeof Reflect.get(prototype, 'error') === 'function');
49
+ }
50
+ /**
51
+ * Prefix a tag attribute schema
52
+ * Renames all fields with a prefix to avoid conflicts
53
+ *
54
+ * Example:
55
+ * - Input: { status: S.number(), method: S.enum(['GET', 'POST']) }
56
+ * - Prefix: 'http'
57
+ * - Output: { http_status: S.number(), http_method: S.enum(['GET', 'POST']) }
58
+ */
59
+ export function prefixSchema(schema, prefix) {
60
+ const prefixedFields = {};
61
+ const constructorFields = {};
62
+ for (const [fieldName, fieldSchema] of schema._columns) {
63
+ const prefixedName = `${prefix}_${fieldName}`;
64
+ prefixedFields[prefixedName] = fieldSchema;
65
+ if (isSchemaField(fieldSchema)) {
66
+ constructorFields[prefixedName] = fieldSchema;
67
+ }
68
+ }
69
+ // Create LogSchema and spread fields directly onto result for direct access
70
+ const logSchema = new LogSchema(constructorFields);
71
+ return Object.assign(logSchema, prefixedFields);
72
+ }
73
+ /**
74
+ * Create a mapping from clean field names to prefixed column names
75
+ *
76
+ * WHY: This mapping is used by generateRemappedSpanLoggerClass to create methods
77
+ * that write to prefixed columns but expose clean API names.
78
+ *
79
+ * @param schema - Clean schema (LogSchema instance)
80
+ * @param prefix - Prefix to apply (e.g., 'http')
81
+ * @returns Mapping from clean name to prefixed name
82
+ *
83
+ * @example
84
+ * const schema = defineLogSchema({ status: S.number() });
85
+ * const mapping = createPrefixMapping(schema, 'http');
86
+ * // Returns: { status: 'http_status' }
87
+ */
88
+ export function createPrefixMapping(schema, prefix) {
89
+ const mapping = {};
90
+ // Use LogSchema.fieldNames directly (no conditional needed)
91
+ for (const fieldName of schema._columnNames) {
92
+ mapping[fieldName] = `${prefix}_${fieldName}`;
93
+ }
94
+ return mapping;
95
+ }
96
+ // ============================================================================
97
+ // RemappedBufferView - Maps prefixed column names to unprefixed for tree traversal
98
+ // ============================================================================
99
+ /**
100
+ * Cache for generated RemappedBufferView classes.
101
+ * Key is a stable string representation of the mapping.
102
+ * This avoids regenerating classes for the same mapping.
103
+ */
104
+ const remappedBufferViewClassCache = new Map();
105
+ /**
106
+ * Cache for generated RemappedSpanLogger classes.
107
+ * Key is a stable string representation of schema fields + prefix mapping.
108
+ */
109
+ const remappedSpanLoggerClassCache = new Map();
110
+ /**
111
+ * Create a stable cache key from a prefix mapping.
112
+ * Sorts keys to ensure consistent ordering.
113
+ */
114
+ function createMappingCacheKey(mapping) {
115
+ const sortedEntries = Object.entries(mapping).sort(([a], [b]) => a.localeCompare(b));
116
+ return JSON.stringify(sortedEntries);
117
+ }
118
+ /**
119
+ * Create a stable cache key from schema and prefix mapping.
120
+ * Combines schema fields with sorted prefix mapping for consistent keys.
121
+ */
122
+ function createSchemaAndMappingCacheKey(schema, mapping) {
123
+ const schemaKey = JSON.stringify(schema.fields);
124
+ const mappingKey = createMappingCacheKey(mapping);
125
+ return `${schemaKey}:${mappingKey}`;
126
+ }
127
+ /**
128
+ * Generate a RemappedBufferView class for library prefix support.
129
+ *
130
+ * WHY: Libraries write to unprefixed columns (status, method) but Arrow conversion
131
+ * iterates using prefixed names from the root schema (http_status, http_method).
132
+ * RemappedBufferView bridges this gap for tree traversal during cold-path Arrow conversion.
133
+ *
134
+ * HOW: Uses new Function() to generate a class at library composition time (cold path).
135
+ * The generated class wraps a SpanBuffer and remaps getColumnIfAllocated/getNullsIfAllocated
136
+ * calls from prefixed names to unprefixed names.
137
+ *
138
+ * WHAT: Returns a class constructor that:
139
+ * - Passes through tree traversal properties (children, next)
140
+ * - Passes through system columns (timestamps, operations, message, etc.)
141
+ * - Passes through identity properties (traceId, spanId, etc.)
142
+ * - Remaps getColumnIfAllocated() and getNullsIfAllocated() from prefixed→unprefixed
143
+ *
144
+ * Per specs/lmao/01e_library_integration_pattern.md:
145
+ * - Hot path: Library writes directly to unprefixed columns (zero overhead)
146
+ * - Cold path: Arrow conversion uses RemappedBufferView to access via prefixed names
147
+ *
148
+ * @param prefixToUnprefixedMapping - Maps prefixed names to unprefixed names
149
+ * e.g., { 'http_status': 'status', 'http_method': 'method' }
150
+ * NOTE: The mapping is prefixed→unprefixed (reverse of createPrefixMapping output)
151
+ *
152
+ * @returns Constructor for RemappedBufferView class
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Create mapping (prefixed → unprefixed)
157
+ * const mapping = { 'http_status': 'status', 'http_method': 'method' };
158
+ * const ViewClass = generateRemappedBufferViewClass(mapping);
159
+ *
160
+ * // Wrap library buffer
161
+ * const view = new ViewClass(libraryBuffer);
162
+ *
163
+ * // Access via prefixed name returns unprefixed column
164
+ * view.getColumnIfAllocated('http_status'); // Returns buffer.getColumnIfAllocated('status')
165
+ * ```
166
+ */
167
+ export function generateRemappedBufferViewClass(prefixToUnprefixedMapping) {
168
+ // Check cache first
169
+ const cacheKey = createMappingCacheKey(prefixToUnprefixedMapping);
170
+ const cached = remappedBufferViewClassCache.get(cacheKey);
171
+ if (cached) {
172
+ return cached;
173
+ }
174
+ const mappingCode = JSON.stringify(prefixToUnprefixedMapping);
175
+ // Generate the class code
176
+ // Uses IIFE wrapper for clean scope, similar to generateRemappedSpanLoggerClass
177
+ const code = `(function() {
178
+ 'use strict';
179
+ const mapping = ${mappingCode};
180
+
181
+ class RemappedBufferView {
182
+ constructor(buffer) {
183
+ this._buffer = buffer;
184
+ // Build _columns with prefixed names from mapping
185
+ // mapping is { prefixedName: unprefixedName }
186
+ // _logSchema may be undefined in tests using mock buffers
187
+ const baseFields = buffer._logSchema?.fields ?? {};
188
+ this._columns = [];
189
+ for (const prefixedName in mapping) {
190
+ const unprefixedName = mapping[prefixedName];
191
+ const schema = baseFields[unprefixedName];
192
+ if (schema) this._columns.push([prefixedName, schema]);
193
+ }
194
+ }
195
+
196
+ // Tree traversal (pass-through)
197
+ get _children() { return this._buffer._children; }
198
+ get _parent() { return this._buffer._parent; }
199
+ get _overflow() { return this._buffer._overflow; }
200
+
201
+ // Row count
202
+ get _writeIndex() { return this._buffer._writeIndex; }
203
+
204
+ // System columns (NOT remapped - same in all buffers)
205
+ get timestamp() { return this._buffer.timestamp; }
206
+ get entry_type() { return this._buffer.entry_type; }
207
+ get message_values() { return this._buffer.message_values; }
208
+ get message_nulls() { return this._buffer.message_nulls; }
209
+ get line_values() { return this._buffer.line_values; }
210
+ get line_nulls() { return this._buffer.line_nulls; }
211
+ get error_code_values() { return this._buffer.error_code_values; }
212
+ get error_code_nulls() { return this._buffer.error_code_nulls; }
213
+ get exception_stack_values() { return this._buffer.exception_stack_values; }
214
+ get exception_stack_nulls() { return this._buffer.exception_stack_nulls; }
215
+ get ff_value_values() { return this._buffer.ff_value_values; }
216
+ get ff_value_nulls() { return this._buffer.ff_value_nulls; }
217
+
218
+ // Identity (pass-through)
219
+ get trace_id() { return this._buffer.trace_id; }
220
+ get thread_id() { return this._buffer.thread_id; }
221
+ get span_id() { return this._buffer.span_id; }
222
+ get parent_span_id() { return this._buffer.parent_span_id; }
223
+ get parent_thread_id() { return this._buffer.parent_thread_id; }
224
+ get _identity() { return this._buffer._identity; }
225
+
226
+ // Metadata (pass-through)
227
+ get module() { return this._buffer._module; }
228
+ get _opMetadata() { return this._buffer._opMetadata; }
229
+ get _callsiteMetadata() { return this._buffer._callsiteMetadata; }
230
+ // Remapped column access (for Arrow conversion iteration)
231
+ // Maps prefixed name → unprefixed name before calling underlying buffer
232
+ getColumnIfAllocated(name) {
233
+ const unprefixedName = mapping[name] ?? name;
234
+ return this._buffer.getColumnIfAllocated(unprefixedName);
235
+ }
236
+
237
+ getNullsIfAllocated(name) {
238
+ const unprefixedName = mapping[name] ?? name;
239
+ return this._buffer.getNullsIfAllocated(unprefixedName);
240
+ }
241
+ }
242
+
243
+ return RemappedBufferView;
244
+ })()`;
245
+ const GeneratedClass = new Function(`return ${code}`)();
246
+ if (!isRemappedBufferViewClass(GeneratedClass)) {
247
+ throw new TypeError('Generated remapped buffer view is missing column remapping methods');
248
+ }
249
+ // Cache for future use
250
+ remappedBufferViewClassCache.set(cacheKey, GeneratedClass);
251
+ return GeneratedClass;
252
+ }
253
+ /**
254
+ * Generate enum value mapping code for remapped class
255
+ * Creates a switch-case statement for compile-time enum mapping
256
+ *
257
+ * WHY: Enums need compile-time mapping to Uint8 values for 1-byte storage
258
+ */
259
+ function generateEnumMapping(fieldName, enumValues) {
260
+ const cases = enumValues.map((value, index) => ` case ${JSON.stringify(value)}: return ${index};`).join('\n');
261
+ return `
262
+ function getEnumIndex_${fieldName}(value) {
263
+ switch(value) {
264
+ ${cases}
265
+ default: return 0;
266
+ }
267
+ }`;
268
+ }
269
+ /**
270
+ * Generate attribute writer method for remapped SpanLogger
271
+ *
272
+ * WHY: Each method must write to the PREFIXED column while being called by CLEAN name
273
+ * HOW: Method name is cleanName, but buffer access uses prefixedColumnName
274
+ *
275
+ * @param cleanName - Clean method name (e.g., 'status')
276
+ * @param prefixedColumnName - Prefixed column name (e.g., 'http_status')
277
+ * @param schema - Field schema for type-specific handling
278
+ * @param hasEnumMapping - Whether enum mapping function exists
279
+ */
280
+ function generateRemappedAttributeWriter(cleanName, prefixedColumnName, schema, hasEnumMapping) {
281
+ const columnName = prefixedColumnName;
282
+ const lmaoType = getSchemaType(schema);
283
+ // For enums, use pre-generated mapping function (uses cleanName for function)
284
+ // Generated code: ALWAYS writes to row 0 (span-start) with overwrite semantics
285
+ // Maps clean method name to prefixed column, marks value as non-null (bit 0)
286
+ if (lmaoType === 'enum' && hasEnumMapping) {
287
+ return `
288
+ ${cleanName}(value) {
289
+ const idx = 0;
290
+ const enumIndex = getEnumIndex_${cleanName}(value);
291
+ this._buffer.${columnName}_values[idx] = enumIndex;
292
+ this._buffer.${columnName}_nulls[0] |= 1;
293
+ return this;
294
+ }`;
295
+ }
296
+ // For categories, store strings directly
297
+ // Generated code: writes to row 0, stores string directly, marks non-null
298
+ if (lmaoType === 'category') {
299
+ return `
300
+ ${cleanName}(value) {
301
+ const idx = 0;
302
+ if (value === null || value === undefined) {
303
+ this._buffer.${columnName}_nulls[0] &= ~1;
304
+ return this;
305
+ }
306
+ this._buffer.${columnName}_values[idx] = value;
307
+ this._buffer.${columnName}_nulls[0] |= 1;
308
+ return this;
309
+ }`;
310
+ }
311
+ // For text, store strings directly
312
+ // Generated code: writes to row 0, handles null/undefined by clearing bit and returning early,
313
+ // stores string directly, marks non-null
314
+ if (lmaoType === 'text') {
315
+ return `
316
+ ${cleanName}(value) {
317
+ const idx = 0;
318
+ if (value === null || value === undefined) {
319
+ this._buffer.${columnName}_nulls[0] &= ~1;
320
+ return this;
321
+ }
322
+ this._buffer.${columnName}_values[idx] = value;
323
+ this._buffer.${columnName}_nulls[0] |= 1;
324
+ return this;
325
+ }`;
326
+ }
327
+ // Boolean: bit-packed storage (8 values per byte)
328
+ // Generated code: writes to row 0, bit 0 of byte 0 is index 0,
329
+ // sets or clears value bit, marks non-null
330
+ if (lmaoType === 'boolean') {
331
+ return `
332
+ ${cleanName}(value) {
333
+ if (value) {
334
+ this._buffer.${columnName}_values[0] |= 1;
335
+ } else {
336
+ this._buffer.${columnName}_values[0] &= ~1;
337
+ }
338
+ this._buffer.${columnName}_nulls[0] |= 1;
339
+ return this;
340
+ }`;
341
+ }
342
+ // Generic writer for other types (number)
343
+ // Generated code: writes to row 0, direct value assignment, marks non-null
344
+ return `
345
+ ${cleanName}(value) {
346
+ const idx = 0;
347
+ this._buffer.${columnName}_values[idx] = value;
348
+ this._buffer.${columnName}_nulls[0] |= 1;
349
+ return this;
350
+ }`;
351
+ }
352
+ /**
353
+ * Generate a remapped SpanLogger class for library prefix support
354
+ *
355
+ * WHY: Library authors write clean code (ctx.tag.status(200)) but buffers use prefixed
356
+ * columns (http_status). This function generates a class at module creation time
357
+ * (cold path) that exposes clean method names but writes to prefixed columns.
358
+ *
359
+ * HOW: Uses new Function() to generate optimized JavaScript code. The generated class
360
+ * has methods named after clean schema fields but writes to prefixed buffer columns.
361
+ *
362
+ * WHAT: Returns executable JavaScript code string for a SpanLogger class with:
363
+ * - Clean method names (status, method, url)
364
+ * - Writes to prefixed columns (http_status, http_method, http_url)
365
+ * - Full support for enum/category/text type handling
366
+ * - Method chaining support
367
+ *
368
+ * @param cleanSchema - Original clean schema (without prefix)
369
+ * @param prefixMapping - Mapping from clean names to prefixed names
370
+ * @param className - Name for the generated class
371
+ * @returns Executable JavaScript code string
372
+ *
373
+ * @example
374
+ * const code = generateRemappedSpanLoggerClass(
375
+ * { status: S.number(), method: S.enum(['GET', 'POST']) },
376
+ * { status: 'http_status', method: 'http_method' },
377
+ * 'HttpSpanLogger'
378
+ * );
379
+ * // Generated class has .status() method that writes to http_status
380
+ */
381
+ export function generateRemappedSpanLoggerClass(cleanSchema, prefixMapping, className = 'RemappedSpanLogger') {
382
+ // Use LogSchema.fieldEntries() to iterate schema fields
383
+ const schemaFields = cleanSchema._columns;
384
+ // Generate enum mapping functions (use cleanName for function names)
385
+ const enumMappings = [];
386
+ const enumFieldNames = new Set();
387
+ for (const [fieldName, fieldSchema] of schemaFields) {
388
+ const lmaoType = getSchemaType(fieldSchema);
389
+ const enumValues = getEnumValues(fieldSchema);
390
+ if (lmaoType === 'enum' && enumValues) {
391
+ enumMappings.push(generateEnumMapping(fieldName, enumValues));
392
+ enumFieldNames.add(fieldName);
393
+ }
394
+ }
395
+ // Generate attribute writer methods with remapping
396
+ const attributeWriters = schemaFields.map(([cleanName, fieldSchema]) => {
397
+ const prefixedName = prefixMapping[cleanName] || cleanName;
398
+ return generateRemappedAttributeWriter(cleanName, prefixedName, fieldSchema, enumFieldNames.has(cleanName));
399
+ });
400
+ // Create schema type map for runtime type detection in scope()
401
+ const schemaTypeMap = Object.fromEntries(schemaFields.map(([fieldName, fieldSchema]) => {
402
+ return [fieldName, getSchemaType(fieldSchema) || 'unknown'];
403
+ }));
404
+ // Create clean-to-prefixed mapping for with() and scope() methods
405
+ const prefixMappingJson = JSON.stringify(prefixMapping);
406
+ // Entry type constants (imported from lmao.ts at module level, used here for code gen)
407
+ // These values are inlined into the generated code string below
408
+ // Generate the complete class
409
+ // Generated code: IIFE wrapper for clean scope
410
+ const classCode = `(function() {
411
+ 'use strict';
412
+ ` +
413
+ // Generated code: getTimestampNanos - platform-aware timestamp function
414
+ // Node.js: uses process.hrtime.bigint() for true nanosecond precision
415
+ // Browser: uses performance.timeOrigin + performance.now() for microsecond precision
416
+ `const getTimestampNanos = (typeof process !== 'undefined' && process.hrtime)
417
+ ? (() => {
418
+ const anchorEpochNanos = BigInt(Date.now()) * 1000000n;
419
+ const anchorHrtime = process.hrtime.bigint();
420
+ return () => anchorEpochNanos + (process.hrtime.bigint() - anchorHrtime);
421
+ })()
422
+ : () => {
423
+ const epochMicros = Math.round((performance.timeOrigin + performance.now()) * 1000);
424
+ return BigInt(epochMicros) * 1000n;
425
+ };
426
+ ` +
427
+ // Generated code: enum mapping functions (getEnumIndex_${fieldName})
428
+ enumMappings.join('\n') +
429
+ `
430
+ ` +
431
+ // Generated code: SCHEMA_TYPES - maps clean field names to lmao types for runtime type detection
432
+ `const SCHEMA_TYPES = ${JSON.stringify(schemaTypeMap)};
433
+ ` +
434
+ // Generated code: PREFIX_MAPPING - maps clean names to prefixed column names
435
+ `const PREFIX_MAPPING = ${prefixMappingJson};
436
+
437
+ class ${className} {
438
+ ` +
439
+ // Generated code: constructor stores buffer, createOverflowBuffer function, and scoped attributes
440
+ `constructor(buffer, createOverflowBuffer, initialScopedAttributes = {}) {
441
+ this._buffer = buffer;
442
+ this._createOverflowBuffer = createOverflowBuffer;
443
+ this._scopedAttributes = initialScopedAttributes;
444
+ }
445
+ ` +
446
+ // Generated code: tag getter returns this for chainable API (writes to row 0 = span-start)
447
+ `get tag() {
448
+ return this;
449
+ }
450
+ ` +
451
+ // Generated code: with() bulk attribute setting - maps clean names to prefixed columns,
452
+ // stores values directly (strings stored as-is), marks non-null (bit 0)
453
+ `with(attributes) {
454
+ const idx = 0;
455
+ for (const [cleanKey, value] of Object.entries(attributes)) {
456
+ const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
457
+ const columnName = prefixedKey;
458
+ const column = this._buffer[columnName + '_values'];
459
+ if (column && value !== null && value !== undefined) {
460
+ column[idx] = value;
461
+ const nullBitmap = this._buffer[columnName + '_nulls'];
462
+ if (nullBitmap) {
463
+ nullBitmap[0] |= 1;
464
+ }
465
+ }
466
+ }
467
+ return this;
468
+ }
469
+ ` +
470
+ // Generated code: individual attribute setters (one per schema field)
471
+ attributeWriters.join('\n') +
472
+ `
473
+ ` +
474
+ // Generated code: scope() stores values in _scopedAttributes,
475
+ // then pre-fills remaining buffer capacity so future log entries inherit these values
476
+ `scope(attributes) {
477
+ for (const [cleanKey, value] of Object.entries(attributes)) {
478
+ if (value !== null && value !== undefined) {
479
+ this._scopedAttributes[cleanKey] = value;
480
+ }
481
+ }
482
+ const startIdx = this._buffer._writeIndex;
483
+ const endIdx = this._buffer._capacity;
484
+ for (let idx = startIdx; idx < endIdx; idx++) {
485
+ for (const [cleanKey, value] of Object.entries(this._scopedAttributes)) {
486
+ const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
487
+ const columnName = prefixedKey;
488
+ const column = this._buffer[columnName + '_values'];
489
+ if (column) {
490
+ column[idx] = value;
491
+ const nullBitmap = this._buffer[columnName + '_nulls'];
492
+ if (nullBitmap) {
493
+ const byteIndex = Math.floor(idx / 8);
494
+ const bitOffset = idx % 8;
495
+ nullBitmap[byteIndex] |= (1 << bitOffset);
496
+ }
497
+ }
498
+ }
499
+ }
500
+ }
501
+ ` +
502
+ // Generated code: _writeMessage() writes a log entry - ensures buffer has space,
503
+ // writes entry type + timestamp + message, applies scoped attributes
504
+ `_writeMessage(entryType, message) {
505
+ // Check if buffer is full and create overflow buffer if needed
506
+ if (this._buffer._writeIndex >= this._buffer._capacity) {
507
+ const oldBuffer = this._buffer;
508
+ this._buffer = this._createOverflowBuffer(oldBuffer);
509
+ oldBuffer._overflow = this._buffer;
510
+ }
511
+ const idx = this._buffer._writeIndex;
512
+ this._buffer.entry_type[idx] = entryType;
513
+ this._buffer.timestamp[idx] = getTimestampNanos(this._buffer._traceRoot.anchorEpochNanos, this._buffer._traceRoot.anchorPerfNow);
514
+ const messageColumn = this._buffer.message_values;
515
+ if (messageColumn) {
516
+ messageColumn[idx] = message;
517
+ const nullBitmap = this._buffer.message_nulls;
518
+ if (nullBitmap) {
519
+ const byteIndex = Math.floor(idx / 8);
520
+ const bitOffset = idx % 8;
521
+ nullBitmap[byteIndex] |= (1 << bitOffset);
522
+ }
523
+ }
524
+ for (const [cleanKey, value] of Object.entries(this._scopedAttributes)) {
525
+ const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
526
+ const columnName = prefixedKey;
527
+ const column = this._buffer[columnName + '_values'];
528
+ if (column) {
529
+ column[idx] = value;
530
+ const nullBitmap = this._buffer[columnName + '_nulls'];
531
+ if (nullBitmap) {
532
+ const byteIndex = Math.floor(idx / 8);
533
+ const bitOffset = idx % 8;
534
+ nullBitmap[byteIndex] |= (1 << bitOffset);
535
+ }
536
+ }
537
+ }
538
+ this._buffer._writeIndex++;
539
+ }
540
+ ` +
541
+ // Generated code: message() generic logging with level string mapping to entry type constants
542
+ `message(level, message) {
543
+ const entryTypeMap = {
544
+ 'info': ${ENTRY_TYPE_INFO},
545
+ 'debug': ${ENTRY_TYPE_DEBUG},
546
+ 'warn': ${ENTRY_TYPE_WARN},
547
+ 'error': ${ENTRY_TYPE_ERROR},
548
+ 'trace': ${ENTRY_TYPE_TRACE}
549
+ };
550
+ this._writeMessage(entryTypeMap[level] || ${ENTRY_TYPE_INFO}, message);
551
+ }
552
+ ` +
553
+ // Generated code: convenience logging methods - each calls _writeMessage with entry type constant
554
+ `info(message) { this._writeMessage(${ENTRY_TYPE_INFO}, message); }
555
+ debug(message) { this._writeMessage(${ENTRY_TYPE_DEBUG}, message); }
556
+ warn(message) { this._writeMessage(${ENTRY_TYPE_WARN}, message); }
557
+ error(message) { this._writeMessage(${ENTRY_TYPE_ERROR}, message); }
558
+ trace(message) { this._writeMessage(${ENTRY_TYPE_TRACE}, message); }
559
+ }
560
+ return ${className};
561
+ })()`;
562
+ return classCode;
563
+ }
564
+ /**
565
+ * Create a remapped SpanLogger class constructor from clean schema and prefix mapping
566
+ *
567
+ * WHY: This is the cold-path function called at module creation time. It compiles
568
+ * the generated class code once and caches the constructor.
569
+ *
570
+ * @param cleanSchema - Clean schema (without prefix)
571
+ * @param prefixMapping - Mapping from clean names to prefixed names
572
+ * @returns Constructor for the remapped SpanLogger class
573
+ */
574
+ export function createRemappedSpanLoggerClass(cleanSchema, prefixMapping) {
575
+ // Check cache first
576
+ const cacheKey = createSchemaAndMappingCacheKey(cleanSchema, prefixMapping);
577
+ const cached = remappedSpanLoggerClassCache.get(cacheKey);
578
+ if (cached && isRemappedSpanLoggerClass(cached)) {
579
+ return cached;
580
+ }
581
+ const classCode = generateRemappedSpanLoggerClass(cleanSchema, prefixMapping).trim();
582
+ const GeneratedClass = new Function(`return ${classCode}`)();
583
+ if (!isRemappedSpanLoggerClass(GeneratedClass)) {
584
+ throw new TypeError('Generated remapped span logger is missing required logging methods');
585
+ }
586
+ remappedSpanLoggerClassCache.set(cacheKey, GeneratedClass);
587
+ return GeneratedClass;
588
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * LogAPI - Simple logging interface for contexts that need structured logging
3
+ * without direct access to a SpanBuffer.
4
+ *
5
+ * Used by:
6
+ * - Other contexts where a simplified logging interface is needed
7
+ *
8
+ * Unlike SpanLogger which is tightly coupled to a SpanBuffer and returns
9
+ * FluentLogEntry for chaining, LogAPI is a simple fire-and-forget interface
10
+ * that can be backed by any logging implementation.
11
+ */
12
+ /**
13
+ * Structured logging API.
14
+ *
15
+ * Provides info/warn/error/debug methods with optional structured data.
16
+ * Implementation determines where logs are written (span buffer, console, etc).
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * function decide(ctx) {
21
+ * ctx.log.info('Processing order', { orderId: ctx.instanceId });
22
+ * if (!ctx.state.inventory) {
23
+ * ctx.log.warn('No inventory data', { state: ctx.state });
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ export interface LogAPI {
29
+ /**
30
+ * Log at info level.
31
+ * @param message - Log message
32
+ * @param data - Optional structured data to include with the log
33
+ */
34
+ info(message: string, data?: Record<string, unknown>): void;
35
+ /**
36
+ * Log at warn level.
37
+ * @param message - Log message
38
+ * @param data - Optional structured data to include with the log
39
+ */
40
+ warn(message: string, data?: Record<string, unknown>): void;
41
+ /**
42
+ * Log at error level.
43
+ * @param message - Log message
44
+ * @param data - Optional structured data to include with the log
45
+ */
46
+ error(message: string, data?: Record<string, unknown>): void;
47
+ /**
48
+ * Log at debug level.
49
+ * @param message - Log message
50
+ * @param data - Optional structured data to include with the log
51
+ */
52
+ debug(message: string, data?: Record<string, unknown>): void;
53
+ }
54
+ /**
55
+ * No-op LogAPI implementation.
56
+ *
57
+ * Used when tracing is disabled or for testing contexts that don't
58
+ * need actual logging.
59
+ */
60
+ export declare const noopLogAPI: LogAPI;
61
+ //# sourceMappingURL=logApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logApi.d.ts","sourceRoot":"","sources":["../../src/lib/logApi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE5D;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE5D;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE7D;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,MAKxB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * No-op LogAPI implementation.
3
+ *
4
+ * Used when tracing is disabled or for testing contexts that don't
5
+ * need actual logging.
6
+ */
7
+ export const noopLogAPI = {
8
+ info: () => { },
9
+ warn: () => { },
10
+ error: () => { },
11
+ debug: () => { },
12
+ };