@lunora/client 1.0.0-alpha.156 → 1.0.0-alpha.157

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/dist/index.d.mts CHANGED
@@ -945,92 +945,4 @@ declare const createReconnect: (options?: ReconnectOptions, random?: () => numbe
945
945
  * ```
946
946
  */
947
947
  declare const createSnapshotPrecondition: (client: LunoraClient, functionRef: FunctionReference, args: Record<string, unknown>, shardKey?: string) => (() => boolean);
948
- /**
949
- * Client-side service-worker registration and lifecycle management.
950
- *
951
- * Usage:
952
- * ```ts
953
- * const sw = new ClientServiceWorker({ swUrl: "/sw.js" });
954
- * await sw.register();
955
- *
956
- * if (sw.active) {
957
- * sw.postMessage({ type: "sync" });
958
- * }
959
- * ```
960
- */
961
- type ServiceWorkerStatus = "unsupported" | "unregistered" | "registering" | "active" | "error";
962
- interface ClientSwOptions {
963
- /** Called when the status changes. */
964
- onStatusChange?: (status: ServiceWorkerStatus) => void;
965
- /** Optional registration scope. Defaults to `/`. */
966
- scope?: string;
967
- /** URL of the service worker script (relative to origin). */
968
- swUrl: string;
969
- }
970
- /**
971
- * Manages service-worker registration and provides a simple API for
972
- * sending messages and listening for responses.
973
- */
974
- declare class ClientServiceWorker {
975
- #private;
976
- readonly swUrl: string;
977
- readonly scope: string;
978
- constructor(options: ClientSwOptions);
979
- /** Current registration status. */
980
- get status(): ServiceWorkerStatus;
981
- /** The underlying `ServiceWorkerRegistration`, if registered. */
982
- get registration(): ServiceWorkerRegistration | undefined;
983
- /** Whether the SW is currently controlling this page. */
984
- get active(): boolean;
985
- /**
986
- * Register the service worker.
987
- *
988
- * Returns `false` when the browser does not support service workers.
989
- */
990
- register(): Promise<boolean>;
991
- /**
992
- * Remove the active service worker registration and clear listeners.
993
- *
994
- * Returns `false` when no registration is currently held.
995
- */
996
- unregister(): Promise<boolean>;
997
- /**
998
- * Send a message to the active service worker.
999
- */
1000
- postMessage(message: unknown): void;
1001
- /**
1002
- * Register a handler for messages **from** the service worker.
1003
- * @returns Unsubscribe function.
1004
- */
1005
- onMessage(handler: (event: MessageEvent) => void): () => void;
1006
- }
1007
- /**
1008
- * Outbound message from the client to the SW.
1009
- */
1010
- interface ClientToSwMessage {
1011
- /** Opaque correlation ID for request/response patterns. */
1012
- correlationId?: string;
1013
- payload?: unknown;
1014
- type: string;
1015
- }
1016
- /**
1017
- * Inbound message from the SW to the client.
1018
- */
1019
- interface SwToClientMessage {
1020
- /** Echoes the correlation ID from the client request, if any. */
1021
- correlationId?: string;
1022
- payload?: unknown;
1023
- type: string;
1024
- }
1025
- /**
1026
- * Send a typed message to the service worker and optionally await a
1027
- * matching response.
1028
- * @returns A promise that resolves when the SW sends a reply with the
1029
- * same `correlationId` (if `expectResponse` is true).
1030
- */
1031
- declare const sendToSw: (sw: ServiceWorker | null, message: ClientToSwMessage, expectResponse?: boolean) => Promise<unknown>;
1032
- /**
1033
- * Create a reply for a client message (call from inside the SW).
1034
- */
1035
- declare const createReply: (original: ClientToSwMessage, payload?: unknown) => SwToClientMessage;
1036
- export { type AsyncStorageLike, type AsyncStoragePersistenceOptions, type AsyncStorageQueryCacheOptions, type BookmarkStorage, CONFLICT_ERROR_CODE, ClientServiceWorker, type ClientSwOptions, type ClientToSwMessage, type ConnectionStatus, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamOptions, type HttpStreamRef, type IndexedDbPersistenceOptions, type IndexedDbQueryCacheOptions, LunoraClient, type MutationDelta, type MutatorHandle, type MutatorRunnerSinks, type MutatorTransaction, OfflineQueue, type OfflineQueueOptions, type OptimisticMessage, type PersistenceAdapter, type QueryCacheAdapter, type QueuedMutation, RETIRE_AFTER_DURABLE_SEQ_ADVANCE, type ReconcileDurableMessage, type ReconnectCalculator, type ReconnectOptions, type ServiceWorkerStatus, type StreamIterable, type SubscriptionError, type SwToClientMessage, TabCoordinator, TransportError, anyApi, applyDelta, createAsyncStoragePersistence, createAsyncStorageQueryCache, createCallRunner, createInMemoryBookmarkStorage, createInMemoryPersistence, createInMemoryQueryCache, createIndexedDbPersistence, createIndexedDbQueryCache, createMutatorRunner, createReconnect, createReply, createSnapshotPrecondition, getErrorCode, getRetryAfterMs, httpStream, isAuthReplayFailure, isConflictError, isForbiddenError, isMutationDelta, isRateLimitedError, isUnauthorizedError, maxSeq, queryCacheKey, reconcileOptimistic, sendToSw };
948
+ export { type AsyncStorageLike, type AsyncStoragePersistenceOptions, type AsyncStorageQueryCacheOptions, type BookmarkStorage, CONFLICT_ERROR_CODE, type ConnectionStatus, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamOptions, type HttpStreamRef, type IndexedDbPersistenceOptions, type IndexedDbQueryCacheOptions, LunoraClient, type MutationDelta, type MutatorHandle, type MutatorRunnerSinks, type MutatorTransaction, OfflineQueue, type OfflineQueueOptions, type OptimisticMessage, type PersistenceAdapter, type QueryCacheAdapter, type QueuedMutation, RETIRE_AFTER_DURABLE_SEQ_ADVANCE, type ReconcileDurableMessage, type ReconnectCalculator, type ReconnectOptions, type StreamIterable, type SubscriptionError, TabCoordinator, TransportError, anyApi, applyDelta, createAsyncStoragePersistence, createAsyncStorageQueryCache, createCallRunner, createInMemoryBookmarkStorage, createInMemoryPersistence, createInMemoryQueryCache, createIndexedDbPersistence, createIndexedDbQueryCache, createMutatorRunner, createReconnect, createSnapshotPrecondition, getErrorCode, getRetryAfterMs, httpStream, isAuthReplayFailure, isConflictError, isForbiddenError, isMutationDelta, isRateLimitedError, isUnauthorizedError, maxSeq, queryCacheKey, reconcileOptimistic };
package/dist/index.d.ts CHANGED
@@ -945,92 +945,4 @@ declare const createReconnect: (options?: ReconnectOptions, random?: () => numbe
945
945
  * ```
946
946
  */
947
947
  declare const createSnapshotPrecondition: (client: LunoraClient, functionRef: FunctionReference, args: Record<string, unknown>, shardKey?: string) => (() => boolean);
948
- /**
949
- * Client-side service-worker registration and lifecycle management.
950
- *
951
- * Usage:
952
- * ```ts
953
- * const sw = new ClientServiceWorker({ swUrl: "/sw.js" });
954
- * await sw.register();
955
- *
956
- * if (sw.active) {
957
- * sw.postMessage({ type: "sync" });
958
- * }
959
- * ```
960
- */
961
- type ServiceWorkerStatus = "unsupported" | "unregistered" | "registering" | "active" | "error";
962
- interface ClientSwOptions {
963
- /** Called when the status changes. */
964
- onStatusChange?: (status: ServiceWorkerStatus) => void;
965
- /** Optional registration scope. Defaults to `/`. */
966
- scope?: string;
967
- /** URL of the service worker script (relative to origin). */
968
- swUrl: string;
969
- }
970
- /**
971
- * Manages service-worker registration and provides a simple API for
972
- * sending messages and listening for responses.
973
- */
974
- declare class ClientServiceWorker {
975
- #private;
976
- readonly swUrl: string;
977
- readonly scope: string;
978
- constructor(options: ClientSwOptions);
979
- /** Current registration status. */
980
- get status(): ServiceWorkerStatus;
981
- /** The underlying `ServiceWorkerRegistration`, if registered. */
982
- get registration(): ServiceWorkerRegistration | undefined;
983
- /** Whether the SW is currently controlling this page. */
984
- get active(): boolean;
985
- /**
986
- * Register the service worker.
987
- *
988
- * Returns `false` when the browser does not support service workers.
989
- */
990
- register(): Promise<boolean>;
991
- /**
992
- * Remove the active service worker registration and clear listeners.
993
- *
994
- * Returns `false` when no registration is currently held.
995
- */
996
- unregister(): Promise<boolean>;
997
- /**
998
- * Send a message to the active service worker.
999
- */
1000
- postMessage(message: unknown): void;
1001
- /**
1002
- * Register a handler for messages **from** the service worker.
1003
- * @returns Unsubscribe function.
1004
- */
1005
- onMessage(handler: (event: MessageEvent) => void): () => void;
1006
- }
1007
- /**
1008
- * Outbound message from the client to the SW.
1009
- */
1010
- interface ClientToSwMessage {
1011
- /** Opaque correlation ID for request/response patterns. */
1012
- correlationId?: string;
1013
- payload?: unknown;
1014
- type: string;
1015
- }
1016
- /**
1017
- * Inbound message from the SW to the client.
1018
- */
1019
- interface SwToClientMessage {
1020
- /** Echoes the correlation ID from the client request, if any. */
1021
- correlationId?: string;
1022
- payload?: unknown;
1023
- type: string;
1024
- }
1025
- /**
1026
- * Send a typed message to the service worker and optionally await a
1027
- * matching response.
1028
- * @returns A promise that resolves when the SW sends a reply with the
1029
- * same `correlationId` (if `expectResponse` is true).
1030
- */
1031
- declare const sendToSw: (sw: ServiceWorker | null, message: ClientToSwMessage, expectResponse?: boolean) => Promise<unknown>;
1032
- /**
1033
- * Create a reply for a client message (call from inside the SW).
1034
- */
1035
- declare const createReply: (original: ClientToSwMessage, payload?: unknown) => SwToClientMessage;
1036
- export { type AsyncStorageLike, type AsyncStoragePersistenceOptions, type AsyncStorageQueryCacheOptions, type BookmarkStorage, CONFLICT_ERROR_CODE, ClientServiceWorker, type ClientSwOptions, type ClientToSwMessage, type ConnectionStatus, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamOptions, type HttpStreamRef, type IndexedDbPersistenceOptions, type IndexedDbQueryCacheOptions, LunoraClient, type MutationDelta, type MutatorHandle, type MutatorRunnerSinks, type MutatorTransaction, OfflineQueue, type OfflineQueueOptions, type OptimisticMessage, type PersistenceAdapter, type QueryCacheAdapter, type QueuedMutation, RETIRE_AFTER_DURABLE_SEQ_ADVANCE, type ReconcileDurableMessage, type ReconnectCalculator, type ReconnectOptions, type ServiceWorkerStatus, type StreamIterable, type SubscriptionError, type SwToClientMessage, TabCoordinator, TransportError, anyApi, applyDelta, createAsyncStoragePersistence, createAsyncStorageQueryCache, createCallRunner, createInMemoryBookmarkStorage, createInMemoryPersistence, createInMemoryQueryCache, createIndexedDbPersistence, createIndexedDbQueryCache, createMutatorRunner, createReconnect, createReply, createSnapshotPrecondition, getErrorCode, getRetryAfterMs, httpStream, isAuthReplayFailure, isConflictError, isForbiddenError, isMutationDelta, isRateLimitedError, isUnauthorizedError, maxSeq, queryCacheKey, reconcileOptimistic, sendToSw };
948
+ export { type AsyncStorageLike, type AsyncStoragePersistenceOptions, type AsyncStorageQueryCacheOptions, type BookmarkStorage, CONFLICT_ERROR_CODE, type ConnectionStatus, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamOptions, type HttpStreamRef, type IndexedDbPersistenceOptions, type IndexedDbQueryCacheOptions, LunoraClient, type MutationDelta, type MutatorHandle, type MutatorRunnerSinks, type MutatorTransaction, OfflineQueue, type OfflineQueueOptions, type OptimisticMessage, type PersistenceAdapter, type QueryCacheAdapter, type QueuedMutation, RETIRE_AFTER_DURABLE_SEQ_ADVANCE, type ReconcileDurableMessage, type ReconnectCalculator, type ReconnectOptions, type StreamIterable, type SubscriptionError, TabCoordinator, TransportError, anyApi, applyDelta, createAsyncStoragePersistence, createAsyncStorageQueryCache, createCallRunner, createInMemoryBookmarkStorage, createInMemoryPersistence, createInMemoryQueryCache, createIndexedDbPersistence, createIndexedDbQueryCache, createMutatorRunner, createReconnect, createSnapshotPrecondition, getErrorCode, getRetryAfterMs, httpStream, isAuthReplayFailure, isConflictError, isForbiddenError, isMutationDelta, isRateLimitedError, isUnauthorizedError, maxSeq, queryCacheKey, reconcileOptimistic };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{anyApi as o}from"./packem_shared/anyApi-CBOws2ZA.mjs";import{RETIRE_AFTER_DURABLE_SEQ_ADVANCE as a,maxSeq as p,reconcileOptimistic as c}from"./packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs";import{createAsyncStoragePersistence as i}from"./packem_shared/createAsyncStoragePersistence-CeUW9NTj.mjs";import{createAsyncStorageQueryCache as f}from"./packem_shared/createAsyncStorageQueryCache-Dpszf7UD.mjs";import{default as x}from"./packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs";import{createCallRunner as l}from"./packem_shared/createCallRunner-Bwcrfh76.mjs";import{createClientQuery as d}from"./packem_shared/createClientQuery-B8Nfj-7o.mjs";import{TabCoordinator as E}from"./packem_shared/TabCoordinator-CXD7vulJ.mjs";import{a as S,i as A}from"./packem_shared/delta-merge-D_5ChS-C.mjs";import{CONFLICT_ERROR_CODE as D,TransportError as Q,getErrorCode as _,getRetryAfterMs as F,isAuthReplayFailure as I,isConflictError as M,isForbiddenError as T,isRateLimitedError as g,isUnauthorizedError as L}from"./packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs";import{httpStream as b}from"./packem_shared/httpStream-v4etRV7m.mjs";import{c as U}from"./packem_shared/local-store-DDppw8Qr.mjs";import{LunoraClient as B}from"./packem_shared/LunoraClient-BWZ8TiRn.mjs";import{createMutatorRunner as N}from"./packem_shared/createMutatorRunner-CuMRJpUx.mjs";import{O as w}from"./packem_shared/offline-queue-D_fr-uQ3.mjs";import{createInMemoryPersistence as K,createIndexedDbPersistence as V}from"./packem_shared/createInMemoryPersistence-Cz2W6XVj.mjs";import{preloadQuery as X,preloadedQueryResult as j}from"./packem_shared/preloadQuery-uFy24PCR.mjs";import{createInMemoryQueryCache as H,createIndexedDbQueryCache as J,queryCacheKey as Y}from"./packem_shared/createInMemoryQueryCache-D2uNHLfM.mjs";import{createReconnect as $}from"./packem_shared/createReconnect-CjTmjJDH.mjs";import{default as re}from"./packem_shared/createSnapshotPrecondition-5GQ_5fFu.mjs";import{DEFAULT_MAX_BUFFER as te,createStream as ae}from"./packem_shared/DEFAULT_MAX_BUFFER-D3QH2iaq.mjs";import{SubscriptionRegistry as ce}from"./packem_shared/SubscriptionRegistry-C3kLqped.mjs";import{ClientServiceWorker as ie}from"./packem_shared/ClientServiceWorker-DXnBXeWK.mjs";import{createReply as fe,sendToSw as se}from"./packem_shared/createReply-CwFABEJs.mjs";export{D as CONFLICT_ERROR_CODE,ie as ClientServiceWorker,te as DEFAULT_MAX_BUFFER,B as LunoraClient,w as OfflineQueue,a as RETIRE_AFTER_DURABLE_SEQ_ADVANCE,ce as SubscriptionRegistry,E as TabCoordinator,Q as TransportError,o as anyApi,S as applyDelta,i as createAsyncStoragePersistence,f as createAsyncStorageQueryCache,l as createCallRunner,d as createClientQuery,x as createInMemoryBookmarkStorage,K as createInMemoryPersistence,H as createInMemoryQueryCache,V as createIndexedDbPersistence,J as createIndexedDbQueryCache,U as createLocalStore,N as createMutatorRunner,$ as createReconnect,fe as createReply,re as createSnapshotPrecondition,ae as createStream,_ as getErrorCode,F as getRetryAfterMs,b as httpStream,I as isAuthReplayFailure,M as isConflictError,T as isForbiddenError,A as isMutationDelta,g as isRateLimitedError,L as isUnauthorizedError,p as maxSeq,X as preloadQuery,j as preloadedQueryResult,Y as queryCacheKey,c as reconcileOptimistic,se as sendToSw};
1
+ import{anyApi as o}from"./packem_shared/anyApi-CBOws2ZA.mjs";import{RETIRE_AFTER_DURABLE_SEQ_ADVANCE as a,maxSeq as c,reconcileOptimistic as p}from"./packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs";import{createAsyncStoragePersistence as i}from"./packem_shared/createAsyncStoragePersistence-CeUW9NTj.mjs";import{createAsyncStorageQueryCache as f}from"./packem_shared/createAsyncStorageQueryCache-Dpszf7UD.mjs";import{default as x}from"./packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs";import{createCallRunner as l}from"./packem_shared/createCallRunner-Bwcrfh76.mjs";import{createClientQuery as d}from"./packem_shared/createClientQuery-B8Nfj-7o.mjs";import{TabCoordinator as R}from"./packem_shared/TabCoordinator-CXD7vulJ.mjs";import{a as A,i as S}from"./packem_shared/delta-merge-D_5ChS-C.mjs";import{CONFLICT_ERROR_CODE as D,TransportError as Q,getErrorCode as _,getRetryAfterMs as F,isAuthReplayFailure as I,isConflictError as M,isForbiddenError as g,isRateLimitedError as L,isUnauthorizedError as O}from"./packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs";import{httpStream as b}from"./packem_shared/httpStream-v4etRV7m.mjs";import{c as U}from"./packem_shared/local-store-DDppw8Qr.mjs";import{LunoraClient as k}from"./packem_shared/LunoraClient-BWZ8TiRn.mjs";import{createMutatorRunner as N}from"./packem_shared/createMutatorRunner-CuMRJpUx.mjs";import{O as K}from"./packem_shared/offline-queue-D_fr-uQ3.mjs";import{createInMemoryPersistence as X,createIndexedDbPersistence as j}from"./packem_shared/createInMemoryPersistence-Cz2W6XVj.mjs";import{preloadQuery as w,preloadedQueryResult as G}from"./packem_shared/preloadQuery-uFy24PCR.mjs";import{createInMemoryQueryCache as J,createIndexedDbQueryCache as W,queryCacheKey as Y}from"./packem_shared/createInMemoryQueryCache-D2uNHLfM.mjs";import{createReconnect as $}from"./packem_shared/createReconnect-CjTmjJDH.mjs";import{default as re}from"./packem_shared/createSnapshotPrecondition-5GQ_5fFu.mjs";import{DEFAULT_MAX_BUFFER as te,createStream as ae}from"./packem_shared/DEFAULT_MAX_BUFFER-D3QH2iaq.mjs";import{SubscriptionRegistry as pe}from"./packem_shared/SubscriptionRegistry-C3kLqped.mjs";export{D as CONFLICT_ERROR_CODE,te as DEFAULT_MAX_BUFFER,k as LunoraClient,K as OfflineQueue,a as RETIRE_AFTER_DURABLE_SEQ_ADVANCE,pe as SubscriptionRegistry,R as TabCoordinator,Q as TransportError,o as anyApi,A as applyDelta,i as createAsyncStoragePersistence,f as createAsyncStorageQueryCache,l as createCallRunner,d as createClientQuery,x as createInMemoryBookmarkStorage,X as createInMemoryPersistence,J as createInMemoryQueryCache,j as createIndexedDbPersistence,W as createIndexedDbQueryCache,U as createLocalStore,N as createMutatorRunner,$ as createReconnect,re as createSnapshotPrecondition,ae as createStream,_ as getErrorCode,F as getRetryAfterMs,b as httpStream,I as isAuthReplayFailure,M as isConflictError,g as isForbiddenError,S as isMutationDelta,L as isRateLimitedError,O as isUnauthorizedError,c as maxSeq,w as preloadQuery,G as preloadedQueryResult,Y as queryCacheKey,p as reconcileOptimistic};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/client",
3
- "version": "1.0.0-alpha.156",
3
+ "version": "1.0.0-alpha.157",
4
4
  "description": "Lunora browser SDK: WebSocket transport, optimistic updates, and an offline mutation queue",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1 +0,0 @@
1
- class r{swUrl;scope;#e=void 0;#r="unregistered";#i;#s=new Set;constructor(e){this.swUrl=e.swUrl,this.scope=e.scope??"/",this.#i=e.onStatusChange}get status(){return this.#r}get registration(){return this.#e}get active(){return this.#e?.active!==null&&this.#e?.active!==void 0}async register(){if(!("serviceWorker"in navigator))return this.#t("unsupported"),!1;this.#t("registering");try{this.#e=await navigator.serviceWorker.register(this.swUrl,{scope:this.scope}),this.#t("active"),navigator.serviceWorker.addEventListener("message",this.#a)}catch{return this.#t("error"),!1}return!0}async unregister(){if(!this.#e)return!1;navigator.serviceWorker.removeEventListener("message",this.#a);const e=await this.#e.unregister();return this.#e=void 0,this.#t("unregistered"),e}postMessage(e){const t=this.#e?.active;t&&t.postMessage(e)}onMessage(e){return this.#s.add(e),()=>{this.#s.delete(e)}}#t(e){this.#r=e,this.#i?.(e)}#a=e=>{for(const t of this.#s)try{t(e)}catch{}}}export{r as ClientServiceWorker};
@@ -1 +0,0 @@
1
- const v=(e,r,d=!1)=>new Promise((a,s)=>{if(!e){s(new Error("No active service worker"));return}const o=r.correlationId??crypto.randomUUID(),n={...r,correlationId:o};if(d){let i;const t=c=>{c.data.correlationId===o&&(clearTimeout(i),navigator.serviceWorker.removeEventListener("message",t),a(c.data.payload))};i=setTimeout(()=>{navigator.serviceWorker.removeEventListener("message",t),s(new Error(`SW message ${o} timed out`))},3e4),navigator.serviceWorker.addEventListener("message",t),e.postMessage(n)}else e.postMessage(n),a(void 0)}),l=(e,r)=>({type:`${e.type}:reply`,payload:r,correlationId:e.correlationId});export{l as createReply,v as sendToSw};