@korajs/core 0.5.0 → 0.6.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.
@@ -639,97 +639,6 @@ interface SequenceConfig {
639
639
  startAt?: number;
640
640
  }
641
641
 
642
- /**
643
- * Hybrid Logical Clock implementation based on Kulkarni et al.
644
- *
645
- * Provides a total order that respects causality without requiring synchronized clocks.
646
- * Each call to now() returns a timestamp strictly greater than the previous one.
647
- *
648
- * @example
649
- * ```typescript
650
- * const clock = new HybridLogicalClock('node-1')
651
- * const ts1 = clock.now()
652
- * const ts2 = clock.now()
653
- * // HybridLogicalClock.compare(ts1, ts2) < 0 (ts1 is earlier)
654
- * ```
655
- */
656
- declare class HybridLogicalClock {
657
- private readonly nodeId;
658
- private readonly timeSource;
659
- private readonly onDriftWarning?;
660
- private wallTime;
661
- private logical;
662
- constructor(nodeId: string, timeSource?: TimeSource, onDriftWarning?: ((driftMs: number) => void) | undefined);
663
- /**
664
- * Generate a new timestamp for a local event.
665
- * Guarantees monotonicity: each call returns a timestamp strictly greater than the previous.
666
- *
667
- * @throws {ClockDriftError} If physical time is more than 5 minutes behind the HLC wallTime
668
- */
669
- now(): HLCTimestamp;
670
- /**
671
- * Update clock on receiving a remote timestamp.
672
- * Merges the remote clock state with the local state to maintain causal ordering.
673
- *
674
- * @throws {ClockDriftError} If physical time is more than 5 minutes behind the resulting wallTime
675
- */
676
- receive(remote: HLCTimestamp): HLCTimestamp;
677
- /**
678
- * Compare two timestamps. Returns negative if a < b, positive if a > b, zero if equal.
679
- * Total order: wallTime first, then logical, then nodeId (lexicographic).
680
- */
681
- static compare(a: HLCTimestamp, b: HLCTimestamp): number;
682
- /**
683
- * Serialize an HLC timestamp to a string that sorts lexicographically.
684
- * Format: zero-padded wallTime:logical:nodeId
685
- */
686
- static serialize(ts: HLCTimestamp): string;
687
- /**
688
- * Deserialize an HLC timestamp from its serialized string form.
689
- */
690
- static deserialize(s: string): HLCTimestamp;
691
- private checkDrift;
692
- }
693
-
694
- /**
695
- * Creates an immutable, content-addressed Operation from the given parameters.
696
- * The operation is deep-frozen after creation — it cannot be modified.
697
- *
698
- * @param input - The operation parameters (without id, which is computed)
699
- * @param clock - The HLC clock to generate the timestamp
700
- * @returns A frozen Operation with a content-addressed id
701
- *
702
- * @example
703
- * ```typescript
704
- * const op = await createOperation({
705
- * nodeId: 'device-1',
706
- * type: 'insert',
707
- * collection: 'todos',
708
- * recordId: 'rec-1',
709
- * data: { title: 'Ship it' },
710
- * previousData: null,
711
- * sequenceNumber: 1,
712
- * causalDeps: [],
713
- * schemaVersion: 1,
714
- * }, clock)
715
- * ```
716
- */
717
- declare function createOperation(input: OperationInput, clock: HybridLogicalClock): Promise<Operation>;
718
- /**
719
- * Validates operation input parameters. Throws OperationError with
720
- * contextual information on validation failure.
721
- */
722
- declare function validateOperationParams(input: OperationInput): void;
723
- /**
724
- * Verify the integrity of an operation by recomputing its content hash.
725
- * Returns true if the id matches the recomputed hash.
726
- */
727
- declare function verifyOperationIntegrity(op: Operation): Promise<boolean>;
728
- /**
729
- * Type guard for Operation interface.
730
- */
731
- declare function isValidOperation(value: unknown): value is Operation;
732
-
733
642
  /**
734
643
  * Trace of a merge decision. Records all inputs and outputs for debugging and DevTools.
735
644
  */
@@ -884,4 +793,4 @@ interface KoraEventEmitter {
884
793
  emit<T extends KoraEventType>(event: KoraEventByType<T>): void;
885
794
  }
886
795
 
