@smoothbricks/lmao 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +206 -206
- package/dist/allocator.wasm +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/JsBufferStrategy.d.ts +4 -3
- package/dist/lib/JsBufferStrategy.d.ts.map +1 -1
- package/dist/lib/JsBufferStrategy.js +18 -11
- package/dist/lib/arrow/lease.d.ts +10 -0
- package/dist/lib/arrow/lease.d.ts.map +1 -0
- package/dist/lib/arrow/lease.js +33 -0
- package/dist/lib/arrow/utils.d.ts +3 -4
- package/dist/lib/arrow/utils.d.ts.map +1 -1
- package/dist/lib/arrow/utils.js +12 -13
- package/dist/lib/arrow/vocabularyDictionary.d.ts +21 -0
- package/dist/lib/arrow/vocabularyDictionary.d.ts.map +1 -0
- package/dist/lib/arrow/vocabularyDictionary.js +95 -0
- package/dist/lib/bufferStrategy.d.ts +3 -2
- package/dist/lib/bufferStrategy.d.ts.map +1 -1
- package/dist/lib/cloudflare/traceRows.d.ts.map +1 -1
- package/dist/lib/cloudflare/traceRows.js +3 -2
- package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/evaluatorGenerator.js +12 -11
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +44 -82
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/fixedPositionWriterGenerator.js +223 -162
- package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts +63 -0
- package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts.map +1 -0
- package/dist/lib/codegen/spanLoggerClosureMaterializer.js +447 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts +36 -19
- package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/spanLoggerGenerator.js +164 -158
- package/dist/lib/convertToArrow.d.ts +7 -2
- package/dist/lib/convertToArrow.d.ts.map +1 -1
- package/dist/lib/convertToArrow.js +499 -285
- package/dist/lib/defineOpContext.js +1 -1
- package/dist/lib/enumMetadata.d.ts +19 -0
- package/dist/lib/enumMetadata.d.ts.map +1 -0
- package/dist/lib/enumMetadata.js +86 -0
- package/dist/lib/flushScheduler.d.ts.map +1 -1
- package/dist/lib/flushScheduler.js +13 -4
- package/dist/lib/library.d.ts +16 -98
- package/dist/lib/library.d.ts.map +1 -1
- package/dist/lib/library.js +32 -525
- package/dist/lib/logBinding.d.ts +21 -27
- package/dist/lib/logBinding.d.ts.map +1 -1
- package/dist/lib/op.d.ts +30 -30
- package/dist/lib/op.d.ts.map +1 -1
- package/dist/lib/op.js +15 -22
- package/dist/lib/opContext/createOpGroup.d.ts +1 -1
- package/dist/lib/opContext/createOpGroup.d.ts.map +1 -1
- package/dist/lib/opContext/createOpGroup.js +22 -29
- package/dist/lib/opContext/defineOp.d.ts +4 -4
- package/dist/lib/opContext/defineOp.d.ts.map +1 -1
- package/dist/lib/opContext/defineOp.js +53 -10
- package/dist/lib/opContext/opGroupTypes.d.ts +2 -2
- package/dist/lib/opContext/opTypes.d.ts +1 -1
- package/dist/lib/opContext/opTypes.d.ts.map +1 -1
- package/dist/lib/opContext/spanContextTypes.d.ts +33 -18
- package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -1
- package/dist/lib/opContext/types.d.ts +4 -4
- package/dist/lib/opContext/types.d.ts.map +1 -1
- package/dist/lib/physicalLayoutPlan.d.ts +89 -0
- package/dist/lib/physicalLayoutPlan.d.ts.map +1 -0
- package/dist/lib/physicalLayoutPlan.js +442 -0
- package/dist/lib/resolveMessage.d.ts +9 -0
- package/dist/lib/resolveMessage.d.ts.map +1 -0
- package/dist/lib/resolveMessage.js +63 -0
- package/dist/lib/result.d.ts +5 -7
- package/dist/lib/result.d.ts.map +1 -1
- package/dist/lib/result.js +19 -26
- package/dist/lib/runtimeHint.d.ts +35 -0
- package/dist/lib/runtimeHint.d.ts.map +1 -0
- package/dist/lib/runtimeHint.js +79 -0
- package/dist/lib/schema/typeGuards.d.ts +7 -47
- package/dist/lib/schema/typeGuards.d.ts.map +1 -1
- package/dist/lib/schema/typeGuards.js +7 -123
- package/dist/lib/schema/types.d.ts +1 -1
- package/dist/lib/schema/types.d.ts.map +1 -1
- package/dist/lib/span-buffer/aot/v1.d.ts +2 -0
- package/dist/lib/span-buffer/aot/v1.d.ts.map +1 -0
- package/dist/lib/span-buffer/aot/v1.js +24 -0
- package/dist/lib/spanBuffer.d.ts +33 -4
- package/dist/lib/spanBuffer.d.ts.map +1 -1
- package/dist/lib/spanBuffer.js +583 -91
- package/dist/lib/spanBufferStats.d.ts +1 -1
- package/dist/lib/spanBufferStats.d.ts.map +1 -1
- package/dist/lib/spanContext.d.ts +27 -51
- package/dist/lib/spanContext.d.ts.map +1 -1
- package/dist/lib/spanContext.js +822 -344
- package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -1
- package/dist/lib/sqlite/sqlite-common.js +20 -21
- package/dist/lib/testing/bun-harness.d.ts +8 -3
- package/dist/lib/testing/bun-harness.d.ts.map +1 -1
- package/dist/lib/testing/bun-harness.js +30 -18
- package/dist/lib/testing/extractFacts.d.ts +1 -1
- package/dist/lib/testing/extractFacts.d.ts.map +1 -1
- package/dist/lib/testing/extractFacts.js +55 -63
- package/dist/lib/testing/facts.d.ts +1 -1
- package/dist/lib/testing/facts.d.ts.map +1 -1
- package/dist/lib/testing/queryable-span.d.ts +1 -1
- package/dist/lib/testing/queryable-span.d.ts.map +1 -1
- package/dist/lib/testing/queryable-span.js +26 -28
- package/dist/lib/testing/span-query.d.ts.map +1 -1
- package/dist/lib/testing/span-query.js +19 -22
- package/dist/lib/testing/stdio-replay.d.ts.map +1 -1
- package/dist/lib/testing/stdio-replay.js +19 -8
- package/dist/lib/threadId.d.ts.map +1 -1
- package/dist/lib/threadId.js +6 -3
- package/dist/lib/traceContext.d.ts.map +1 -1
- package/dist/lib/traceContext.js +1 -4
- package/dist/lib/traceRoot.d.ts +30 -8
- package/dist/lib/traceRoot.d.ts.map +1 -1
- package/dist/lib/traceRoot.es.d.ts +17 -15
- package/dist/lib/traceRoot.es.d.ts.map +1 -1
- package/dist/lib/traceRoot.es.js +68 -34
- package/dist/lib/traceRoot.js +11 -0
- package/dist/lib/traceRoot.node.d.ts +17 -19
- package/dist/lib/traceRoot.node.d.ts.map +1 -1
- package/dist/lib/traceRoot.node.js +66 -38
- package/dist/lib/traceTopology.d.ts +42 -0
- package/dist/lib/traceTopology.d.ts.map +1 -0
- package/dist/lib/traceTopology.js +260 -0
- package/dist/lib/tracer.d.ts +9 -5
- package/dist/lib/tracer.d.ts.map +1 -1
- package/dist/lib/tracer.js +65 -71
- package/dist/lib/tracers/ArrayQueueTracer.d.ts +1 -1
- package/dist/lib/tracers/ArrayQueueTracer.js +1 -1
- package/dist/lib/tracers/StdioTracer.d.ts.map +1 -1
- package/dist/lib/tracers/StdioTracer.js +15 -13
- package/dist/lib/tracers/TestTracer.d.ts +4 -6
- package/dist/lib/tracers/TestTracer.d.ts.map +1 -1
- package/dist/lib/tracers/TestTracer.js +6 -8
- package/dist/lib/types.d.ts +49 -32
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/vocabularyRegistry.d.ts +25 -0
- package/dist/lib/vocabularyRegistry.d.ts.map +1 -0
- package/dist/lib/vocabularyRegistry.js +372 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts +6 -10
- package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -1
- package/dist/lib/wasm/WasmBufferStrategy.js +44 -37
- package/dist/lib/wasm/wasmAllocator.d.ts +27 -22
- package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -1
- package/dist/lib/wasm/wasmAllocator.js +66 -44
- package/dist/lib/wasm/wasmPhysicalLayout.d.ts +67 -0
- package/dist/lib/wasm/wasmPhysicalLayout.d.ts.map +1 -0
- package/dist/lib/wasm/wasmPhysicalLayout.js +179 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts +79 -31
- package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -1
- package/dist/lib/wasm/wasmSpanBuffer.js +442 -272
- package/dist/lib/wasm/wasmTraceRoot.d.ts +24 -22
- package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -1
- package/dist/lib/wasm/wasmTraceRoot.js +110 -71
- package/dist/vocabulary/register/v1.d.ts +2 -0
- package/dist/vocabulary/register/v1.d.ts.map +1 -0
- package/dist/vocabulary/register/v1.js +1 -0
- package/dist/wasm.d.ts +5 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +4 -0
- package/package.json +54 -6
- package/src/index.ts +1 -0
- package/src/lib/JsBufferStrategy.ts +27 -9
- package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +335 -37
- package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +97 -26
- package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +75 -15
- package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +30 -6
- package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +18 -21
- package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +5 -2
- package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +25 -7
- package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +3 -2
- package/src/lib/__tests__/buffer-overflow.test.ts +24 -18
- package/src/lib/__tests__/capability-span-context.test.ts +505 -0
- package/src/lib/__tests__/capacity-tuning.test.ts +5 -3
- package/src/lib/__tests__/eager-columns.test.ts +345 -0
- package/src/lib/__tests__/enum-metadata-aot.test.ts +153 -0
- package/src/lib/__tests__/enum-metadata.test.ts +177 -0
- package/src/lib/__tests__/fixtures/empty-vocabulary-runtime.fixture.ts +15 -0
- package/src/lib/__tests__/flushScheduler.test.ts +5 -1
- package/src/lib/__tests__/identity-view.property.test.ts +179 -0
- package/src/lib/__tests__/library.test.ts +19 -235
- package/src/lib/__tests__/message-buffer-families.test.ts +878 -0
- package/src/lib/__tests__/nested-library-tasks.test.ts +14 -15
- package/src/lib/__tests__/op-metadata.test.ts +1 -1
- package/src/lib/__tests__/op-type-safety.test.ts +5 -16
- package/src/lib/__tests__/physical-layout-plan.test.ts +333 -0
- package/src/lib/__tests__/remap-descriptor-integration.test.ts +381 -0
- package/src/lib/__tests__/root-context-construction.test.ts +414 -0
- package/src/lib/__tests__/span-auto-runtime.test.ts +386 -0
- package/src/lib/__tests__/span-buffer-segment-stats.test.ts +221 -0
- package/src/lib/__tests__/span-lifecycle.test.ts +53 -25
- package/src/lib/__tests__/spanbuffer-materializer-parity.test.ts +266 -0
- package/src/lib/__tests__/sync-async-trace.test.ts +24 -23
- package/src/lib/__tests__/tag-writer-aot.test.ts +214 -0
- package/src/lib/__tests__/test-helpers.ts +67 -12
- package/src/lib/__tests__/threadId.test.ts +62 -0
- package/src/lib/__tests__/timestamp.test.ts +221 -93
- package/src/lib/__tests__/traceTopology.property.test.ts +383 -0
- package/src/lib/__tests__/type-narrowing.test.ts +63 -0
- package/src/lib/__tests__/vocabulary-dense-decoding.test.ts +405 -0
- package/src/lib/__tests__/vocabularyRegistry.test.ts +313 -0
- package/src/lib/arrow/lease.ts +43 -0
- package/src/lib/arrow/utils.ts +10 -14
- package/src/lib/arrow/vocabularyDictionary.ts +123 -0
- package/src/lib/bufferStrategy.ts +9 -1
- package/src/lib/cloudflare/traceRows.ts +3 -2
- package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +21 -141
- package/src/lib/codegen/__tests__/fixedPositionWriter-parity.test.ts +273 -0
- package/src/lib/codegen/__tests__/fixedPositionWriter-uint64.test.ts +61 -34
- package/src/lib/codegen/__tests__/nullBitmap.test.ts +33 -37
- package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +34 -18
- package/src/lib/codegen/__tests__/spanLoggerMaterializerParity.test.ts +503 -0
- package/src/lib/codegen/evaluatorGenerator.ts +18 -13
- package/src/lib/codegen/fixedPositionWriterGenerator.ts +329 -245
- package/src/lib/codegen/spanLoggerClosureMaterializer.ts +598 -0
- package/src/lib/codegen/spanLoggerGenerator.ts +241 -177
- package/src/lib/convertToArrow.ts +598 -311
- package/src/lib/defineOpContext.ts +1 -1
- package/src/lib/enumMetadata.ts +121 -0
- package/src/lib/flushScheduler.ts +11 -5
- package/src/lib/library.ts +37 -595
- package/src/lib/logBinding.ts +21 -27
- package/src/lib/op.ts +75 -18
- package/src/lib/opContext/__tests__/retry.test.ts +27 -21
- package/src/lib/opContext/createOpGroup.ts +33 -31
- package/src/lib/opContext/defineOp.ts +88 -11
- package/src/lib/opContext/opGroupTypes.ts +2 -2
- package/src/lib/opContext/opTypes.ts +1 -1
- package/src/lib/opContext/spanContextTypes.ts +122 -24
- package/src/lib/opContext/types.ts +7 -3
- package/src/lib/physicalLayoutPlan.ts +598 -0
- package/src/lib/resolveMessage.ts +67 -0
- package/src/lib/result.ts +20 -33
- package/src/lib/runtimeHint.ts +98 -0
- package/src/lib/schema/__tests__/featureFlags.test.ts +2 -1
- package/src/lib/schema/builder.ts +1 -1
- package/src/lib/schema/typeGuards.ts +7 -151
- package/src/lib/schema/types.ts +1 -1
- package/src/lib/span-buffer/aot/v1.ts +26 -0
- package/src/lib/spanBuffer.ts +658 -92
- package/src/lib/spanBufferStats.ts +1 -1
- package/src/lib/spanContext.ts +1350 -861
- package/src/lib/sqlite/sqlite-common.ts +20 -31
- package/src/lib/testing/__tests__/topology-traversal.test.ts +174 -0
- package/src/lib/testing/__tests__/vitest-harness.test.ts +2 -1
- package/src/lib/testing/bun-harness.ts +94 -43
- package/src/lib/testing/extractFacts.ts +64 -78
- package/src/lib/testing/facts.ts +1 -1
- package/src/lib/testing/queryable-span.ts +23 -30
- package/src/lib/testing/span-query.ts +16 -20
- package/src/lib/testing/stdio-replay.ts +25 -8
- package/src/lib/testing/vitest-harness.ts +1 -1
- package/src/lib/threadId.ts +6 -3
- package/src/lib/traceContext.ts +1 -6
- package/src/lib/traceRoot.es.ts +77 -42
- package/src/lib/traceRoot.node.ts +75 -46
- package/src/lib/traceRoot.ts +41 -14
- package/src/lib/traceTopology.ts +279 -0
- package/src/lib/tracer.ts +109 -98
- package/src/lib/tracers/ArrayQueueTracer.ts +1 -1
- package/src/lib/tracers/StdioTracer.ts +15 -13
- package/src/lib/tracers/TestTracer.ts +6 -8
- package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +15 -10
- package/src/lib/tracers/__tests__/CompositeTracer.test.ts +150 -0
- package/src/lib/tracers/__tests__/TestTracer.test.ts +23 -13
- package/src/lib/types.ts +64 -33
- package/src/lib/vocabularyRegistry.ts +439 -0
- package/src/lib/wasm/WasmBufferStrategy.ts +56 -48
- package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +215 -11
- package/src/lib/wasm/__tests__/allocatorFreeBlockClamp.test.ts +86 -0
- package/src/lib/wasm/__tests__/wasm-identity-view.test.ts +311 -0
- package/src/lib/wasm/__tests__/wasm-integration.test.ts +417 -44
- package/src/lib/wasm/__tests__/wasm-message-buffer-families.test.ts +588 -0
- package/src/lib/wasm/__tests__/wasmAllocator.test.ts +100 -668
- package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +419 -63
- package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +24 -29
- package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +2 -2
- package/src/lib/wasm/wasmAllocator.ts +131 -96
- package/src/lib/wasm/wasmPhysicalLayout.ts +309 -0
- package/src/lib/wasm/wasmSpanBuffer.ts +597 -341
- package/src/lib/wasm/wasmTraceRoot.ts +140 -78
- package/src/vocabulary/register/v1.ts +1 -0
- package/src/wasm.ts +19 -0
- package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +0 -319
- package/src/lib/__tests__/remapped-buffer-view.test.ts +0 -635
- package/src/lib/wasm/allocator.zig +0 -948
package/src/lib/result.ts
CHANGED
|
@@ -31,9 +31,8 @@
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import {
|
|
34
|
+
import type { ResultWriter, WriterState } from './codegen/fixedPositionWriterGenerator.js';
|
|
35
35
|
import type { InferSchema, LogSchema } from './schema/types.js';
|
|
36
|
-
import type { AnySpanBuffer } from './types.js';
|
|
37
36
|
|
|
38
37
|
// =============================================================================
|
|
39
38
|
// TAGGED ERROR INTERFACE
|
|
@@ -68,20 +67,10 @@ type BoundResultWriter<T extends LogSchema, R, E> = ResultWriter<T, R, E>;
|
|
|
68
67
|
|
|
69
68
|
function ensureResultWriter<T extends LogSchema, R, E>(
|
|
70
69
|
writer: BoundResultWriter<T, R, E> | undefined,
|
|
71
|
-
|
|
72
|
-
buffer: AnySpanBuffer | undefined,
|
|
73
|
-
resultOrError: R | E,
|
|
74
|
-
isError: boolean,
|
|
70
|
+
state: WriterState | undefined,
|
|
75
71
|
): BoundResultWriter<T, R, E> | undefined {
|
|
76
|
-
if (writer)
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!schema || !buffer) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return createResultWriter<T, R, E>(schema, buffer, resultOrError, isError);
|
|
72
|
+
if (writer || !state) return writer;
|
|
73
|
+
return new state._physicalLayoutPlan.ResultWriterClass<T, R, E>(state);
|
|
85
74
|
}
|
|
86
75
|
|
|
87
76
|
function isErrPredicate<E>(value: ErrMatcher<E>): value is ErrPredicate<E> {
|
|
@@ -123,19 +112,18 @@ function createCodeErrorValue<Code extends string, Fields extends object>(
|
|
|
123
112
|
export class Ok<V, T extends LogSchema = LogSchema> {
|
|
124
113
|
readonly value: V;
|
|
125
114
|
|
|
126
|
-
private readonly
|
|
127
|
-
private
|
|
128
|
-
private _writer: BoundResultWriter<T, V, never> | undefined;
|
|
115
|
+
private readonly _state: WriterState | undefined;
|
|
116
|
+
private declare _writer: BoundResultWriter<T, V, never> | undefined;
|
|
129
117
|
|
|
130
|
-
constructor(value: V,
|
|
118
|
+
constructor(value: V, state?: WriterState) {
|
|
131
119
|
this.value = value;
|
|
132
|
-
this.
|
|
133
|
-
this._buffer = buffer;
|
|
120
|
+
this._state = state;
|
|
134
121
|
}
|
|
135
122
|
|
|
136
123
|
private _resultWriter(): BoundResultWriter<T, V, never> | undefined {
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
const writer = ensureResultWriter<T, V, never>(this._writer, this._state);
|
|
125
|
+
if (writer) this._writer = writer;
|
|
126
|
+
return writer;
|
|
139
127
|
}
|
|
140
128
|
|
|
141
129
|
/** Discriminant for type narrowing. */
|
|
@@ -172,7 +160,7 @@ export class Ok<V, T extends LogSchema = LogSchema> {
|
|
|
172
160
|
|
|
173
161
|
/** Transform the success value. */
|
|
174
162
|
map<U>(fn: (value: V) => U): Ok<U, T> {
|
|
175
|
-
return new Ok<U, T>(fn(this.value), this.
|
|
163
|
+
return new Ok<U, T>(fn(this.value), this._state);
|
|
176
164
|
}
|
|
177
165
|
|
|
178
166
|
/** No-op for Ok (error transformation). */
|
|
@@ -270,19 +258,18 @@ export class Ok<V, T extends LogSchema = LogSchema> {
|
|
|
270
258
|
export class Err<E, T extends LogSchema = LogSchema> {
|
|
271
259
|
readonly error: E;
|
|
272
260
|
|
|
273
|
-
private readonly
|
|
274
|
-
private
|
|
275
|
-
private _writer: BoundResultWriter<T, never, E> | undefined;
|
|
261
|
+
private readonly _state: WriterState | undefined;
|
|
262
|
+
private declare _writer: BoundResultWriter<T, never, E> | undefined;
|
|
276
263
|
|
|
277
|
-
constructor(error: E,
|
|
264
|
+
constructor(error: E, state?: WriterState) {
|
|
278
265
|
this.error = error;
|
|
279
|
-
this.
|
|
280
|
-
this._buffer = buffer;
|
|
266
|
+
this._state = state;
|
|
281
267
|
}
|
|
282
268
|
|
|
283
269
|
private _resultWriter(): BoundResultWriter<T, never, E> | undefined {
|
|
284
|
-
|
|
285
|
-
|
|
270
|
+
const writer = ensureResultWriter<T, never, E>(this._writer, this._state);
|
|
271
|
+
if (writer) this._writer = writer;
|
|
272
|
+
return writer;
|
|
286
273
|
}
|
|
287
274
|
|
|
288
275
|
/** Discriminant for type narrowing. */
|
|
@@ -349,7 +336,7 @@ export class Err<E, T extends LogSchema = LogSchema> {
|
|
|
349
336
|
|
|
350
337
|
/** Transform the error. */
|
|
351
338
|
mapErr<F>(fn: (error: E) => F): Err<F, T> {
|
|
352
|
-
return new Err<F, T>(fn(this.error), this.
|
|
339
|
+
return new Err<F, T>(fn(this.error), this._state);
|
|
353
340
|
}
|
|
354
341
|
|
|
355
342
|
/** No-op for Err (returns self). */
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export const RUNTIME_HINT_INITIAL_CAPACITY_MASK = 0x0000ffff;
|
|
2
|
+
|
|
3
|
+
export const RUNTIME_HINT_TAG = 0x00010000;
|
|
4
|
+
export const RUNTIME_HINT_LOG = 0x00020000;
|
|
5
|
+
export const RUNTIME_HINT_FF = 0x00040000;
|
|
6
|
+
export const RUNTIME_HINT_SPAN = 0x00080000;
|
|
7
|
+
export const RUNTIME_HINT_RESULT = 0x00100000;
|
|
8
|
+
export const RUNTIME_HINT_SCOPE = 0x00200000;
|
|
9
|
+
export const RUNTIME_HINT_DEPS = 0x00400000;
|
|
10
|
+
export const RUNTIME_HINT_CAPABILITIES_MASK = 0x007f0000;
|
|
11
|
+
export const RUNTIME_HINT_ANALYZED_VALID = 0x00800000;
|
|
12
|
+
export const RUNTIME_HINT_MESSAGE_LAYOUT_STATIC_ONLY = 0x01000000;
|
|
13
|
+
export const RUNTIME_HINT_MESSAGE_LAYOUT_DYNAMIC_ONLY = 0x02000000;
|
|
14
|
+
export const RUNTIME_HINT_MESSAGE_LAYOUT_MIXED = 0x03000000;
|
|
15
|
+
export const RUNTIME_HINT_MESSAGE_LAYOUT_MASK = 0x03000000;
|
|
16
|
+
export const RUNTIME_HINT_MESSAGE_PHYSICAL_PACKED = 0x04000000;
|
|
17
|
+
export const RUNTIME_HINT_MESSAGE_PHYSICAL_SPECIALIZED = 0x08000000;
|
|
18
|
+
export const RUNTIME_HINT_MESSAGE_PHYSICAL_MASK = 0x0c000000;
|
|
19
|
+
export const RUNTIME_HINT_RESERVED_MASK = 0xf0000000;
|
|
20
|
+
|
|
21
|
+
export const RUNTIME_HINT_FULL_CAPABILITIES = RUNTIME_HINT_CAPABILITIES_MASK;
|
|
22
|
+
export type MessageLayoutFamily = 'static-only' | 'mixed' | 'dynamic-only';
|
|
23
|
+
export type MessagePhysicalLayout = 'current' | 'specialized' | 'packed';
|
|
24
|
+
|
|
25
|
+
export interface DecodedRuntimeHint {
|
|
26
|
+
readonly analyzed: boolean;
|
|
27
|
+
readonly initialCapacity: number | undefined;
|
|
28
|
+
readonly capabilities: number;
|
|
29
|
+
readonly messageLayoutFamily: MessageLayoutFamily;
|
|
30
|
+
readonly messagePhysicalLayout: MessagePhysicalLayout;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isRuntimeHintAnalyzed(runtimeHint: number): boolean {
|
|
34
|
+
return (
|
|
35
|
+
Number.isInteger(runtimeHint) &&
|
|
36
|
+
runtimeHint >= 0 &&
|
|
37
|
+
runtimeHint <= 0xffffffff &&
|
|
38
|
+
(runtimeHint & RUNTIME_HINT_RESERVED_MASK) === 0 &&
|
|
39
|
+
(runtimeHint & RUNTIME_HINT_ANALYZED_VALID) !== 0
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function runtimeHintInitialCapacity(runtimeHint: number): number | undefined {
|
|
44
|
+
if (!isRuntimeHintAnalyzed(runtimeHint)) return undefined;
|
|
45
|
+
const capacity = runtimeHint & RUNTIME_HINT_INITIAL_CAPACITY_MASK;
|
|
46
|
+
return capacity < 2 ? undefined : capacity;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function runtimeHintHasCapability(runtimeHint: number, capability: number): boolean {
|
|
50
|
+
return !isRuntimeHintAnalyzed(runtimeHint) || (runtimeHint & capability) !== 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function runtimeHintMessageLayoutFamily(runtimeHint: number): MessageLayoutFamily {
|
|
54
|
+
if (!isRuntimeHintAnalyzed(runtimeHint)) return 'mixed';
|
|
55
|
+
|
|
56
|
+
switch (runtimeHint & RUNTIME_HINT_MESSAGE_LAYOUT_MASK) {
|
|
57
|
+
case RUNTIME_HINT_MESSAGE_LAYOUT_STATIC_ONLY:
|
|
58
|
+
return 'static-only';
|
|
59
|
+
case RUNTIME_HINT_MESSAGE_LAYOUT_DYNAMIC_ONLY:
|
|
60
|
+
return 'dynamic-only';
|
|
61
|
+
case RUNTIME_HINT_MESSAGE_LAYOUT_MIXED:
|
|
62
|
+
return 'mixed';
|
|
63
|
+
default:
|
|
64
|
+
return 'mixed';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function runtimeHintMessagePhysicalLayout(runtimeHint: number): MessagePhysicalLayout {
|
|
69
|
+
if (!isRuntimeHintAnalyzed(runtimeHint)) return 'current';
|
|
70
|
+
switch (runtimeHint & RUNTIME_HINT_MESSAGE_PHYSICAL_MASK) {
|
|
71
|
+
case RUNTIME_HINT_MESSAGE_PHYSICAL_PACKED:
|
|
72
|
+
return 'packed';
|
|
73
|
+
case RUNTIME_HINT_MESSAGE_PHYSICAL_SPECIALIZED:
|
|
74
|
+
return 'specialized';
|
|
75
|
+
default:
|
|
76
|
+
return 'current';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function decodeRuntimeHint(runtimeHint: number): DecodedRuntimeHint {
|
|
81
|
+
if (!isRuntimeHintAnalyzed(runtimeHint)) {
|
|
82
|
+
return {
|
|
83
|
+
analyzed: false,
|
|
84
|
+
initialCapacity: undefined,
|
|
85
|
+
capabilities: RUNTIME_HINT_FULL_CAPABILITIES,
|
|
86
|
+
messageLayoutFamily: 'mixed',
|
|
87
|
+
messagePhysicalLayout: 'current',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
analyzed: true,
|
|
93
|
+
initialCapacity: runtimeHintInitialCapacity(runtimeHint),
|
|
94
|
+
capabilities: runtimeHint & RUNTIME_HINT_CAPABILITIES_MASK,
|
|
95
|
+
messageLayoutFamily: runtimeHintMessageLayoutFamily(runtimeHint),
|
|
96
|
+
messagePhysicalLayout: runtimeHintMessagePhysicalLayout(runtimeHint),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -3,6 +3,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
3
3
|
import '../../__tests__/test-helpers.js';
|
|
4
4
|
import { createTestTracerOptions } from '../../__tests__/test-helpers.js';
|
|
5
5
|
import { defineOpContext } from '../../defineOpContext.js';
|
|
6
|
+
import { resolveEntryType } from '../../resolveMessage.js';
|
|
6
7
|
import { TestTracer } from '../../tracers/TestTracer.js';
|
|
7
8
|
import type { AnySpanBuffer } from '../../types.js';
|
|
8
9
|
import { S } from '../builder.js';
|
|
@@ -20,7 +21,7 @@ function countEntryType(buffer: AnySpanBuffer, entryType: number): number {
|
|
|
20
21
|
while (current) {
|
|
21
22
|
const writeIndex = current._writeIndex;
|
|
22
23
|
for (let i = 0; i < writeIndex; i++) {
|
|
23
|
-
if (current
|
|
24
|
+
if (resolveEntryType(current, i) === entryType) {
|
|
24
25
|
count++;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -132,7 +132,7 @@ const schemaBuilderImpl: SchemaBuilder = {
|
|
|
132
132
|
* - S.enum(['CREATE', 'READ', 'UPDATE', 'DELETE']) - for tag attributes
|
|
133
133
|
* - S.enum(['dev', 'staging', 'prod']).default('dev').sync() - feature flag
|
|
134
134
|
*/
|
|
135
|
-
enum: <T extends readonly string[]>(values: T): SchemaOrFlagBuilder<T[number]> & LazyEnumSchema<T[number]> => {
|
|
135
|
+
enum: <const T extends readonly string[]>(values: T): SchemaOrFlagBuilder<T[number]> & LazyEnumSchema<T[number]> => {
|
|
136
136
|
const schema = ArrowS.enum(values);
|
|
137
137
|
return createSchemaWithFlagBuilder(schema);
|
|
138
138
|
},
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Schema type-guard re-exports.
|
|
3
3
|
*
|
|
4
|
-
* Re-exports schema
|
|
4
|
+
* Re-exports the schema introspection guards from arrow-builder so the rest of
|
|
5
|
+
* the package imports them from a single place.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: Do not hand-write `isRecord`/`typeof` guards here. For runtime
|
|
8
|
+
* validation at trust boundaries use Typia (`typia.is<T>()`) or
|
|
9
|
+
* `@smoothbricks/validation`'s shared helpers (e.g. `isRecord`).
|
|
5
10
|
*/
|
|
6
11
|
|
|
7
|
-
// Re-export schema type guards from arrow-builder
|
|
8
12
|
export {
|
|
9
13
|
getBinaryEncoder,
|
|
10
14
|
getEnumUtf8,
|
|
@@ -13,151 +17,3 @@ export {
|
|
|
13
17
|
isEnumSchema,
|
|
14
18
|
isSchemaWithMetadata,
|
|
15
19
|
} 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
|
-
}
|
package/src/lib/schema/types.ts
CHANGED
|
@@ -207,7 +207,7 @@ export interface SchemaBuilder {
|
|
|
207
207
|
* Use for: Operations, HTTP methods, entry types, status enums
|
|
208
208
|
* Example: S.enum(['CREATE', 'READ', 'UPDATE', 'DELETE'])
|
|
209
209
|
*/
|
|
210
|
-
enum<T extends readonly string[]>(values: T): SchemaOrFlagBuilder<T[number]>;
|
|
210
|
+
enum<const T extends readonly string[]>(values: T): SchemaOrFlagBuilder<T[number]>;
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
213
|
* Category - Values that often repeat (limited cardinality)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkCapacityTuning } from '../../capacityTuning.js';
|
|
2
|
+
import { EMPTY_SCOPE, materializeCompiledSpanBufferClass } from '../../spanBuffer.js';
|
|
3
|
+
import { copyThreadIdTo, getThreadId } from '../../threadId.js';
|
|
4
|
+
|
|
5
|
+
const SPAN_BUFFER_AOT_ABI_SYMBOL = Symbol.for('@smoothbricks/lmao/span-buffer/aot/v1');
|
|
6
|
+
|
|
7
|
+
const spanBufferAotRuntime = Object.freeze({
|
|
8
|
+
EMPTY_SCOPE,
|
|
9
|
+
checkCapacityTuning,
|
|
10
|
+
copyThreadIdTo,
|
|
11
|
+
getThreadId,
|
|
12
|
+
materializeCompiledSpanBufferClass,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const existingRuntime = Reflect.get(globalThis, SPAN_BUFFER_AOT_ABI_SYMBOL);
|
|
16
|
+
if (existingRuntime === undefined) {
|
|
17
|
+
Object.defineProperty(globalThis, SPAN_BUFFER_AOT_ABI_SYMBOL, {
|
|
18
|
+
value: spanBufferAotRuntime,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
configurable: false,
|
|
21
|
+
writable: false,
|
|
22
|
+
});
|
|
23
|
+
} else if (existingRuntime !== spanBufferAotRuntime) {
|
|
24
|
+
// invariant throw: one realm must expose exactly one canonical SpanBuffer AOT ABI.
|
|
25
|
+
throw new TypeError('Conflicting LMAO SpanBuffer AOT runtime registrations');
|
|
26
|
+
}
|