@mmstack/primitives 22.6.0 → 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.0",
3
+ "version": "22.7.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -2283,7 +2283,7 @@ type PointerDragState = {
2283
2283
  /**
2284
2284
  * The element the gesture started on: the `handleSelector` match when one is
2285
2285
  * set (so a single delegated listener can tell which child started the drag),
2286
- * otherwise the listener's element. `null` when idle.
2286
+ * otherwise the pressed element itself (`event.target`). `null` when idle.
2287
2287
  */
2288
2288
  origin: HTMLElement | null;
2289
2289
  /**
@@ -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>;
@@ -3498,6 +3508,23 @@ type MaybePromise<T> = T | Promise<T>;
3498
3508
  * del: (k) => table.delete(k),
3499
3509
  * };
3500
3510
  * ```
3511
+ *
3512
+ * The backend is also the seam for cross-cutting storage concerns like encryption: wrap any
3513
+ * backend in a decorator (get/set may be async, so WebCrypto fits here — `serialize` is sync
3514
+ * by design and is for shape, not for the storage medium). Versioning and migration still work
3515
+ * because the version envelope is inspected on what the backend RETURNS, i.e. after decryption:
3516
+ *
3517
+ * ```ts
3518
+ * const encrypted = (inner: AsyncStore, cipher: MyCipher): AsyncStore => ({
3519
+ * get: async (k) => {
3520
+ * const raw = await inner.get(k);
3521
+ * return raw === undefined ? undefined : cipher.decrypt(raw);
3522
+ * },
3523
+ * set: async (k, v) => inner.set(k, await cipher.encrypt(v)),
3524
+ * del: (k) => inner.del(k),
3525
+ * });
3526
+ * providePersistedStoreOptions({ store: encrypted(idbKeyval, cipher) });
3527
+ * ```
3501
3528
  */
3502
3529
  type AsyncStore = {
3503
3530
  get(key: string): MaybePromise<unknown>;
@@ -3790,6 +3817,18 @@ type StoredSignal<T> = WritableSignal<T> & {
3790
3817
  */
3791
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>;
3792
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
+ };
3793
3832
  type LegacySyncSignalOptions = {
3794
3833
  id?: string;
3795
3834
  };
@@ -3803,11 +3842,13 @@ type SyncSignalOptions = {
3803
3842
  * it — a cross-tab consistency gap not worth the negligible saving. The channel stays live.
3804
3843
  */
3805
3844
  injector?: Injector;
3845
+ /** Cross-tab transport. Defaults to the injected {@link MessageBus} (a `BroadcastChannel`). */
3846
+ bus?: TabSyncBus;
3806
3847
  };
3807
3848
  /**
3808
3849
  * Store mode (`tabSync(store, …)`): syncs structural OPS instead of whole values — concurrent
3809
3850
  * edits to different leaves merge instead of clobbering, and a joining tab hydrates from a
3810
- * peer via the hello exchange (up-to-date / snapshot; op-protocol RFC §6).
3851
+ * peer via the hello exchange.
3811
3852
  */
3812
3853
  type StoreTabSyncOptions = SyncSignalOptions & {
3813
3854
  /** Principal pseudonym on emitted envelopes. Tabs share one user, so a default is fine. */
@@ -4113,4 +4154,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4113
4154
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4114
4155
 
4115
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 };
4116
- 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 };