@storesjs/stores 0.8.6 → 0.9.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/dist/config.d.ts +37 -7
- package/dist/createBaseStore.d.ts +2 -2
- package/dist/createQueryStore.d.ts +7 -23
- package/dist/createStoreWithEqualityFn.d.ts +5 -0
- package/dist/createVirtualStore.d.ts +4 -3
- package/dist/derivedStore/{globalDeriveScheduler.d.ts → cascadeScheduler.d.ts} +9 -1
- package/dist/derivedStore/deriveProxy.d.ts +6 -16
- package/dist/derivedStore/pathFinder.d.ts +27 -0
- package/dist/errors.d.ts +14 -0
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +5 -0
- package/dist/index.d.ts +3 -1
- package/dist/logger.d.ts +0 -5
- package/dist/middleware/createHydrationGate.d.ts +1 -1
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +3 -1
- package/dist/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/queryStore/signalTypes.d.ts +13 -0
- package/dist/queryStore/types.d.ts +35 -30
- package/dist/signal.d.ts +2 -11
- package/dist/storage/storageCreators.d.ts +1 -1
- package/dist/sync/syncEnhancer.d.ts +4 -0
- package/dist/sync/types.d.ts +53 -128
- package/dist/types/functions.d.ts +19 -2
- package/dist/types/objects.d.ts +10 -3
- package/dist/types/utils.d.ts +1 -1
- package/dist/types.d.ts +35 -32
- package/dist/utils/core.d.ts +23 -4
- package/dist/utils/createStoreActions.d.ts +3 -3
- package/dist/utils/persistUtils.d.ts +2 -2
- package/dist/utils/storeUtils.d.ts +22 -15
- package/dist/utils/time.d.ts +0 -3
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-3U5A7HQV.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/package.json +17 -12
- package/dist/sync/transport.d.ts +0 -113
- package/dist/web/chunk-B3GRBY25.mjs +0 -1
package/dist/sync/transport.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { SyncAuthPayload, SyncUpdate } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* ### `SyncTransportMessage`
|
|
4
|
-
*
|
|
5
|
-
* Message envelope for sync engine communication over a transport layer.
|
|
6
|
-
* Supports sync updates and presence coordination.
|
|
7
|
-
*/
|
|
8
|
-
export type SyncTransportMessage<T extends Record<string, unknown> = Record<string, unknown>> = PingMessage | {
|
|
9
|
-
type: 'sync-update';
|
|
10
|
-
storeKey: string;
|
|
11
|
-
update: SyncUpdate<T>;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'auth-challenge';
|
|
14
|
-
code: string;
|
|
15
|
-
message?: string;
|
|
16
|
-
} | {
|
|
17
|
-
type: 'auth-error';
|
|
18
|
-
code: string;
|
|
19
|
-
message?: string;
|
|
20
|
-
} | {
|
|
21
|
-
type: 'presence-join';
|
|
22
|
-
storeKey: string;
|
|
23
|
-
userId: string;
|
|
24
|
-
userData?: unknown;
|
|
25
|
-
} | {
|
|
26
|
-
type: 'presence-leave';
|
|
27
|
-
storeKey: string;
|
|
28
|
-
userId: string;
|
|
29
|
-
} | {
|
|
30
|
-
type: 'presence-update';
|
|
31
|
-
storeKey: string;
|
|
32
|
-
userId: string;
|
|
33
|
-
userData: unknown;
|
|
34
|
-
};
|
|
35
|
-
export type PingMessage = {
|
|
36
|
-
readonly type: 'ping';
|
|
37
|
-
} | {
|
|
38
|
-
readonly type: 'pong';
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* ### `SyncTransport`
|
|
42
|
-
*
|
|
43
|
-
* Abstract transport interface for network-based sync engines.
|
|
44
|
-
* Implementations can use WebSockets, SSE, HTTP long-polling, or any other
|
|
45
|
-
* bidirectional communication protocol.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const transport = new WebSocketTransport('ws://localhost:3000');
|
|
50
|
-
* await transport.connect();
|
|
51
|
-
*
|
|
52
|
-
* transport.onMessage(message => {
|
|
53
|
-
* if (message.type === 'sync-update') {
|
|
54
|
-
* // Handle update
|
|
55
|
-
* }
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* transport.send({
|
|
59
|
-
* type: 'sync-update',
|
|
60
|
-
* storeKey: 'my-store',
|
|
61
|
-
* update: { ... }
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export interface SyncTransport {
|
|
66
|
-
/**
|
|
67
|
-
* Establishes connection to the transport endpoint.
|
|
68
|
-
* @throws {Error} If connection fails
|
|
69
|
-
*/
|
|
70
|
-
connect(options?: SyncTransportConnectOptions): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Closes the transport connection and cleans up resources.
|
|
73
|
-
*/
|
|
74
|
-
disconnect(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Sends a message through the transport.
|
|
77
|
-
* Messages sent while disconnected may be queued or dropped depending on implementation.
|
|
78
|
-
*
|
|
79
|
-
* @param message - The message to send
|
|
80
|
-
*/
|
|
81
|
-
send(message: SyncTransportMessage): void;
|
|
82
|
-
/**
|
|
83
|
-
* Registers a handler for incoming messages.
|
|
84
|
-
* Only one handler can be registered at a time; subsequent calls replace the previous handler.
|
|
85
|
-
*
|
|
86
|
-
* @param handler - Function to call when messages arrive
|
|
87
|
-
*/
|
|
88
|
-
onMessage(handler: (message: SyncTransportMessage) => void): void;
|
|
89
|
-
/**
|
|
90
|
-
* Registers a handler for connection state changes.
|
|
91
|
-
*
|
|
92
|
-
* @param handler - Function to call when connection state changes
|
|
93
|
-
*/
|
|
94
|
-
onConnectionChange(handler: (connected: boolean) => void): void;
|
|
95
|
-
/**
|
|
96
|
-
* Updates the active authentication payload. Transports may choose to
|
|
97
|
-
* reconnect automatically or apply the metadata lazily on the next handshake.
|
|
98
|
-
*/
|
|
99
|
-
updateAuth?(auth: SyncAuthPayload | null): void;
|
|
100
|
-
/**
|
|
101
|
-
* Current connection status.
|
|
102
|
-
*/
|
|
103
|
-
readonly connected: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Unique identifier for this transport client.
|
|
106
|
-
* Used to filter self-updates in distributed sync.
|
|
107
|
-
*/
|
|
108
|
-
readonly clientId: string;
|
|
109
|
-
}
|
|
110
|
-
export type SyncTransportConnectOptions = {
|
|
111
|
-
readonly auth?: SyncAuthPayload | null;
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e="undefined"!=typeof window&&"undefined"!=typeof document,t=!1,r="development"===process.env.NODE_ENV,o="test"===process.env.NODE_ENV,n=e=>e();function s(){return"undefined"!=typeof window?window.localStorage:null}var i=class extends Error{constructor(e,t){super(e),this.name="StoresError",this.cause=c(t)}},a={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!o&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function c(e){return e instanceof Error?e:new Error(String(e))}var l="stores/core/sync-channel",u=`${l}:storage:`;function d(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var h,y,g,f=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=Object.create(null);for(const r of Object.entries(e.values))t[r[0]]=r[1];const r={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(r)}},p=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(u))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){a.error(new i("[sync] Failed to parse storage event payload"),{error:e})}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(l),this.storage=d(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),e&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const r=Object.create(null);for(const o of e.fields)Object.prototype.hasOwnProperty.call(t.values,o)&&(r[o]=t.values[o]);Object.keys(r).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:r})};let r=this.listeners.get(e.key);return r||(r=new Set,this.listeners.set(e.key,r)),r.add(t),new f({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){a.error(new i("[sync] Failed to broadcast update"),{error:e})}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const r of t)r(e)}removeListener(e,t){const r=this.listeners.get(e);r&&(r.delete(t),r.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=d()),!this.storage)return;const t=`${u}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){a.error(new i("[sync] Failed to write broadcast payload to storage"),{error:e})}}},w=class{destroy(){}publish(){}},m=class{constructor(){this.sessionId="noop"}register(e){return new w}},v="stores:",b=!1;function S(e){var t;r&&function(){if(b)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,a=t),g??(g=I(e))}function E(){return g??(g=I(void 0))}function O(){b=!0}function I(t){return{storage:t?.storage??(r=t?.storageKeyPrefix??v,{clearAll(){try{const e=s();if(!e)return;const t=[];for(let o=0;o<e.length;o++){const n=e.key(o);n?.startsWith(r)&&t.push(n)}for(const r of t)e.removeItem(r)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const t=s();return null!==t?.getItem(`${r}${e}`)},delete(e){try{const t=s();t?.removeItem(`${r}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=s();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const t=s();return t?t.getItem(`${r}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,t){try{const o=s();o?.setItem(`${r}${e}`,t)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:t?.syncEngine??(e?(h||(h=new p),h):(y||(y=new m),y))};var r}function _(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function $(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}function j(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function k(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function K(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}export{v as DEFAULT_STORAGE_KEY_PREFIX,e as IS_BROWSER,r as IS_DEV,t as IS_IOS,o as IS_TEST,i as StoresError,S as configureStores,c as ensureError,E as getStoresConfig,k as hasOwn,K as isPlainObject,j as isPromiseLike,a as logger,O as markStoreCreated,_ as replacer,$ as reviver,n as unstable_batchedUpdates};
|