887
- export { type AtomicOpType as A, RollbackBuilder as B, type CustomResolver as C, type SequenceConfig as D, EnumFieldBuilder as E, FieldBuilder as F, type StateMachineDefinition as G, type HLCTimestamp as H, type SyncDiagnosticsSnapshot as I, type SyncRuleDefinition as J, type KoraEvent as K, type TimeSource as L, type MigrationDefinition as M, createOperation as N, type OperationType as O, isValidOperation as P, migrate as Q, type RandomSource as R, type SchemaDefinition as S, type TransitionMap as T, t as U, type VersionVector as V, verifyOperationIntegrity as W, validateOperationParams as X, type AtomicOp as a, type CollectionDefinition as b, type RelationDefinition as c, ArrayFieldBuilder as d, type FieldKind as e, type Operation as f, type MigrationStep as g, type StateMachineConstraint as h, type TransitionValidationResult as i, CONNECTION_QUALITIES as j, type ConnectionQuality as k, type Constraint as l, type FieldDescriptor as m, type FieldMergeStrategy as n, HybridLogicalClock as o, type KoraEventByType as p, type KoraEventEmitter as q, type KoraEventListener as r, type KoraEventType as s, MERGE_STRATEGIES as t, type MergeStrategy as u, type MergeTrace as v, MigrationBuilder as w, type OnDeleteAction as x, type OperationInput as y, type RelationType as z };
796
+ export { type AtomicOpType as A, type SequenceConfig as B, type CustomResolver as C, type StateMachineDefinition as D, EnumFieldBuilder as E, FieldBuilder as F, type SyncDiagnosticsSnapshot as G, type HLCTimestamp as H, type SyncRuleDefinition as I, type TimeSource as J, type KoraEvent as K, migrate as L, type MigrationDefinition as M, t as N, type OperationType as O, type RandomSource as R, type SchemaDefinition as S, type TransitionMap as T, type VersionVector as V, type AtomicOp as a, type CollectionDefinition as b, type RelationDefinition as c, ArrayFieldBuilder as d, type FieldKind as e, type Operation as f, type MigrationStep as g, type StateMachineConstraint as h, type TransitionValidationResult as i, CONNECTION_QUALITIES as j, type ConnectionQuality as k, type Constraint as l, type FieldDescriptor as m, type FieldMergeStrategy as n, type KoraEventByType as o, type KoraEventEmitter as p, type KoraEventListener as q, type KoraEventType as r, MERGE_STRATEGIES as s, type MergeStrategy as t, type MergeTrace as u, MigrationBuilder as v, type OnDeleteAction as w, type OperationInput as x, type RelationType as y, RollbackBuilder as z };
@@ -639,97 +639,6 @@ interface SequenceConfig {
639
639
  startAt?: number;
640
640
  }
641
641
 
642
- /**
643
- * Hybrid Logical Clock implementation based on Kulkarni et al.
644
- *
645
- * Provides a total order that respects causality without requiring synchronized clocks.
646
- * Each call to now() returns a timestamp strictly greater than the previous one.
647
- *
648
- * @example
649
- * ```typescript
650
- * const clock = new HybridLogicalClock('node-1')
651
- * const ts1 = clock.now()
652
- * const ts2 = clock.now()
653
- * // HybridLogicalClock.compare(ts1, ts2) < 0 (ts1 is earlier)
654
- * ```
655
- */
656
- declare class HybridLogicalClock {
657
- private readonly nodeId;
658
- private readonly timeSource;
659
- private readonly onDriftWarning?;
660
- private wallTime;
661
- private logical;
662
- constructor(nodeId: string, timeSource?: TimeSource, onDriftWarning?: ((driftMs: number) => void) | undefined);
663
- /**
664
- * Generate a new timestamp for a local event.
665
- * Guarantees monotonicity: each call returns a timestamp strictly greater than the previous.
666
- *
667
- * @throws {ClockDriftError} If physical time is more than 5 minutes behind the HLC wallTime
668
- */
669
- now(): HLCTimestamp;
670
- /**
671
- * Update clock on receiving a remote timestamp.
672
- * Merges the remote clock state with the local state to maintain causal ordering.
673
- *
674
- * @throws {ClockDriftError} If physical time is more than 5 minutes behind the resulting wallTime
675
- */
676
- receive(remote: HLCTimestamp): HLCTimestamp;
677
- /**
678
- * Compare two timestamps. Returns negative if a < b, positive if a > b, zero if equal.
679
- * Total order: wallTime first, then logical, then nodeId (lexicographic).
680
- */
681
- static compare(a: HLCTimestamp, b: HLCTimestamp): number;
682
- /**
683
- * Serialize an HLC timestamp to a string that sorts lexicographically.
684
- * Format: zero-padded wallTime:logical:nodeId
685
- */
686
- static serialize(ts: HLCTimestamp): string;
687
- /**
688
- * Deserialize an HLC timestamp from its serialized string form.
689
- */
690
- static deserialize(s: string): HLCTimestamp;
691
- private checkDrift;
692
- }
693
-
694
- /**
695
- * Creates an immutable, content-addressed Operation from the given parameters.
696
- * The operation is deep-frozen after creation — it cannot be modified.
697
- *
698
- * @param input - The operation parameters (without id, which is computed)
699
- * @param clock - The HLC clock to generate the timestamp
700
- * @returns A frozen Operation with a content-addressed id
701
- *
702
- * @example
703
- * ```typescript
704
- * const op = await createOperation({
705
- * nodeId: 'device-1',
706
- * type: 'insert',
707
- * collection: 'todos',
708
- * recordId: 'rec-1',
709
- * data: { title: 'Ship it' },
710
- * previousData: null,
711
- * sequenceNumber: 1,
712
- * causalDeps: [],
713
- * schemaVersion: 1,
714
- * }, clock)
715
- * ```
716
- */
717
- declare function createOperation(input: OperationInput, clock: HybridLogicalClock): Promise<Operation>;
718
- /**
719
- * Validates operation input parameters. Throws OperationError with
720
- * contextual information on validation failure.
721
- */
722
- declare function validateOperationParams(input: OperationInput): void;
723
- /**
724
- * Verify the integrity of an operation by recomputing its content hash.
725
- * Returns true if the id matches the recomputed hash.
726
- */
727
- declare function verifyOperationIntegrity(op: Operation): Promise<boolean>;
728
- /**
729
- * Type guard for Operation interface.
730
- */
731
- declare function isValidOperation(value: unknown): value is Operation;
732
-
733
642
  /**
734
643
  * Trace of a merge decision. Records all inputs and outputs for debugging and DevTools.
735
644
  */
