@laboverwire/stitch 0.4.1 → 0.5.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/CHANGELOG.md +60 -0
- package/README.md +8 -5
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +1 -1
- package/dist/internal-list-apply.js.map +1 -1
- package/dist/react/context.js.map +1 -1
- package/dist/react/hooks/useChildCounts.js.map +1 -1
- package/dist/react/hooks/useConnectionStatus.js.map +1 -1
- package/dist/react/hooks/useEntitySnapshot.js.map +1 -1
- package/dist/react/hooks/useRootEntityList.js.map +1 -1
- package/dist/react/hooks/useScopedEntities.js.map +1 -1
- package/dist/react/hooks/useSyncScope.js.map +1 -1
- package/dist/react/hooks/useTopLevelEntities.js.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -2
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js.map +1 -1
- package/dist/store.d.ts +2 -2
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +190 -724
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +23 -161
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -6
- package/dist/types.js.map +1 -1
- package/dist/vue/StitchAuth.js.map +1 -1
- package/dist/vue/StoreRoot.js.map +1 -1
- package/dist/vue/composables/useChildCounts.js.map +1 -1
- package/dist/vue/composables/useConnectionStatus.js.map +1 -1
- package/dist/vue/composables/useEntitySnapshot.js.map +1 -1
- package/dist/vue/composables/useRootEntityList.js.map +1 -1
- package/dist/vue/composables/useScopedEntities.js.map +1 -1
- package/dist/vue/composables/useStore.js.map +1 -1
- package/dist/vue/composables/useSyncScope.js.map +1 -1
- package/dist/vue/composables/useTopLevelEntities.js.map +1 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/injection-key.js.map +1 -1
- package/package.json +17 -8
- package/dist/internal-utils.d.ts +0 -3
- package/dist/internal-utils.d.ts.map +0 -1
- package/dist/internal-utils.js +0 -15
- package/dist/internal-utils.js.map +0 -1
- package/dist/internal-wasm-error.d.ts +0 -9
- package/dist/internal-wasm-error.d.ts.map +0 -1
- package/dist/internal-wasm-error.js +0 -48
- package/dist/internal-wasm-error.js.map +0 -1
- package/dist/memory-store.d.ts +0 -3
- package/dist/memory-store.d.ts.map +0 -1
- package/dist/memory-store.js +0 -572
- package/dist/memory-store.js.map +0 -1
- package/dist/offline-queue.d.ts +0 -6
- package/dist/offline-queue.d.ts.map +0 -1
- package/dist/offline-queue.js +0 -361
- package/dist/offline-queue.js.map +0 -1
- package/dist/persistence-layer.d.ts +0 -7
- package/dist/persistence-layer.d.ts.map +0 -1
- package/dist/persistence-layer.js +0 -409
- package/dist/persistence-layer.js.map +0 -1
- package/dist/remote-sync-layer.d.ts +0 -8
- package/dist/remote-sync-layer.d.ts.map +0 -1
- package/dist/remote-sync-layer.js +0 -439
- package/dist/remote-sync-layer.js.map +0 -1
- package/dist/sync-engine.d.ts +0 -3
- package/dist/sync-engine.d.ts.map +0 -1
- package/dist/sync-engine.js +0 -643
- package/dist/sync-engine.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- _Nothing yet._
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Changed (breaking)
|
|
12
|
+
|
|
13
|
+
- **Store backend replaced by `@laboverwire/stitch-wasm`.** The entire TypeScript store — memory cache, IndexedDB persistence, MQTT sync, offline queue — has been removed. `@laboverwire/stitch` is now a thin, framework-agnostic binding layer: `src/store.ts` is a small adapter that wraps the Rust/WASM `Store` from `@laboverwire/stitch-wasm` (`^0.2.1`), and the package ships the same React and Vue bindings. All store/sync/persistence/offline-queue/MQTT logic now lives inside the wasm (compiled from the sibling `stitch-rs` repo).
|
|
14
|
+
- **`StoreOptions.remote` shape changed.** `remote` is now `{ url, clientId?, ticket?, username?, password? }` instead of `{ serverUrl, getTicket }`. `url` is a `ws://`|`wss://` MQTT endpoint; `ticket` is a JWT for MQTT v5 enhanced auth; `username`/`password` drive classic MQTT password auth. `persistence` is `{ dbName, passphrase? }` — supplying `passphrase` enables AES-GCM encryption.
|
|
15
|
+
- **`responseTopicPrefix` default moved off `$SYS`.** Default changed from `$SYS/responses` to `$DB/clients`. The previous default published responses under `$SYS`, which the MQTT 5 spec reserves for broker-internal use (§4.7.2) — production brokers (EMQX, HiveMQ, AWS IoT Core) reject client publishes under `$SYS` by default ACL, so the old default only worked against permissive or custom-configured brokers. Per-request response topic shape is unchanged: `{prefix}/{clientId}/{requestId}`. The `responseTopicPrefix` config field still exists on `StoreConfig` and is forwarded to the wasm; only the implementation moved. Deployments overriding `responseTopicPrefix` explicitly are unaffected. Deployments relying on the old default must either set `responseTopicPrefix: '$SYS/responses'` to preserve current behavior or update broker ACLs to accept the new `$DB/clients/...` topic.
|
|
16
|
+
- **Subscription callbacks are now asynchronous.** `subscribeToEntity` and `subscribeToScope` callbacks fire one tick after the mutating call resolves, not synchronously within it. Callers that relied on synchronous delivery must not assume the callback has run by the time `create`/`update`/`delete` returns.
|
|
17
|
+
- **`connectionStatus` values are lowercase** — `'connected' | 'connecting' | 'disconnected' | 'error' | 'offline'`.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **`@laboverwire/stitch-wasm` dependency** (`^0.2.1`) — the Rust/WASM store, MQTT client, and IndexedDB persistence, bundled as a single wasm-bindgen module.
|
|
22
|
+
- **Pre-initialize tolerance in the adapter.** The wasm store requires `initialize()` before use, but the TS adapter tolerates pre-init access: synchronous reads return empties (`[]` / `{}` / `null` / `0` / `'offline'`) before init, `subscribe*` defer wiring until `initialize()` resolves and then trigger a re-read, and async methods await init. React and Vue hooks are therefore safe to mount before the provider finishes initializing.
|
|
23
|
+
- **`Store.getVersion(scopeId, entity): number`** — reactivity token used by the memory snapshot cache.
|
|
24
|
+
- **`Store.pendingMutationCount(scopeId): Promise<number>`** — offline-queue depth for a scope.
|
|
25
|
+
|
|
26
|
+
### Removed
|
|
27
|
+
|
|
28
|
+
- **In-package store internals.** `src/memory-store.ts`, `src/persistence-layer.ts`, `src/remote-sync-layer.ts`, `src/sync-engine.ts`, `src/offline-queue.ts`, `src/internal-utils.ts`, and `src/internal-wasm-error.ts` deleted — their logic now lives in `@laboverwire/stitch-wasm`.
|
|
29
|
+
- **`mqdb-wasm` and `mqtt5-wasm` direct dependencies.** Both are now bundled inside `@laboverwire/stitch-wasm`.
|
|
30
|
+
- **Internal factory exports.** `createMemoryStore`, `createSyncEngine`, `createPersistenceLayer`, `createRemoteSyncLayer`, `createPersistentOfflineQueue`, `createInMemoryOfflineQueue` removed. The only value export is now `createStore`.
|
|
31
|
+
- **`OwnershipError` and `MqdbError` classes** removed — error handling for the wasm store no longer surfaces these TS types.
|
|
32
|
+
- **Session/auth-cache `Store` methods removed.** `getCachedUser`, `setCachedUser`, `clearCachedUser`, `hasPendingLogout`, `setPendingLogout`, and `flushPendingLogout` are no longer on `Store`. They were thin `sessionStorage` wrappers; apps that relied on them must reimplement the caching in application code.
|
|
33
|
+
- **Internal-layer interface types.** `SyncEngine`, `PersistenceLayer`, `RemoteSyncLayer`, `OfflineQueue`, `MutationSender`, `LocalAccessor`, `PendingMutation`, `ConsolidatedMutation`, `ScopeBundle`, `ScopeState`, `SyncMutation`, `MutationEvent` no longer exported. The public type surface is now `StoreConfig`, `EntityDefinition`, `SchemaField`, `ForeignKeyDefinition`, `ConnectionStatus`, `SortField`, `SortDirection`, `ListFilter`, `Store`, `StoreOptions`, `PersistenceConfig`, `RemoteConfig`, `MemoryStore`, `EntitySchema`, `DefaultSchema`, `EntityKey`, and `OriginTag`. The `MemoryStore` type still exists but is trimmed to `{ getSnapshot, getSnapshotAsMap, subscribeToScope }`.
|
|
34
|
+
- **Consumer Vite `server.fs.allow` / `optimizeDeps.exclude` guidance obsolete.** `stitch-wasm` ships a wasm-bindgen bundler-target ESM module (ESM wasm import proposal), so a consuming Vite app must instead add `vite-plugin-wasm` and `vite-plugin-top-level-await`, and set `build.target: 'esnext'` for production builds (the wasm module and the top-level-await plugin emit top-level `await`). The old `mqdb-wasm`/`mqtt5-wasm` filesystem-allow and dep-exclude instructions no longer apply and must be removed. This repo's `vitest.config.ts` now uses those two plugins and the browser test suite loads the real wasm.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- **React/Vue init-order safety.** Because the adapter tolerates pre-init access (see Added), hooks like `useEntitySnapshot`, `useScopedEntities`, and `useRootEntityList` no longer read stale or throwing state when a component mounts before the provider's `initialize()` resolves — `subscribe*` wires up and re-reads once init completes.
|
|
39
|
+
- **Brittle response-topic parsing** now lives in `@laboverwire/stitch-wasm`. The former `src/sync-engine.ts` regex that split `{prefix}/{clientId}/{requestId}` on a fixed segment count is gone along with the file; the wasm handles response-topic matching against the configured `responseTopicPrefix`.
|
|
40
|
+
|
|
41
|
+
### Unchanged
|
|
42
|
+
|
|
43
|
+
- **React bindings** — `StoreProvider`, `AuthProvider`, `useEntitySnapshot`, `useScopedEntities`, `useRootEntityList`, `useTopLevelEntities`, `useChildCounts`, `useConnectionStatus`, `useSyncScope`, `useStore` — and **Vue bindings** — `StoreRoot`, `StitchAuth`, matching composables, and `useStore` — keep the same API. `Store.reconnect(serverUrl, getTicket?)` also keeps its signature: the adapter resolves the ticket via `getTicket` and runs any reconnect validator.
|
|
44
|
+
|
|
45
|
+
## 0.4.3
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
|
|
49
|
+
- **Offline queue flush regression tests.** New `tests/unit/offline-queue-flush.test.ts` exercises `createInMemoryOfflineQueue.flushConsolidated` against the permanent/transient/conflict/ownership classifier paths added in 0.4.2, locking in the "drop after permanent or unknown error" terminal branch and the `OwnershipError` immediate re-throw.
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- **`typescript` bumped to `6.0.3`** (from `5.9.3`).
|
|
54
|
+
- **Dependabot grouped updates.** npm minor/patch and GitHub Actions groups updated to current versions.
|
|
55
|
+
|
|
56
|
+
## 0.4.2
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- **Offline queue retry loop on permanent constraint errors.** `flushConsolidated` in `src/offline-queue.ts` did not match MQDB's actual error string `unique constraint violation: <entity>.<field>` in its conflict regex, and the terminal `else` branch logged the error without dequeuing — so any unclassified failure retried every flush cycle, indefinitely. Conflict regex extended; new `isPermanentMutationError` helper in `internal-utils.ts` covers the full MQDB constraint-failure set (`unique constraint violation`, `foreign key violation`, `not null violation`, `cascade blocked`, `referenced by other entities`) and dropping mutations after permanent or unknown errors is now the explicit terminal branch with a one-time log line.
|
|
61
|
+
- **`foreign key violation` mis-classified as transient.** `isTransientSyncError` previously matched `foreign key violation`, which is a permanent constraint failure and would never succeed on retry. Removed from the transient regex; covered by the new permanent classifier above.
|
|
62
|
+
- **Behavior change to call out:** previously, any error not classified as transient/conflict/not-found/ownership stayed in the offline queue and re-ran every flush cycle (visible only as repeated console errors). After this release, those entries are dropped after one attempt with a `Dropping mutation after permanent error:` or `Dropping mutation after unknown error:` log.
|
|
63
|
+
- **Vite sourcemap warnings.** `tsconfig.build.json` enabled `sourceMap: true` but not `inlineSources`, so the published `.map` files referenced `../src/*.ts` paths that are not in the npm tarball. Vite warned for every `dist/*.js` consumer-side. Added `inlineSources: true`; source content is now embedded in the maps.
|
|
64
|
+
|
|
5
65
|
## 0.4.1
|
|
6
66
|
|
|
7
67
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @laboverwire/stitch
|
|
2
2
|
|
|
3
|
-
Reactive state synchronization
|
|
3
|
+
Reactive state synchronization for React and Vue. A thin, framework-agnostic binding layer over [`@laboverwire/stitch-wasm`](https://www.npmjs.com/package/@laboverwire/stitch-wasm) — a Rust/WASM package that owns the in-memory store, IndexedDB persistence, and MQTT-based remote sync. This package wraps that WASM `Store` in a small adapter and ships React and Vue 3 bindings on top; all store, sync, persistence, and offline-queue logic lives inside the WASM.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install @laboverwire/stitch
|
|
@@ -11,7 +11,7 @@ import { createStore } from '@laboverwire/stitch';
|
|
|
11
11
|
|
|
12
12
|
const store = createStore<Schema>(config, {
|
|
13
13
|
persistence: { dbName: 'my-app' },
|
|
14
|
-
remote: {
|
|
14
|
+
remote: { url: 'wss://mqtt.example.com', ticket: await fetchAuthTicket() },
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
await store.initialize();
|
|
@@ -20,15 +20,18 @@ await store.replaceScope('project-abc');
|
|
|
20
20
|
const tasks = store.getSnapshot('task', 'project-abc');
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
`remote.url` is a `ws://`/`wss://` MQTT endpoint. Pass `ticket` (a JWT) for MQTT v5 enhanced auth, or `username`/`password` for classic password auth. A `persistence.passphrase` enables AES-GCM encryption of the IndexedDB store.
|
|
24
|
+
|
|
23
25
|
## Documentation
|
|
24
26
|
|
|
25
27
|
- [Configuration](./docs/configuration.md) — `StoreConfig`, `StoreOptions`, scope model, typed schemas
|
|
26
|
-
- [Store API](./docs/api.md) — full method reference
|
|
28
|
+
- [Store API](./docs/api.md) — full method reference
|
|
27
29
|
- [React bindings](./docs/react.md) — providers, hooks, runnable example
|
|
28
30
|
- [Vue 3 bindings](./docs/vue.md) — providers, composables, runnable example
|
|
29
31
|
- [Concepts](./docs/concepts.md) — origin tags, offline queue, reconciliation, connection resilience
|
|
30
|
-
- [Vite consumer guide](./docs/vite-consumer.md) —
|
|
31
|
-
- [Architecture](./ARCHITECTURE.md) —
|
|
32
|
+
- [Vite consumer guide](./docs/vite-consumer.md) — consuming apps must add `vite-plugin-wasm` (and `vite-plugin-top-level-await`) so the bundler can load the WASM module
|
|
33
|
+
- [Architecture](./ARCHITECTURE.md) — layer composition, data flow, invariants
|
|
34
|
+
- [Upgrading to 0.5.0](./docs/upgrading-to-0.5.md) — breaking changes and step-by-step upgrade from 0.4.x
|
|
32
35
|
- [Changelog](./CHANGELOG.md)
|
|
33
36
|
- [Releasing](./RELEASING.md)
|
|
34
37
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export type { StoreConfig, EntityDefinition, SchemaField, ForeignKeyDefinition,
|
|
2
|
-
export { OwnershipError } from './types.ts';
|
|
3
|
-
export { MqdbError } from './internal-wasm-error.ts';
|
|
4
|
-
export { createMemoryStore } from './memory-store.ts';
|
|
5
|
-
export { createSyncEngine } from './sync-engine.ts';
|
|
1
|
+
export type { StoreConfig, EntityDefinition, SchemaField, ForeignKeyDefinition, ConnectionStatus, SortField, SortDirection, ListFilter, Store, StoreOptions, PersistenceConfig, RemoteConfig, MemoryStore, EntitySchema, DefaultSchema, EntityKey, OriginTag, } from './types.ts';
|
|
6
2
|
export { createStore } from './store.ts';
|
|
7
|
-
export { createPersistenceLayer } from './persistence-layer.ts';
|
|
8
|
-
export { createRemoteSyncLayer } from './remote-sync-layer.ts';
|
|
9
|
-
export { createPersistentOfflineQueue, createInMemoryOfflineQueue } from './offline-queue.ts';
|
|
10
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,UAAU,EACV,KAAK,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export { OwnershipError } from "./types.js";
|
|
2
|
-
export { MqdbError } from "./internal-wasm-error.js";
|
|
3
|
-
export { createMemoryStore } from "./memory-store.js";
|
|
4
|
-
export { createSyncEngine } from "./sync-engine.js";
|
|
5
1
|
export { createStore } from "./store.js";
|
|
6
|
-
export { createPersistenceLayer } from "./persistence-layer.js";
|
|
7
|
-
export { createRemoteSyncLayer } from "./remote-sync-layer.js";
|
|
8
|
-
export { createPersistentOfflineQueue, createInMemoryOfflineQueue } from "./offline-queue.js";
|
|
9
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export type {\n StoreConfig,\n EntityDefinition,\n SchemaField,\n ForeignKeyDefinition,\n ConnectionStatus,\n SortField,\n SortDirection,\n ListFilter,\n Store,\n StoreOptions,\n PersistenceConfig,\n RemoteConfig,\n MemoryStore,\n EntitySchema,\n DefaultSchema,\n EntityKey,\n OriginTag,\n} from './types.ts';\n\nexport { createStore } from './store.ts';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-list-apply.js","sourceRoot":"","sources":["../src/internal-list-apply.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CACxB,IAAgB,EAChB,MAAe,EACf,EAAkC;IAElC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,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AAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAkB,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzB,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC;QACD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["export type ListItem = Record<string, unknown> & { id: string };\n\nexport function applyEvent(\n prev: ListItem[],\n entity: unknown,\n op: 'insert' | 'update' | 'delete'\n): ListItem[] {\n if (!entity || typeof entity !== 'object' || !('id' in entity)) return prev;\n const item = entity as ListItem;\n const idx = prev.findIndex((d) => d.id === item.id);\n switch (op) {\n case 'insert': {\n if (idx < 0) return [...prev, item];\n const next = prev.slice();\n next[idx] = item;\n return next;\n }\n case 'update': {\n if (idx < 0) return prev;\n const next = prev.slice();\n next[idx] = item;\n return next;\n }\n case 'delete': {\n if (idx < 0) return prev;\n return [...prev.slice(0, idx), ...prev.slice(idx + 1)];\n }\n default:\n return prev;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAUlD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAE1E,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAUlD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAE1E,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ConnectionStatus, Store } from '../types.ts';\n\nexport interface StoreContextValue {\n store: Store;\n initialized: boolean;\n connectionStatus: ConnectionStatus;\n error: Error | null;\n}\n\nexport const StoreContext = createContext<StoreContextValue | null>(null);\n\nexport function useStore(): StoreContextValue {\n const ctx = useContext(StoreContext);\n if (!ctx) throw new Error('useStore must be used within a StoreProvider');\n return ctx;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChildCounts.js","sourceRoot":"","sources":["../../../src/react/hooks/useChildCounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,MAAc;IACzD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;IAEjD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAsB,IAAI,GAAG,EAAE,CAAC,CAAC;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,MAAM,MAAM,GAAmE,EAAE,CAAC;QAElF,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,KAAK;iBACF,IAAI,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;iBAChD,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBAChB,IAAI,SAAS;oBAAE,OAAO;gBACtB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;gBAC3C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;oBAC7B,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAW,CAAC;oBACzC,IAAI,GAAG,EAAE,CAAC;wBACR,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAClD,CAAC;gBACH,CAAC;gBAED,KAAK,MAAM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IAAI,EAAE,EAAE;gBACjB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACnC,IAAI,EAAE,KAAK,QAAQ,EAAE,CAAC;oBACpB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;gBAC7B,CAAC;qBAAM,IAAI,EAAE,KAAK,QAAQ,EAAE,CAAC;oBAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC1C,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC,CACF,CAAC;QAEF,QAAQ,EAAE,CAAC;QAEX,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAEhC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\nimport type { Store } from '../../types.ts';\n\nexport function useChildCounts(store: Store, entity: string): Map<string, number> {\n const scopeField = store.config.scope.scopeField;\n\n const [counts, setCounts] = useState<Map<string, number>>(new Map());\n\n useEffect(() => {\n let fetched = false;\n let cancelled = false;\n const buffer: Array<{ entity: unknown; op: 'insert' | 'update' | 'delete' }> = [];\n\n const fetchAll = () => {\n store\n .list(entity, { projection: ['id', scopeField] })\n .then((records) => {\n if (cancelled) return;\n const countMap = new Map<string, number>();\n for (const record of records) {\n const sid = record[scopeField] as string;\n if (sid) {\n countMap.set(sid, (countMap.get(sid) ?? 0) + 1);\n }\n }\n\n for (const { entity: e, op } of buffer) {\n if (op === 'update') continue;\n const n = e as Record<string, unknown>;\n const sid = n[scopeField] as string;\n if (!sid) continue;\n const current = countMap.get(sid) ?? 0;\n if (op === 'insert') {\n countMap.set(sid, current + 1);\n } else if (op === 'delete') {\n countMap.set(sid, Math.max(0, current - 1));\n }\n }\n buffer.length = 0;\n fetched = true;\n setCounts(countMap);\n })\n .catch(() => {\n if (cancelled) return;\n fetched = true;\n buffer.length = 0;\n });\n };\n\n const unsubscribe = store.subscribeToEntity(\n entity,\n (entityData: unknown, op: 'insert' | 'update' | 'delete') => {\n if (entityData === null) {\n fetchAll();\n return;\n }\n if (op === 'update') return;\n if (typeof entityData !== 'object') return;\n\n if (!fetched) {\n buffer.push({ entity: entityData, op });\n return;\n }\n\n const record = entityData as Record<string, unknown>;\n const sid = record[scopeField] as string;\n if (!sid) return;\n\n setCounts((prev) => {\n const next = new Map(prev);\n const current = next.get(sid) ?? 0;\n if (op === 'insert') {\n next.set(sid, current + 1);\n } else if (op === 'delete') {\n next.set(sid, Math.max(0, current - 1));\n }\n return next;\n });\n }\n );\n\n fetchAll();\n\n return () => {\n cancelled = true;\n unsubscribe();\n };\n }, [store, entity, scopeField]);\n\n return counts;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnectionStatus.js","sourceRoot":"","sources":["../../../src/react/hooks/useConnectionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,UAAU,mBAAmB,CAAC,KAAY;IAC9C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAmB,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE/E,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,KAAK,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"useConnectionStatus.js","sourceRoot":"","sources":["../../../src/react/hooks/useConnectionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,UAAU,mBAAmB,CAAC,KAAY;IAC9C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAmB,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE/E,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,KAAK,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\nimport type { ConnectionStatus, Store } from '../../types.ts';\n\nexport function useConnectionStatus(store: Store): ConnectionStatus {\n const [status, setStatus] = useState<ConnectionStatus>(store.connectionStatus);\n\n useEffect(() => {\n return store.subscribeToConnectionStatus(setStatus);\n }, [store]);\n\n return status;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntitySnapshot.js","sourceRoot":"","sources":["../../../src/react/hooks/useEntitySnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAG7C,MAAM,WAAW,GAA8B,EAAE,CAAC;AAClD,MAAM,SAAS,GAA4C,EAAE,CAAC;AAE9D,SAAS,aAAa,CAAC,aAAkC;IACvD,IAAI,QAAQ,IAAI,aAAa;QAAE,OAAQ,aAAuB,CAAC,MAAM,CAAC;IACtE,OAAO,aAA4B,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAA0B,EAC1B,OAAe,EACf,MAAc;IAEd,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,oBAAoB,CACzB,CAAC,aAAa,EAAE,EAAE;QAChB,IAAI,CAAC,OAAO;YAAE,OA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AAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,oBAAoB,CACzB,CAAC,aAAa,EAAE,EAAE;QAChB,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACjE,CAAC,EACD,GAAG,EAAE;QACH,IAAI,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC;QACjC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAA0B,EAC1B,OAAe,EACf,MAAc;IAEd,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,oBAAoB,CACzB,CAAC,aAAa,EAAE,EAAE;QAChB,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACjE,CAAC,EACD,GAAG,EAAE;QACH,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAC/B,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type { MemoryStore, Store } from '../../types.ts';\n\nconst EMPTY_ARRAY: Record<string, unknown>[] = [];\nconst EMPTY_MAP: Record<string, Record<string, unknown>> = {};\n\nfunction resolveMemory(storeOrMemory: MemoryStore | Store): MemoryStore {\n if ('memory' in storeOrMemory) return (storeOrMemory as Store).memory;\n return storeOrMemory as MemoryStore;\n}\n\nexport function useEntitySnapshot(\n store: MemoryStore | Store,\n scopeId: string,\n entity: string\n): Record<string, unknown>[] {\n const memory = resolveMemory(store);\n return useSyncExternalStore(\n (onStoreChange) => {\n if (!scopeId) return () => {};\n return memory.subscribeToScope(scopeId, entity, onStoreChange);\n },\n () => {\n if (!scopeId) return EMPTY_ARRAY;\n return memory.getSnapshot(entity, scopeId);\n }\n );\n}\n\nexport function useEntitySnapshotAsMap(\n store: MemoryStore | Store,\n scopeId: string,\n entity: string\n): Record<string, Record<string, unknown>> {\n const memory = resolveMemory(store);\n return useSyncExternalStore(\n (onStoreChange) => {\n if (!scopeId) return () => {};\n return memory.subscribeToScope(scopeId, entity, onStoreChange);\n },\n () => {\n if (!scopeId) return EMPTY_MAP;\n return memory.getSnapshotAsMap(entity, scopeId);\n }\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRootEntityList.js","sourceRoot":"","sources":["../../../src/react/hooks/useRootEntityList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAiB,MAAM,8BAA8B,CAAC;AAEzE,MAAM,UAAU,iBAAiB,CAAC,KAAY;IAM5C,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;IAEjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAa,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACrC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,gB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import type { Store } from '../../types.ts';\nimport { applyEvent, type ListItem } from '../../internal-list-apply.ts';\n\nexport function useRootEntityList(store: Store): {\n items: ListItem[];\n loading: boolean;\n error: Error | null;\n refetch: () => Promise<void>;\n} {\n const rootEntity = store.config.scope.rootEntity;\n\n const [items, setItems] = useState<ListItem[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const refetch = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const entities = await store.listRootEntities();\n setItems(entities as ListItem[]);\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to fetch root entities'));\n } finally {\n setLoading(false);\n }\n }, [store]);\n\n useEffect(() => {\n let fetched = false;\n let cancelled = false;\n const buffer: Array<{ entity: unknown; op: 'insert' | 'update' | 'delete' }> = [];\n\n const fetchAll = () => {\n store\n .listRootEntities()\n .then((entities) => {\n if (cancelled) return;\n let result = entities as ListItem[];\n for (const { entity, op } of buffer) {\n result = applyEvent(result, entity, op);\n }\n buffer.length = 0;\n fetched = true;\n setItems(result);\n setLoading(false);\n })\n .catch((err) => {\n if (cancelled) return;\n fetched = true;\n buffer.length = 0;\n setError(err instanceof Error ? err : new Error('Failed to fetch root entities'));\n setLoading(false);\n });\n };\n\n const unsubscribe = store.subscribeToEntity(\n rootEntity,\n (entity: unknown, op: 'insert' | 'update' | 'delete') => {\n if (entity === null) {\n fetchAll();\n return;\n }\n if (!fetched) {\n buffer.push({ entity, op });\n return;\n }\n setItems((prev) => applyEvent(prev, entity, op));\n }\n );\n\n fetchAll();\n\n return () => {\n cancelled = true;\n unsubscribe();\n };\n }, [store, rootEntity]);\n\n return { items, loading, error, refetch };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScopedEntities.js","sourceRoot":"","sources":["../../../src/react/hooks/useScopedEntities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEz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AE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBACxC,OAAO;YACT,CAAC;YAED,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC,CACF,CAAC;QAEF,QAAQ,EAAE,CAAC;QAEX,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import { useEffect, useState, useCallback } from 'react';\nimport type { Store } from '../../types.ts';\nimport { applyEvent, type ListItem } from '../../internal-list-apply.ts';\n\nexport function useScopedEntities(\n store: Store,\n scopeId: string | null,\n entity: string\n): {\n data: ListItem[];\n loading: boolean;\n error: Error | null;\n refetch: () => Promise<void>;\n} {\n const effectiveScopeField = store.config.scope.scopeField;\n const [data, setData] = useState<ListItem[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const refetch = useCallback(async () => {\n if (!scopeId) {\n setData([]);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n\n try {\n const entities = await store.list(entity, { scopeId });\n setData(entities as ListItem[]);\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to fetch entities'));\n } finally {\n setLoading(false);\n }\n }, [store, scopeId, entity]);\n\n useEffect(() => {\n if (!scopeId) {\n Promise.resolve().then(() => setData([]));\n return;\n }\n\n let fetched = false;\n let cancelled = false;\n const buffer: Array<{ entity: unknown; op: 'insert' | 'update' | 'delete' }> = [];\n\n const fetchAll = () => {\n store\n .list(entity, { scopeId })\n .then((entities) => {\n if (cancelled) return;\n let result = entities as ListItem[];\n for (const { entity: e, op } of buffer) {\n result = applyEvent(result, e, op);\n }\n buffer.length = 0;\n fetched = true;\n setData(result);\n setLoading(false);\n })\n .catch((err) => {\n if (cancelled) return;\n fetched = true;\n buffer.length = 0;\n setError(err instanceof Error ? err : new Error('Failed to fetch entities'));\n setLoading(false);\n });\n };\n\n const unsubscribe = store.subscribeToEntity(\n entity,\n (entityData: unknown, op: 'insert' | 'update' | 'delete') => {\n if (entityData === null) {\n fetchAll();\n return;\n }\n const rec = entityData as Record<string, unknown>;\n if (rec[effectiveScopeField] !== scopeId) {\n return;\n }\n\n if (!fetched) {\n buffer.push({ entity: entityData, op });\n return;\n }\n\n setData((prev) => applyEvent(prev, entityData, op));\n }\n );\n\n fetchAll();\n\n return () => {\n cancelled = true;\n unsubscribe();\n };\n }, [store, scopeId, entity, effectiveScopeField]);\n\n return { data, loading, error, refetch };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSyncScope.js","sourceRoot":"","sources":["../../../src/react/hooks/useSyncScope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGjE,MAAM,UAAU,YAAY,CAC1B,KAAY,EACZ,OAAsB;IAOtB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAC9C,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1C,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,OAAO,GAAG,OAAO,CAAC;IACtC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,WAAW,CAAC,KA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9B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,YAAY,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC/E,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAErB,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACxC,IAAI,CAAC,SAAS,CAAC,OAAO;YAAE,OAAO;QAE/B,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC1C,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;gBACtB,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACpD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAErB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import { useEffect, useState, useCallback, useRef } from 'react';\nimport type { Store } from '../../types.ts';\n\nexport function useSyncScope(\n store: Store,\n scopeId: string | null\n): {\n syncing: boolean;\n syncError: Error | null;\n openScope: () => Promise<void>;\n closeScope: () => Promise<void>;\n} {\n const [syncing, setSyncing] = useState(false);\n const [syncError, setSyncError] = useState<Error | null>(null);\n const openedRef = useRef<string | null>(null);\n const currentScopeIdRef = useRef(scopeId);\n\n useEffect(() => {\n currentScopeIdRef.current = scopeId;\n }, [scopeId]);\n\n const openScope = useCallback(async () => {\n if (!scopeId || openedRef.current === scopeId) return;\n\n setSyncing(true);\n setSyncError(null);\n\n try {\n await store.replaceScope(scopeId);\n if (currentScopeIdRef.current === scopeId) {\n openedRef.current = scopeId;\n }\n } catch (err) {\n setSyncError(err instanceof Error ? err : new Error('Failed to open scope'));\n } finally {\n setSyncing(false);\n }\n }, [store, scopeId]);\n\n const closeScope = useCallback(async () => {\n if (!openedRef.current) return;\n\n try {\n await store.closeScope(openedRef.current);\n openedRef.current = null;\n } catch (err) {\n console.error('[useSyncScope] Failed to close scope:', err);\n }\n }, [store]);\n\n useEffect(() => {\n return () => {\n if (openedRef.current) {\n store.closeScope(openedRef.current).catch(() => {});\n openedRef.current = null;\n }\n };\n }, [store, scopeId]);\n\n return { syncing, syncError, openScope, closeScope };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTopLevelEntities.js","sourceRoot":"","sources":["../../../src/react/hooks/useTopLevelEntities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAiB,MAAM,8BAA8B,CAAC;AAEzE,MAAM,UAAU,mBAAmB,CACjC,KAAY,EACZ,MAAc;IAKd,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAa,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,GAAG,KAAK,C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C;gBACD,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;gBAClB,OAAO,GAAG,IAAI,CAAC;gBACf,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACjB,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE;gBACV,IAAI,SAAS;oBAAE,OAAO;gBACtB,OAAO,GAAG,IAAI,CAAC;gBACf,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;gBAClB,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,KAAK,CAAC,iBAAiB,CACzC,MAAM,EACN,CAAC,UAAmB,EAAE,EAAkC,EAAE,EAAE;YAC1D,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,QAAQ,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;gBACxC,OAAO;YACT,CAAC;YACD,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;QACvD,CAAC,CACF,CAAC;QAEF,QAAQ,EAAE,CAAC;QAEX,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\nimport type { Store } from '../../types.ts';\nimport { applyEvent, type ListItem } from '../../internal-list-apply.ts';\n\nexport function useTopLevelEntities(\n store: Store,\n entity: string\n): {\n items: ListItem[];\n loading: boolean;\n} {\n const [items, setItems] = useState<ListItem[]>([]);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n let fetched = false;\n let cancelled = false;\n const buffer: Array<{ entity: unknown; op: 'insert' | 'update' | 'delete' }> = [];\n\n const fetchAll = () => {\n store\n .list(entity)\n .then((entities) => {\n if (cancelled) return;\n let result = entities as ListItem[];\n for (const { entity: e, op } of buffer) {\n result = applyEvent(result, e, op);\n }\n buffer.length = 0;\n fetched = true;\n setItems(result);\n setLoading(false);\n })\n .catch(() => {\n if (cancelled) return;\n fetched = true;\n buffer.length = 0;\n setLoading(false);\n });\n };\n\n const unsubscribe = store.subscribeToEntity(\n entity,\n (entityData: unknown, op: 'insert' | 'update' | 'delete') => {\n if (entityData === null) {\n fetchAll();\n return;\n }\n if (!fetched) {\n buffer.push({ entity: entityData, op });\n return;\n }\n setItems((prev) => applyEvent(prev, entityData, op));\n }\n );\n\n fetchAll();\n\n return () => {\n cancelled = true;\n unsubscribe();\n };\n }, [store, entity]);\n\n return { items, loading };\n}\n"]}
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAgB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAgB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { StoreContext, useStore } from './context.ts';\nexport type { StoreContextValue } from './context.ts';\nexport { StoreProvider, AuthProvider } from './provider.tsx';\nexport { useEntitySnapshot, useEntitySnapshotAsMap } from './hooks/useEntitySnapshot.ts';\nexport { useConnectionStatus } from './hooks/useConnectionStatus.ts';\nexport { useScopedEntities } from './hooks/useScopedEntities.ts';\nexport { useRootEntityList } from './hooks/useRootEntityList.ts';\nexport { useTopLevelEntities } from './hooks/useTopLevelEntities.ts';\nexport { useChildCounts } from './hooks/useChildCounts.ts';\nexport { useSyncScope } from './hooks/useSyncScope.ts';\n"]}
|
package/dist/react/provider.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ interface StoreProviderProps {
|
|
|
12
12
|
* handlers, logout gating) live in {@link AuthProvider}; compose both if you need
|
|
13
13
|
* an auth-aware app.
|
|
14
14
|
*/
|
|
15
|
-
export declare function StoreProvider({ store, serverUrl, getTicket, children }: StoreProviderProps): import("react
|
|
15
|
+
export declare function StoreProvider({ store, serverUrl, getTicket, children }: StoreProviderProps): import("react").JSX.Element;
|
|
16
16
|
interface AuthProviderProps {
|
|
17
17
|
store: Store;
|
|
18
18
|
userId?: string;
|
|
@@ -27,6 +27,6 @@ interface AuthProviderProps {
|
|
|
27
27
|
* Controls `setAuthenticatedUser`, session-invalid + reconnect-validator handlers, and
|
|
28
28
|
* tears down the store via `resetForLogout()` when `authenticated` transitions to false.
|
|
29
29
|
*/
|
|
30
|
-
export declare function AuthProvider({ store, userId, authenticated, onSessionInvalid, onReconnectValidate, children, }: AuthProviderProps): import("react
|
|
30
|
+
export declare function AuthProvider({ store, userId, authenticated, onSessionInvalid, onReconnectValidate, children, }: AuthProviderProps): import("react").JSX.Element;
|
|
31
31
|
export {};
|
|
32
32
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,aAAa,CAAC;AAG3D,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,aAAa,CAAC;AAG3D,UAAU,kBAAkB;IAC1B,KA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;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,MAAM,EACN,aAAa,GAAG,IAAI,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,GACU;IAClB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,KAAK,CAAC,UAAU,EAAE,CAAC;YACnB,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QACD,IAAI,MAAM;YAAE,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,gBAAgB;YAAE,KAAK,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;QACvE,IAAI,mBAAmB;YAAE,KAAK,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;IAC5E,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAE1E,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC","sourcesContent":["import { useEffect, useState, useMemo, type ReactNode } from 'react';\nimport type { ConnectionStatus, Store } from '../types.ts';\nimport { StoreContext } from './context.ts';\n\ninterface StoreProviderProps {\n store: Store;\n serverUrl?: string;\n getTicket?: () => Promise<string>;\n children: ReactNode;\n}\n\n/**\n * Store lifecycle only — initializes the store, tracks connection status, and\n * handles visibility-change reconnection. Authentication concerns (userId, session\n * handlers, logout gating) live in {@link AuthProvider}; compose both if you need\n * an auth-aware app.\n */\nexport function StoreProvider({ store, serverUrl, getTicket, children }: StoreProviderProps) {\n const [initialized, setInitialized] = useState(false);\n const [connectionStatus, setConnectionStatus] = useState<ConnectionStatus>('offline');\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n let mounted = true;\n\n async function init() {\n try {\n if (!store.ready) {\n await store.initialize();\n }\n if (mounted) setInitialized(true);\n } catch (err) {\n console.error('[StoreProvider] Initialization failed:', err);\n if (mounted) {\n setError(err instanceof Error ? err : new Error('Store initialization failed'));\n }\n }\n }\n\n init();\n\n return () => {\n mounted = false;\n };\n }, [store]);\n\n useEffect(() => {\n const unsubscribe = store.subscribeToConnectionStatus((status) => {\n setConnectionStatus(status);\n });\n\n function handleBeforeUnload() {\n store.disconnect();\n }\n window.addEventListener('beforeunload', handleBeforeUnload);\n\n return () => {\n unsubscribe();\n window.removeEventListener('beforeunload', handleBeforeUnload);\n };\n }, [store]);\n\n useEffect(() => {\n if (!initialized || !store.hasRemote) return;\n\n let lastHidden = 0;\n const STALE_THRESHOLD_MS = 30_000;\n\n function handleVisibilityChange() {\n if (document.hidden) {\n lastHidden = Date.now();\n return;\n }\n\n if (lastHidden > 0 && Date.now() - lastHidden > STALE_THRESHOLD_MS && serverUrl) {\n if (store.connectionStatus !== 'connected' && !store.isReconnecting) {\n store\n .reconnect(serverUrl, getTicket)\n .catch((err: unknown) =>\n console.error('[StoreProvider] Reconnect on wake failed:', err)\n );\n }\n }\n }\n\n document.addEventListener('visibilitychange', handleVisibilityChange);\n return () => document.removeEventListener('visibilitychange', handleVisibilityChange);\n }, [initialized, store, serverUrl, getTicket]);\n\n const contextValue = useMemo(\n () => ({ store, initialized, connectionStatus, error }),\n [store, initialized, connectionStatus, error]\n );\n\n return <StoreContext.Provider value={contextValue}>{children}</StoreContext.Provider>;\n}\n\ninterface AuthProviderProps {\n store: Store;\n userId?: string;\n /** When false, the store is torn down via `resetForLogout()` and remote sync disconnects. Defaults to `true`. */\n authenticated?: boolean;\n onSessionInvalid?: () => void;\n onReconnectValidate?: () => Promise<void>;\n children?: ReactNode;\n}\n\n/**\n * Binds authentication-related state to the store. Nest inside a {@link StoreProvider}.\n * Controls `setAuthenticatedUser`, session-invalid + reconnect-validator handlers, and\n * tears down the store via `resetForLogout()` when `authenticated` transitions to false.\n */\nexport function AuthProvider({\n store,\n userId,\n authenticated = true,\n onSessionInvalid,\n onReconnectValidate,\n children,\n}: AuthProviderProps) {\n useEffect(() => {\n if (!authenticated) {\n store.disconnect();\n store.resetForLogout();\n return;\n }\n if (userId) store.setAuthenticatedUser(userId);\n if (onSessionInvalid) store.setSessionInvalidHandler(onSessionInvalid);\n if (onReconnectValidate) store.setReconnectValidator(onReconnectValidate);\n }, [store, userId, authenticated, onSessionInvalid, onReconnectValidate]);\n\n return <>{children}</>;\n}\n"]}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createStore<S extends
|
|
1
|
+
import type { DefaultSchema, EntitySchema, Store, StoreConfig, StoreOptions } from './types.ts';
|
|
2
|
+
export declare function createStore<S extends EntitySchema = DefaultSchema>(config: StoreConfig, options?: StoreOptions): Store<S>;
|
|
3
3
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,aAAa,EAEb,YAAY,EAKZ,KAAK,EACL,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAuUpB,wBAAgB,WAAW,CAAC,CAAC,SAAS,YAAY,GAAG,aAAa,EAChE,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,CAAC,CAAC,CAAC,CAIV"}
|