@devicerail/recorder 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.
@@ -0,0 +1,9 @@
1
+ export type RecorderErrorCode = "action_call_reused" | "action_correlation_mismatch" | "action_in_flight" | "action_not_started" | "action_result_mismatch" | "bundle_cli_failed" | "bundle_summary_invalid" | "bundle_summary_mismatch" | "checkpoint_conflict" | "checkpoint_corrupt" | "checkpoint_durability_unknown" | "checkpoint_locked" | "duplicate_event_id" | "event_too_large" | "invalid_event" | "invalid_lifecycle" | "operation_cancelled" | "out_of_order" | "sequence_conflict" | "sequence_gap" | "session_export_mismatch" | "session_mismatch" | "session_not_ended" | "source_conflict" | "source_corrupt" | "source_durability_unknown" | "source_too_large" | "terminal_append" | "upstream_unavailable";
2
+ export interface RecorderErrorOptions extends ErrorOptions {
3
+ readonly details?: Readonly<Record<string, unknown>>;
4
+ }
5
+ export declare class RecorderError extends Error {
6
+ readonly code: RecorderErrorCode;
7
+ readonly details: Readonly<Record<string, unknown>> | undefined;
8
+ constructor(code: RecorderErrorCode, message: string, options?: RecorderErrorOptions);
9
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,10 @@
1
+ export class RecorderError extends Error {
2
+ code;
3
+ details;
4
+ constructor(code, message, options = {}) {
5
+ super(message, options);
6
+ this.name = "RecorderError";
7
+ this.code = code;
8
+ this.details = options.details;
9
+ }
10
+ }
@@ -0,0 +1,71 @@
1
+ import type { ProtocolVersion, TestEvent } from "@devicerail/protocol";
2
+ import type { EventAcceptance, EventBatchResult, EventLogSnapshot } from "./types.js";
3
+ declare const PREPARED_STATE: unique symbol;
4
+ declare const ABSENT: unique symbol;
5
+ type CorrelationValue = string | number | null | typeof ABSENT;
6
+ interface OpenAction {
7
+ readonly deviceId: CorrelationValue;
8
+ readonly requestId: CorrelationValue;
9
+ }
10
+ interface OpenMediaStream {
11
+ readonly mediaType: string;
12
+ readonly nextFrameIndex: number;
13
+ }
14
+ interface MutableLogState {
15
+ readonly owner: object;
16
+ eventCount: number;
17
+ readonly appendedEvents: TestEvent[];
18
+ readonly eventIds: OverlaySet;
19
+ openActions: Map<string, OpenAction>;
20
+ openMediaStreams: Map<string, OpenMediaStream>;
21
+ readonly seenCallIds: OverlaySet;
22
+ readonly seenMediaStreamIds: OverlaySet;
23
+ terminal: boolean;
24
+ }
25
+ declare class OverlaySet {
26
+ #private;
27
+ readonly added: Set<string>;
28
+ constructor(base: ReadonlySet<string>);
29
+ has(value: string): boolean;
30
+ add(value: string): void;
31
+ }
32
+ /** Opaque, generation-bound result of validating one delivery batch. */
33
+ export interface PreparedEventBatch {
34
+ readonly baseGeneration: number;
35
+ readonly acceptedEvents: readonly TestEvent[];
36
+ readonly result: EventBatchResult;
37
+ readonly [PREPARED_STATE]: MutableLogState;
38
+ }
39
+ /** Runtime-validates and takes an immutable snapshot of one untrusted event. */
40
+ export declare function validateTestEvent(value: unknown, location?: string, protocol?: ProtocolVersion): TestEvent;
41
+ /** Sequence-authoritative, transport-neutral Session event accumulator. */
42
+ export declare class EventLog {
43
+ #private;
44
+ constructor(sessionId: string, eventProtocolVersion?: ProtocolVersion);
45
+ /** Strictly reconstructs a canonical checkpoint log. */
46
+ static replay(sessionId: string, events: readonly unknown[], eventProtocolVersion?: ProtocolVersion): EventLog;
47
+ get sessionId(): string;
48
+ get events(): readonly TestEvent[];
49
+ get lastSequence(): number | null;
50
+ get nextSequence(): number;
51
+ get terminal(): boolean;
52
+ get openActionCount(): number;
53
+ /**
54
+ * Creates an isolated speculative branch. Immutable event chunks are shared;
55
+ * identity indexes are copied because subsequent writes to either branch must
56
+ * remain independent. The Recorder hot path uses `prepareBatch` instead.
57
+ */
58
+ fork(): EventLog;
59
+ accept(value: unknown): EventAcceptance;
60
+ /** Validate a batch without copying or mutating the confirmed event prefix. */
61
+ prepareBatch(values: readonly unknown[]): PreparedEventBatch;
62
+ /** Commit a previously validated batch without replaying its durable prefix. */
63
+ commitPreparedBatch(prepared: PreparedEventBatch): EventBatchResult;
64
+ /**
65
+ * Accepts one delivery batch atomically. Any malformed event or state-machine
66
+ * failure leaves the prior log unchanged.
67
+ */
68
+ acceptBatch(values: readonly unknown[]): EventBatchResult;
69
+ snapshot(): EventLogSnapshot;
70
+ }
71
+ export {};