@@ -884,4 +793,4 @@ interface KoraEventEmitter {
884
793
  emit<T extends KoraEventType>(event: KoraEventByType<T>): void;
885
794
  }
886
795
 
887
- export { type AtomicOpType as A, RollbackBuilder as B, type CustomResolver as C, type SequenceConfig as D, EnumFieldBuilder as E, FieldBuilder as F, type StateMachineDefinition as G, type HLCTimestamp as H, type SyncDiagnosticsSnapshot as I, type SyncRuleDefinition as J, type KoraEvent as K, type TimeSource as L, type MigrationDefinition as M, createOperation as N, type OperationType as O, isValidOperation as P, migrate as Q, type RandomSource as R, type SchemaDefinition as S, type TransitionMap as T, t as U, type VersionVector as V, verifyOperationIntegrity as W, validateOperationParams as X, type AtomicOp as a, type CollectionDefinition as b, type RelationDefinition as c, ArrayFieldBuilder as d, type FieldKind as e, type Operation as f, type MigrationStep as g, type StateMachineConstraint as h, type TransitionValidationResult as i, CONNECTION_QUALITIES as j, type ConnectionQuality as k, type Constraint as l, type FieldDescriptor as m, type FieldMergeStrategy as n, HybridLogicalClock as o, type KoraEventByType as p, type KoraEventEmitter as q, type KoraEventListener as r, type KoraEventType as s, MERGE_STRATEGIES as t, type MergeStrategy as u, type MergeTrace as v, MigrationBuilder as w, type OnDeleteAction as x, type OperationInput as y, type RelationType as z };
796
+ export { type AtomicOpType as A, type SequenceConfig as B, type CustomResolver as C, type StateMachineDefinition as D, EnumFieldBuilder as E, FieldBuilder as F, type SyncDiagnosticsSnapshot as G, type HLCTimestamp as H, type SyncRuleDefinition as I, type TimeSource as J, type KoraEvent as K, migrate as L, type MigrationDefinition as M, t as N, type OperationType as O, type RandomSource as R, type SchemaDefinition as S, type TransitionMap as T, type VersionVector as V, type AtomicOp as a, type CollectionDefinition as b, type RelationDefinition as c, ArrayFieldBuilder as d, type FieldKind as e, type Operation as f, type MigrationStep as g, type StateMachineConstraint as h, type TransitionValidationResult as i, CONNECTION_QUALITIES as j, type ConnectionQuality as k, type Constraint as l, type FieldDescriptor as m, type FieldMergeStrategy as n, type KoraEventByType as o, type KoraEventEmitter as p, type KoraEventListener as q, type KoraEventType as r, MERGE_STRATEGIES as s, type MergeStrategy as t, type MergeTrace as u, MigrationBuilder as v, type OnDeleteAction as w, type OperationInput as x, type RelationType as y, RollbackBuilder as z };
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  APPLY_FAILURE_CODES: () => APPLY_FAILURE_CODES,
24
24
  APPLY_RESULTS: () => APPLY_RESULTS,
25
+ AppNotReadyError: () => AppNotReadyError,
25
26
  ArrayFieldBuilder: () => ArrayFieldBuilder,
26
27
  CONNECTION_QUALITIES: () => CONNECTION_QUALITIES,
27
28
  CausalTracker: () => CausalTracker,
@@ -177,6 +178,14 @@ var StorageError = class extends KoraError {
177
178
  this.name = "StorageError";
178
179
  }
179
180
  };
181
+ var AppNotReadyError = class extends KoraError {
182
+ constructor(detail) {
183
+ super(detail, "APP_NOT_READY", {
184
+ fix: "Await app.ready, or wrap your UI in <KoraProvider app={app}> before calling useQuery()."
185
+ });
186
+ this.name = "AppNotReadyError";
187
+ }
188
+ };
180
189
  var ClockDriftError = class extends KoraError {
181
190
  constructor(currentHlcTime, physicalTime) {
182
191
  const driftSeconds = Math.round((currentHlcTime - physicalTime) / 1e3);
@@ -2462,6 +2471,7 @@ function generateProtoDefinitions(schema) {
2462
2471
  0 && (module.exports = {
2463
2472
  APPLY_FAILURE_CODES,
2464
2473
  APPLY_RESULTS,
2474
+ AppNotReadyError,
2465
2475
  ArrayFieldBuilder,
2466
2476
  CONNECTION_QUALITIES,
2467
2477
  CausalTracker,