@mmstack/primitives 22.6.1 → 22.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "22.6.1",
3
+ "version": "22.7.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -3313,7 +3313,7 @@ declare function createHlcClock(now?: () => number): HlcClock;
3313
3313
  declare const OP_PROTO_VERSION = 1;
3314
3314
  type Key = string | number;
3315
3315
  /**
3316
- * The wire/journal record (op-protocol RFC §3). `writer` is an opaque principal pseudonym —
3316
+ * The wire/journal recor. `writer` is an opaque principal pseudonym —
3317
3317
  * natural identity never enters the envelope; `origin` identifies the emitting log instance.
3318
3318
  */
3319
3319
  type OpEnvelope = {
@@ -3354,7 +3354,7 @@ declare const lww: MergeFn;
3354
3354
  declare const mergeThree: MergeFn;
3355
3355
  declare const preserve: MergeFn;
3356
3356
  /**
3357
- * Identity-aware array merge (op-protocol RFC §12 v0): reconciles two concurrent versions of
3357
+ * Identity-aware array merge: reconciles two concurrent versions of
3358
3358
  * an array item-wise by a user-provided identity, instead of last-writer-wins on the whole
3359
3359
  * array. Items are matched by key; per-item fields merge via `merge3` against the ancestor
3360
3360
  * item; items added on either side survive; an item removed on either side and unedited on
@@ -3379,7 +3379,7 @@ type ConvergingApply = {
3379
3379
  reset(): void;
3380
3380
  };
3381
3381
  /**
3382
- * The unsequenced-topology convergence core (op-protocol RFC §4): a per-path last-writer-wins
3382
+ * The unsequenced-topology convergence core: a per-path last-writer-wins
3383
3383
  * register map over the total order (hlc, writer), with subtree dominance. Order-independent:
3384
3384
  * any arrival order of the same envelope set yields the same state.
3385
3385
  */
@@ -3392,7 +3392,7 @@ type RebaseResult<T = unknown> = {
3392
3392
  pending: StoreOp[][];
3393
3393
  };
3394
3394
  /**
3395
- * The shared rebase routine (op-protocol RFC §5): invert pending, apply remote, re-apply
3395
+ * The shared rebase routine: invert pending, apply remote, re-apply
3396
3396
  * pending through the merge policies. Pure — branching's `rebase()` and the sequenced relay
3397
3397
  * client both call this.
3398
3398
  */
@@ -3406,7 +3406,7 @@ declare function rebaseOps<T>(root: T, pending: readonly (readonly StoreOp[])[],
3406
3406
  */
3407
3407
  declare function policyStrategy<T>(policies: readonly MergePolicyEntry[]): (ancestor: T, mine: T, theirs: T) => T;
3408
3408
  type OpSyncOptions = {
3409
- /** Opaque principal pseudonym — provided by the app, never minted here (RFC §3). */
3409
+ /** Opaque principal pseudonym — provided by the app, never minted here. */
3410
3410
  readonly writer: string;
3411
3411
  readonly origin?: string;
3412
3412
  readonly policyVersion?: number;
@@ -3443,6 +3443,16 @@ type OpSync<T = unknown> = {
3443
3443
  * top, so writes made before hydration are never silently lost.
3444
3444
  */
3445
3445
  hydrate(root: T, wm?: Record<string, number>): void;
3446
+ /**
3447
+ * Re-inject this origin's persisted local envelopes on boot (a durable outbox), WITHOUT minting
3448
+ * new versions: each is applied to the store (echo-free), registered as a local winner, and handed
3449
+ * to subscribers so a transport can resend the unacknowledged tail. `highWater` is the highest
3450
+ * version this origin ever emitted (>= every `env.version`); the next mint continues past it, so a
3451
+ * version acked before the reboot but dropped from a debounced outbox never collides. Call on a
3452
+ * FRESH instance, before any `receive`/`hydrate` — restoring onto already-ingested remote winners
3453
+ * would wrongly let a stale local op override them.
3454
+ */
3455
+ restore(envs: readonly OpEnvelope[], highWater?: number): void;
3446
3456
  destroy(): void;
3447
3457
  };
3448
3458
  declare function opSync<T extends object>(source: WritableSignal<T>, opt: OpSyncOptions): OpSync<T>;
@@ -3807,6 +3817,18 @@ type StoredSignal<T> = WritableSignal<T> & {
3807
3817
  */
3808
3818
  declare function stored<T>(fallback: T, { key, store: providedStore, serialize, deserialize, syncTabs, equal, onKeyChange, cleanupOldKey, validate, pause, injector: providedInjector, ...rest }: CreateStoredOptions<T>): StoredSignal<T>;
3809
3819
 
3820
+ /**
3821
+ * The cross-tab transport `tabSync` rides. The default is {@link MessageBus} (a `BroadcastChannel`);
3822
+ * pass a custom one through `tabSync`'s `bus` option to route over a different channel, or to drive
3823
+ * tabs deterministically in a test. `subscribe` returns an unsubscribe handle plus a `post` that
3824
+ * fans the value to every OTHER tab on the same `id`.
3825
+ */
3826
+ type TabSyncBus = {
3827
+ subscribe<T>(id: string, listener: (data: T) => void): {
3828
+ unsub: () => void;
3829
+ post: (value: T) => void;
3830
+ };
3831
+ };
3810
3832
  type LegacySyncSignalOptions = {
3811
3833
  id?: string;
3812
3834
  };
@@ -3820,11 +3842,13 @@ type SyncSignalOptions = {
3820
3842
  * it — a cross-tab consistency gap not worth the negligible saving. The channel stays live.
3821
3843
  */
3822
3844
  injector?: Injector;
3845
+ /** Cross-tab transport. Defaults to the injected {@link MessageBus} (a `BroadcastChannel`). */
3846
+ bus?: TabSyncBus;
3823
3847
  };
3824
3848
  /**
3825
3849
  * Store mode (`tabSync(store, …)`): syncs structural OPS instead of whole values — concurrent
3826
3850
  * edits to different leaves merge instead of clobbering, and a joining tab hydrates from a
3827
- * peer via the hello exchange (up-to-date / snapshot; op-protocol RFC §6).
3851
+ * peer via the hello exchange.
3828
3852
  */
3829
3853
  type StoreTabSyncOptions = SyncSignalOptions & {
3830
3854
  /** Principal pseudonym on emitted envelopes. Tabs share one user, so a default is fine. */
@@ -4130,4 +4154,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4130
4154
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4131
4155
 
4132
4156
  export { CONCURRENCY_INSTRUMENTATION, MmActivity, MmTransition, MmViewTransitionName, OP_PROTO_VERSION, PAUSABLE_OPTIONS, PERSISTED_STORE_OPTIONS, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, applyOps, batteryStatus, bridgeScopeToPendingTasks, chunked, clipboard, combineWith, compareHlc, compareTotal, createAttributedPending, createConvergingApply, createForwardingScope, createHlcClock, createStoreContext, createTransaction, createTransitionScope, debounce, debounced, deferredValue, derived, diffOps, distinct, elementSize, elementVisibility, extendStore, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, invertBatch, isConflicted, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, keyedArray, latest, lww, map, mapArray, mapObject, mediaQuery, merge3, mergeThree, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opLog, opSync, opaque, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, perfCustomTracks, persist, persistedStore, pipeable, piped, pointerDrag, policyStrategy, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, preserve, projection, provideConcurrencyInstrumentation, provideForwardingTransitionScope, providePausableOptions, providePaused, providePersistedStoreOptions, provideTransitionScope, rebaseOps, reconcile, registerResource, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, storeHistory, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, use, windowSize, withHistory };
4133
- export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncOptions, Opaque, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncSignalOptions, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };
4157
+ export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncOptions, Opaque, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncSignalOptions, TabSyncBus, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };