@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,339 @@
1
+ /**
2
+ * System schema - base columns that all modules inherit
3
+ *
4
+ * Per specs/lmao/01h_entry_types_and_logging_primitives.md and 01f_arrow_table_structure.md:
5
+ * - These columns are available in all traces regardless of user schema
6
+ * - The `message` column is UNIFIED for span names, log message templates, exception messages, result messages, and feature flag names
7
+ */
8
+
9
+ import type {
10
+ EagerCategorySchema,
11
+ LazyBigUint64Schema,
12
+ LazyCategorySchema,
13
+ LazyNumberSchema,
14
+ LazyTextSchema,
15
+ } from '@smoothbricks/arrow-builder';
16
+ import { S as ArrowS } from '@smoothbricks/arrow-builder';
17
+ import { type DefinedLogSchema, defineLogSchema } from './defineLogSchema.js';
18
+ import { LogSchema, type Schema } from './types.js';
19
+
20
+ /**
21
+ * System schema field type - explicit type to avoid Sury's internal brand symbol leaking.
22
+ */
23
+ export interface SystemSchemaFieldTypes extends Record<string, Schema<unknown>> {
24
+ message: EagerCategorySchema;
25
+ line: LazyNumberSchema;
26
+ error_code: LazyCategorySchema;
27
+ retry_attempt: LazyNumberSchema;
28
+ retry_delay_ms: LazyNumberSchema;
29
+ exception_stack: LazyTextSchema;
30
+ ff_value: LazyCategorySchema;
31
+ uint64_value: LazyBigUint64Schema;
32
+ }
33
+
34
+ // Use arrow-builder's S directly (not lmao's wrapped version) to get clean types
35
+ // that don't include the flag builder methods - this avoids type inference issues.
36
+ const messageSchema: EagerCategorySchema = ArrowS.category().eager();
37
+ const lineSchema: LazyNumberSchema = ArrowS.number();
38
+ const errorCodeSchema: LazyCategorySchema = ArrowS.category();
39
+ const retryAttemptSchema: LazyNumberSchema = ArrowS.number();
40
+ const retryDelayMsSchema: LazyNumberSchema = ArrowS.number();
41
+ const exceptionStackSchema: LazyTextSchema = ArrowS.text();
42
+ const ffValueSchema: LazyCategorySchema = ArrowS.category();
43
+ const uint64ValueSchema: LazyBigUint64Schema = ArrowS.bigUint64();
44
+
45
+ /**
46
+ * Raw system schema fields object.
47
+ * Using explicit type annotation to ensure proper type inference.
48
+ */
49
+ /**
50
+ * System schema field names - used to filter out system fields when processing user schema
51
+ * These fields are handled separately in Arrow conversion and should not be included
52
+ * in the user attribute columns.
53
+ */
54
+ export const SYSTEM_SCHEMA_FIELD_NAMES = new Set([
55
+ 'message',
56
+ 'line',
57
+ 'error_code',
58
+ 'retry_attempt',
59
+ 'retry_delay_ms',
60
+ 'exception_stack',
61
+ 'ff_value',
62
+ 'uint64_value',
63
+ ]);
64
+
65
+ /**
66
+ * Reserved system column names - these correspond to Arrow table columns and cannot be
67
+ * used as user schema field names because they conflict with SpanBuffer properties.
68
+ */
69
+ export const RESERVED_SYSTEM_COLUMN_NAMES = new Set([
70
+ // Arrow table columns (exact names)
71
+ 'trace_id',
72
+ 'thread_id',
73
+ 'span_id',
74
+ 'parent_thread_id',
75
+ 'parent_span_id',
76
+ 'timestamp',
77
+ 'entry_type',
78
+ ]);
79
+
80
+ const systemSchemaFields: SystemSchemaFieldTypes = {
81
+ /**
82
+ * Unified message column - serves different purposes based on entry type.
83
+ *
84
+ * Per specs/lmao/01h_entry_types_and_logging_primitives.md:
85
+ * - span-start, span-ok, span-err: Span name (e.g., 'create-user')
86
+ * - span-exception: Exception message (e.g., 'Connection timeout')
87
+ * - info, debug, warn, error, trace: Log message TEMPLATE (e.g., 'User ${userId} created')
88
+ * - ff-access, ff-usage: Feature flag name (e.g., 'darkMode')
89
+ * - tag: Span name (same as span lifecycle entries)
90
+ *
91
+ * Uses S.category().eager() because:
92
+ * - Message is ALWAYS written for every entry type (span name, log message, etc.)
93
+ * - Eager allocation eliminates null bitmap overhead (never null)
94
+ * - Span names repeat across many traces
95
+ * - Log templates repeat (only values differ)
96
+ * - Flag names repeat across evaluations
97
+ * - Exception messages often repeat (same error types)
98
+ * - String interning provides excellent compression
99
+ *
100
+ * NOTE: Log messages are FORMAT STRINGS, NOT interpolated! The template is stored
101
+ * verbatim, and values go in their own typed columns for queryability.
102
+ */
103
+ message: messageSchema,
104
+
105
+ /**
106
+ * Source code line number for this entry.
107
+ *
108
+ * Per specs/lmao/01c_context_flow_and_op_wrappers.md "Line Number System":
109
+ * - Uint16 column (max 65535 lines per file)
110
+ * - TypeScript transformer injects line numbers at compile time
111
+ * - No runtime overhead - just a method call with literal number
112
+ * - Value of 0 means "line number not set"
113
+ *
114
+ * Used for:
115
+ * - Linking trace entries back to source code
116
+ * - Debugging and error analysis
117
+ * - IDE integration for "jump to line"
118
+ */
119
+ line: lineSchema,
120
+
121
+ // Error handling
122
+ error_code: errorCodeSchema,
123
+ retry_attempt: retryAttemptSchema,
124
+ retry_delay_ms: retryDelayMsSchema,
125
+ exception_stack: exceptionStackSchema,
126
+
127
+ // Feature flags (ffName is now part of unified `message` column)
128
+ ff_value: ffValueSchema, // Can be boolean, string, or number as string
129
+
130
+ /**
131
+ * uint64 value column for metrics and user .uint64() API.
132
+ *
133
+ * Per specs/lmao/01f_arrow_table_structure.md:
134
+ * - Metric values (counts, durations in nanoseconds)
135
+ * - User large integers via .uint64() fluent method
136
+ * - Sparse data (only rows that need uint64)
137
+ *
138
+ * Uses S.bigUint64() (lazy BigUint64Array) because:
139
+ * - Most trace rows don't have a uint64 value
140
+ * - Only metrics rows and entries where .uint64() is called
141
+ * - Zero overhead for rows that don't use it
142
+ */
143
+ uint64_value: uint64ValueSchema,
144
+ };
145
+
146
+ /**
147
+ * Base system schema that all modules inherit.
148
+ * Wrapped with defineLogSchema for validation and extension support.
149
+ */
150
+ export const systemSchema: DefinedLogSchema<SystemSchemaFieldTypes> = defineLogSchema(
151
+ systemSchemaFields,
152
+ // Skip reserved name validation for system schema - `message` is a system column
153
+ { _skipReservedNameValidation: true },
154
+ );
155
+
156
+ /**
157
+ * Merge system schema with user schema
158
+ * System columns are always included, user schema extends them
159
+ *
160
+ * Warns if user schema conflicts with system schema fields or reserved column names.
161
+ */
162
+ export function mergeWithSystemSchema<T extends Record<string, unknown>>(userSchema: T): SystemSchemaFieldTypes & T {
163
+ // Check for conflicts between user schema and system schema
164
+ // Use fieldNames to get only actual field names, not ColumnSchema properties or methods
165
+ const systemKeys = new Set(systemSchema._columnNames);
166
+ const reservedKeys = RESERVED_SYSTEM_COLUMN_NAMES;
167
+ const userKeys = userSchema instanceof LogSchema ? userSchema._columnNames : Object.keys(userSchema);
168
+ const userFields = userSchema instanceof LogSchema ? userSchema.fields : userSchema;
169
+
170
+ const conflictingSystemKeys = userKeys.filter((key) => {
171
+ // Only check if it's a schema field (not a method like validate/parse/extend)
172
+ const value = userFields[key];
173
+ return systemKeys.has(key) && typeof value !== 'function';
174
+ });
175
+
176
+ const conflictingReservedKeys = userKeys.filter((key) => {
177
+ const value = userFields[key];
178
+ return reservedKeys.has(key) && typeof value !== 'function';
179
+ });
180
+
181
+ if (conflictingSystemKeys.length > 0) {
182
+ throw new Error(
183
+ `User schema conflicts with system schema fields: ${conflictingSystemKeys.join(', ')}\n` +
184
+ 'System schema fields are reserved and cannot be overridden.\n' +
185
+ `System fields: ${Array.from(systemKeys).join(', ')}`,
186
+ );
187
+ }
188
+
189
+ if (conflictingReservedKeys.length > 0) {
190
+ throw new Error(
191
+ `User schema cannot include reserved system column names: ${conflictingReservedKeys.join(', ')}\n` +
192
+ ' These names conflict with SpanBuffer properties that correspond to Arrow table columns.\n' +
193
+ ` Reserved names: ${Array.from(reservedKeys).join(', ')}`,
194
+ );
195
+ }
196
+
197
+ // Spread .fields to get the actual schema field definitions
198
+ // (spreading systemSchema directly would spread class instance properties like _fieldNames, not schema fields)
199
+ const merged: SystemSchemaFieldTypes & T = {
200
+ ...systemSchema.fields,
201
+ ...userFields,
202
+ };
203
+ return merged;
204
+ }
205
+
206
+ // =============================================================================
207
+ // Entry Type Constants
208
+ // =============================================================================
209
+ // Per specs/lmao/01h_entry_types_and_logging_primitives.md
210
+ // Stored in Uint8Array for 1-byte storage per entry.
211
+ // Ordered by frequency/importance:
212
+ // 1-4: Span lifecycle (most common - every span has start + end)
213
+ // 5-9: Logging levels (ordered by verbosity: trace < debug < info < warn < error)
214
+ // 10-11: Feature flags (least common)
215
+ // =============================================================================
216
+
217
+ /** Span start event - written at row 0 when a span begins */
218
+ export const ENTRY_TYPE_SPAN_START = 1;
219
+
220
+ /** Span success completion - written to row 1 via ctx.ok() */
221
+ export const ENTRY_TYPE_SPAN_OK = 2;
222
+
223
+ /** Span error completion - written to row 1 via ctx.err() */
224
+ export const ENTRY_TYPE_SPAN_ERR = 3;
225
+
226
+ /** Span exception - written to row 1 when an unhandled exception occurs */
227
+ export const ENTRY_TYPE_SPAN_EXCEPTION = 4;
228
+
229
+ /** Span retry - written when a transient failure triggers a retry attempt (Phase 19) */
230
+ export const ENTRY_TYPE_SPAN_RETRY = 5;
231
+
232
+ /** Trace log level entry - via ctx.log.trace() (most verbose) */
233
+ export const ENTRY_TYPE_TRACE = 6;
234
+
235
+ /** Debug log level entry - via ctx.log.debug() */
236
+ export const ENTRY_TYPE_DEBUG = 7;
237
+
238
+ /** Info log level entry - via ctx.log.info() */
239
+ export const ENTRY_TYPE_INFO = 8;
240
+
241
+ /** Warning log level entry - via ctx.log.warn() */
242
+ export const ENTRY_TYPE_WARN = 9;
243
+
244
+ /** Error log level entry - via ctx.log.error() */
245
+ export const ENTRY_TYPE_ERROR = 10;
246
+
247
+ /** Feature flag access event - logged when a flag value is first read in a span */
248
+ export const ENTRY_TYPE_FF_ACCESS = 11;
249
+
250
+ /** Feature flag usage event - logged when a flag influences a code path decision */
251
+ export const ENTRY_TYPE_FF_USAGE = 12;
252
+
253
+ // =============================================================================
254
+ // Period Markers
255
+ // =============================================================================
256
+
257
+ /** Period start marker - written at the beginning of each metrics collection period */
258
+ export const ENTRY_TYPE_PERIOD_START = 13;
259
+
260
+ // =============================================================================
261
+ // Op Metrics (per specs/lmao/01n_op_and_buffer_metrics.md)
262
+ // =============================================================================
263
+
264
+ /** Op invocations counter - total calls to this operation */
265
+ export const ENTRY_TYPE_OP_INVOCATIONS = 14;
266
+
267
+ /** Op errors counter - calls that returned err() */
268
+ export const ENTRY_TYPE_OP_ERRORS = 15;
269
+
270
+ /** Op exceptions counter - calls that threw unhandled exceptions */
271
+ export const ENTRY_TYPE_OP_EXCEPTIONS = 16;
272
+
273
+ /** Op duration total - sum of all invocation durations (ms) */
274
+ export const ENTRY_TYPE_OP_DURATION_TOTAL = 17;
275
+
276
+ /** Op duration ok - sum of successful invocation durations (ms) */
277
+ export const ENTRY_TYPE_OP_DURATION_OK = 18;
278
+
279
+ /** Op duration err - sum of error invocation durations (ms) */
280
+ export const ENTRY_TYPE_OP_DURATION_ERR = 19;
281
+
282
+ /** Op duration min - minimum invocation duration (ms) */
283
+ export const ENTRY_TYPE_OP_DURATION_MIN = 20;
284
+
285
+ /** Op duration max - maximum invocation duration (ms) */
286
+ export const ENTRY_TYPE_OP_DURATION_MAX = 21;
287
+
288
+ // =============================================================================
289
+ // Buffer Metrics (utilization-based capacity tuning)
290
+ // =============================================================================
291
+
292
+ /** Buffer writes counter - total writes across all buffers */
293
+ export const ENTRY_TYPE_BUFFER_WRITES = 22;
294
+
295
+ /** Buffer spans counter - number of spans created (non-overflow buffers) */
296
+ export const ENTRY_TYPE_BUFFER_SPANS = 23;
297
+
298
+ /** Buffer capacity - current buffer capacity for this module */
299
+ export const ENTRY_TYPE_BUFFER_CAPACITY = 24;
300
+
301
+ /**
302
+ * Human-readable names for entry types, indexed by entry type code.
303
+ *
304
+ * Used for Arrow dictionary encoding and display purposes.
305
+ * Index 0 is unused (entry types start at 1).
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * const entryType = buffer.entry_type[index];
310
+ * const typeName = ENTRY_TYPE_NAMES[entryType]; // e.g., 'span-ok'
311
+ * ```
312
+ */
313
+ export const ENTRY_TYPE_NAMES = [
314
+ '', // 0 - unused
315
+ 'span-start', // 1
316
+ 'span-ok', // 2
317
+ 'span-err', // 3
318
+ 'span-exception', // 4
319
+ 'span-retry', // 5 (Phase 19 - transient failure retry)
320
+ 'trace', // 6 (most verbose)
321
+ 'debug', // 7
322
+ 'info', // 8
323
+ 'warn', // 9
324
+ 'error', // 10
325
+ 'ff-access', // 11
326
+ 'ff-usage', // 12
327
+ 'period-start', // 13
328
+ 'op-invocations', // 14
329
+ 'op-errors', // 15
330
+ 'op-exceptions', // 16
331
+ 'op-duration-total', // 17
332
+ 'op-duration-ok', // 18
333
+ 'op-duration-err', // 19
334
+ 'op-duration-min', // 20
335
+ 'op-duration-max', // 21
336
+ 'buffer-writes', // 22
337
+ 'buffer-spans', // 23
338
+ 'buffer-capacity', // 24
339
+ ] as const;
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Type guard functions for runtime type checking
3
+ *
4
+ * Re-exports schema type guards from arrow-builder and adds lmao-specific guards.
5
+ */
6
+
7
+ // Re-export schema type guards from arrow-builder
8
+ export {
9
+ getBinaryEncoder,
10
+ getEnumUtf8,
11
+ getEnumValues,
12
+ getSchemaType,
13
+ isEnumSchema,
14
+ isSchemaWithMetadata,
15
+ } from '@smoothbricks/arrow-builder';
16
+
17
+ import type { EvaluationContext, UsageContext } from './defineFeatureFlags.js';
18
+ import type { FeatureFlagDefinition } from './types.js';
19
+
20
+ /** Narrow unknown to Record<string, unknown> — non-null object with string-keyed access. */
21
+ export function isRecord(value: unknown): value is Record<string, unknown> {
22
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
23
+ }
24
+
25
+ /**
26
+ * Type guard to check if a value is a FeatureFlagDefinition
27
+ */
28
+ export function isFeatureFlagDefinition(value: unknown): value is FeatureFlagDefinition<string | number | boolean> {
29
+ if (!isRecord(value)) {
30
+ return false;
31
+ }
32
+
33
+ return (
34
+ 'schema' in value &&
35
+ 'defaultValue' in value &&
36
+ 'evaluationType' in value &&
37
+ (value.evaluationType === 'sync' || value.evaluationType === 'async')
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Type guard to check if a value is a valid EvaluationContext
43
+ */
44
+ export function isEvaluationContext(value: unknown): value is EvaluationContext {
45
+ if (!isRecord(value)) {
46
+ return false;
47
+ }
48
+
49
+ // EvaluationContext can have various string/number/boolean properties
50
+ // Check that all values are of valid types
51
+ for (const key in value) {
52
+ const val = value[key];
53
+ if (val !== undefined && typeof val !== 'string' && typeof val !== 'number' && typeof val !== 'boolean') {
54
+ return false;
55
+ }
56
+ }
57
+
58
+ return true;
59
+ }
60
+
61
+ /**
62
+ * Type guard to check if a value is a valid UsageContext
63
+ */
64
+ export function isUsageContext(value: unknown): value is UsageContext {
65
+ if (!isRecord(value)) {
66
+ return false;
67
+ }
68
+
69
+ // Check action property if present
70
+ if ('action' in value && typeof value.action !== 'string' && value.action !== undefined) {
71
+ return false;
72
+ }
73
+
74
+ // Check outcome property if present
75
+ if ('outcome' in value && value.outcome !== undefined && value.outcome !== 'success' && value.outcome !== 'failure') {
76
+ return false;
77
+ }
78
+
79
+ // Check value property if present
80
+ if ('value' in value && typeof value.value !== 'number' && value.value !== undefined) {
81
+ return false;
82
+ }
83
+
84
+ // Check metadata property if present
85
+ if ('metadata' in value && value.metadata !== undefined) {
86
+ if (!isRecord(value.metadata)) {
87
+ return false;
88
+ }
89
+
90
+ // Validate metadata values
91
+ const metadata = value.metadata;
92
+ for (const key in metadata) {
93
+ const val = metadata[key];
94
+ if (typeof val !== 'string' && typeof val !== 'number' && typeof val !== 'boolean') {
95
+ return false;
96
+ }
97
+ }
98
+ }
99
+
100
+ return true;
101
+ }
102
+
103
+ /**
104
+ * Type guard to check if a value is a string
105
+ * Useful for narrowing unknown types in safe contexts
106
+ */
107
+ export function isString(value: unknown): value is string {
108
+ return typeof value === 'string';
109
+ }
110
+
111
+ /**
112
+ * Type guard to check if a value is a number
113
+ * Useful for narrowing unknown types in safe contexts
114
+ */
115
+ export function isNumber(value: unknown): value is number {
116
+ return typeof value === 'number' && !Number.isNaN(value);
117
+ }
118
+
119
+ /**
120
+ * Type guard to check if a value is a boolean
121
+ * Useful for narrowing unknown types in safe contexts
122
+ */
123
+ export function isBoolean(value: unknown): value is boolean {
124
+ return typeof value === 'boolean';
125
+ }
126
+
127
+ /**
128
+ * Type guard to check if a value is a primitive type (string | number | boolean)
129
+ * Useful for validating feature flag values and tag attributes
130
+ */
131
+ export function isPrimitive(value: unknown): value is string | number | boolean {
132
+ return isString(value) || isNumber(value) || isBoolean(value);
133
+ }
134
+
135
+ /**
136
+ * Type guard to check if a value is a plain object (not array, not null)
137
+ */
138
+ export function isPlainObject(value: unknown): value is Record<string, unknown> {
139
+ return (
140
+ typeof value === 'object' &&
141
+ value !== null &&
142
+ !Array.isArray(value) &&
143
+ Object.getPrototypeOf(value) === Object.prototype
144
+ );
145
+ }
146
+
147
+ /**
148
+ * Type guard to check if a value is a valid record with primitive values
149
+ * Useful for validating tag attribute objects
150
+ */
151
+ export function isRecordOfPrimitives(value: unknown): value is Record<string, string | number | boolean> {
152
+ if (!isPlainObject(value)) {
153
+ return false;
154
+ }
155
+
156
+ for (const key in value) {
157
+ if (!isPrimitive(value[key])) {
158
+ return false;
159
+ }
160
+ }
161
+
162
+ return true;
163
+ }