ahmed-rivet-convex 2.2.3 → 2.2.4

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/README.md CHANGED
@@ -1,40 +1,30 @@
1
1
  # ahmed-rivet-convex
2
2
 
3
- Protocolbase's client-only Zero runtime for local-first synchronization with
4
- Convex as the source of truth.
3
+ A client-only, local-first data runtime for the browser: a reactive query
4
+ layer over an IndexedDB-backed store, with optimistic writes and durable
5
+ reconciliation.
5
6
 
6
7
  ## Published Interface
7
8
 
8
9
  Only the browser client is published:
9
10
 
10
- - `ahmed-rivet-convex` — Zero, schema builders, client types, and the generic
11
- `ConvexSyncAdapter`.
11
+ - `ahmed-rivet-convex` — the client, schema builders, and client types.
12
12
  - `ahmed-rivet-convex/react` — `ZeroProvider`, `useZero`, and `useQuery`.
13
13
 
14
- The upstream server, PostgreSQL, CLI, Solid, React Native, and Zero Cache
15
- Modules remain in the monorepo for development and source comparison, but are
16
- not part of the npm artifact.
14
+ Server, database, and CLI modules are not part of the npm artifact.
17
15
 
18
- The generic adapter is available from the package root:
16
+ ## Behaviour
19
17
 
20
- ```ts
21
- import {ConvexSyncAdapter} from 'ahmed-rivet-convex';
22
-
23
- const adapter = new ConvexSyncAdapter({
24
- zero,
25
- orgId,
26
- tables: ['issues', 'comments'],
27
- primaryKeys: {issues: 'id', comments: 'id'},
28
- convexBatchCrud,
29
- convexQuery,
30
- });
31
- ```
32
-
33
- Tables omitted from a Convex response are untouched. A table present with an
18
+ Tables omitted from a backend response are untouched. A table present with an
34
19
  empty array is authoritatively cleared. `pokeDirect()` resolves only after the
35
- new Zero head is durable in IndexedDB, and adapters call `markTablesReady()`
36
- only after that authoritative reconciliation succeeds. `localHydrationComplete`
37
- is a separate signal for warm-cache rendering.
20
+ new head is durable in IndexedDB, and adapters call `markTablesReady()` only
21
+ after that authoritative reconciliation succeeds. `localHydrationComplete` is a
22
+ separate signal for warm-cache rendering.
23
+
24
+ Adapters that supply their own pokes must floor every `lastMutationIDChanges`
25
+ entry with `currentLastMutationIDs`. An entry below what is already durable —
26
+ for another tab's client especially — makes the local store unable to persist,
27
+ permanently. See the API docs on that accessor.
38
28
 
39
29
  ## Release checks
40
30
 
@@ -140,7 +140,7 @@ import {
140
140
  withWrite,
141
141
  withWriteNoImplicitCommit,
142
142
  wrapIterable
143
- } from "./chunk-7WH525PL.js";
143
+ } from "./chunk-SIMXYEFB.js";
144
144
 
145
145
  // ../zero-schema/src/builder/table-builder.ts
146
146
  function table(name) {
@@ -6160,6 +6160,44 @@ var ReplicacheImpl = class {
6160
6160
  query(body) {
6161
6161
  return this.#queryInternal(body);
6162
6162
  }
6163
+ /**
6164
+ * The DURABLE last-mutation-IDs of this client's client group, read from
6165
+ * the PERDAG — the companion to `cookie`, and required by any embedder
6166
+ * that supplies its own pokes.
6167
+ *
6168
+ * WHY THIS HAS TO EXIST. A poke's `lastMutationIDChanges` are merged
6169
+ * over the base snapshot's, so naming a client with a value BELOW what
6170
+ * is already durable silently rewrites that client's history in the
6171
+ * memdag. `persist` then refuses to adopt the snapshot —
6172
+ * `mutationIDsAreAtLeast` — because adopting one that under-reports a
6173
+ * SIBLING would let that sibling re-push mutations the authority has
6174
+ * already applied. Refusing is correct, but it is also terminal: the
6175
+ * client's own absorbed mutations are gone from the memdag chain while
6176
+ * the perdag has never seen them, so `rebase` throws `Inconsistent
6177
+ * mutation ID` on every attempt and the client persists nothing again,
6178
+ * forever, while continuing to look healthy.
6179
+ *
6180
+ * An embedder cannot avoid that with per-session bookkeeping: after a
6181
+ * reload its in-memory high-water marks start empty while the dag does
6182
+ * not, and it has no way to learn what a SIBLING tab made durable —
6183
+ * `refresh` is the mechanism for that, and it aborts whenever the
6184
+ * memdag's cookie is ahead, which for an app-driven poke source is
6185
+ * essentially always. So the floor has to be readable, and only the dag
6186
+ * can report it.
6187
+ *
6188
+ * Read the perdag rather than the memdag deliberately: the perdag is
6189
+ * what `persist` compares against, and it is where a sibling's progress
6190
+ * appears.
6191
+ */
6192
+ get lastMutationIDs() {
6193
+ return this.#ready.then(async () => {
6194
+ const clientGroupID = await this.#clientGroupIDPromise;
6195
+ return withRead(this.perdag, async (perdagRead) => {
6196
+ const clientGroup = await getClientGroup(clientGroupID, perdagRead);
6197
+ return clientGroup ? { ...clientGroup.mutationIDs } : {};
6198
+ });
6199
+ });
6200
+ }
6163
6201
  get cookie() {
6164
6202
  return this.#ready.then(
6165
6203
  () => withRead(this.memdag, async (dagRead) => {
@@ -15008,7 +15046,7 @@ function makeMessage(message, context, logLevel) {
15008
15046
  }
15009
15047
 
15010
15048
  // ../zero-client/src/client/version.ts
15011
- var version2 = "2.2.3";
15049
+ var version2 = "2.2.4";
15012
15050
 
15013
15051
  // ../zero-client/src/client/log-options.ts
15014
15052
  var LevelFilterLogSink = class {
@@ -17157,6 +17195,20 @@ var Zero = class _Zero {
17157
17195
  get currentCookie() {
17158
17196
  return this.#rep.cookie;
17159
17197
  }
17198
+ /**
17199
+ * The DURABLE last-mutation-IDs of this client's client group.
17200
+ *
17201
+ * An adapter that supplies its own pokes MUST floor every
17202
+ * `lastMutationIDChanges` entry with this. A poke naming any client —
17203
+ * especially a SIBLING TAB — at a value below what is already durable
17204
+ * wedges `persist` permanently: see `ReplicacheImpl.lastMutationIDs`
17205
+ * for the full mechanism. Session-local bookkeeping cannot substitute,
17206
+ * because it starts empty after every reload and never learns what a
17207
+ * sibling made durable.
17208
+ */
17209
+ get currentLastMutationIDs() {
17210
+ return this.#rep.lastMutationIDs;
17211
+ }
17160
17212
  #onMessage = (e) => {
17161
17213
  const lc = this.#lc;
17162
17214
  lc.debug?.("received message", e.data);
@@ -18095,4 +18147,3 @@ export {
18095
18147
  pako/dist/pako.esm.mjs:
18096
18148
  (*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
18097
18149
  */
18098
- //# sourceMappingURL=chunk-UHDLB4MJ.js.map
@@ -8719,4 +8719,3 @@ export {
8719
8719
  Client,
8720
8720
  TDigest
8721
8721
  };
8722
- //# sourceMappingURL=chunk-7WH525PL.js.map
@@ -22,7 +22,7 @@ import {
22
22
  unreachable,
23
23
  valita_exports,
24
24
  withRead
25
- } from "./chunk-7WH525PL.js";
25
+ } from "./chunk-SIMXYEFB.js";
26
26
 
27
27
  // ../zero-client/src/client/inspector/html-dialog-prompt.ts
28
28
  function canUseHTMLDialog() {
@@ -550,4 +550,3 @@ export {
550
550
  rpc,
551
551
  serverVersion
552
552
  };
553
- //# sourceMappingURL=lazy-inspector-UQUFJWOZ.js.map
package/dist/react.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Zero
3
- } from "./chunk-UHDLB4MJ.js";
3
+ } from "./chunk-LBAN6SUK.js";
4
4
  import {
5
5
  DEFAULT_TTL_MS
6
- } from "./chunk-7WH525PL.js";
6
+ } from "./chunk-SIMXYEFB.js";
7
7
 
8
8
  // ../zero-react/src/use-query.tsx
9
9
  import React, { useSyncExternalStore } from "react";
@@ -382,4 +382,3 @@ export {
382
382
  useZero,
383
383
  useZeroOnline
384
384
  };
385
- //# sourceMappingURL=react.js.map
@@ -10,6 +10,7 @@ import type { Puller } from './puller.ts';
10
10
  import { type Pusher } from './pusher.ts';
11
11
  import type { ReplicacheOptions, ZeroOption } from './replicache-options.ts';
12
12
  import { type SubscribeOptions, type SubscriptionsManager, type WatchCallbackForOptions, type WatchNoIndexCallback, type WatchOptions } from './subscriptions.ts';
13
+ import type { ClientID } from './sync/ids.ts';
13
14
  import type { ReadTransaction } from './transactions.ts';
14
15
  import type { BeginPullResult, MakeMutators, MutatorDefs, PokeInternal, QueryInternal, RequestOptions, UpdateNeededReason } from './types.ts';
15
16
  /** @deprecated Not used any more */
@@ -315,6 +316,36 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
315
316
  * and `scan`.
316
317
  */
317
318
  query<R>(body: (tx: ReadTransaction) => Promise<R> | R): Promise<R>;
319
+ /**
320
+ * The DURABLE last-mutation-IDs of this client's client group, read from
321
+ * the PERDAG — the companion to `cookie`, and required by any embedder
322
+ * that supplies its own pokes.
323
+ *
324
+ * WHY THIS HAS TO EXIST. A poke's `lastMutationIDChanges` are merged
325
+ * over the base snapshot's, so naming a client with a value BELOW what
326
+ * is already durable silently rewrites that client's history in the
327
+ * memdag. `persist` then refuses to adopt the snapshot —
328
+ * `mutationIDsAreAtLeast` — because adopting one that under-reports a
329
+ * SIBLING would let that sibling re-push mutations the authority has
330
+ * already applied. Refusing is correct, but it is also terminal: the
331
+ * client's own absorbed mutations are gone from the memdag chain while
332
+ * the perdag has never seen them, so `rebase` throws `Inconsistent
333
+ * mutation ID` on every attempt and the client persists nothing again,
334
+ * forever, while continuing to look healthy.
335
+ *
336
+ * An embedder cannot avoid that with per-session bookkeeping: after a
337
+ * reload its in-memory high-water marks start empty while the dag does
338
+ * not, and it has no way to learn what a SIBLING tab made durable —
339
+ * `refresh` is the mechanism for that, and it aborts whenever the
340
+ * memdag's cookie is ahead, which for an app-driven poke source is
341
+ * essentially always. So the floor has to be readable, and only the dag
342
+ * can report it.
343
+ *
344
+ * Read the perdag rather than the memdag deliberately: the perdag is
345
+ * what `persist` compares against, and it is where a sibling's progress
346
+ * appears.
347
+ */
348
+ get lastMutationIDs(): Promise<Record<ClientID, number>>;
318
349
  get cookie(): Promise<Cookie>;
319
350
  recoverMutations(): Promise<boolean> | void;
320
351
  /**
@@ -200,6 +200,18 @@ export declare class Zero<const S extends Schema, MD extends CustomMutatorDefs |
200
200
  * Used by adapters to track sync state for poke operations.
201
201
  */
202
202
  get currentCookie(): Promise<Cookie>;
203
+ /**
204
+ * The DURABLE last-mutation-IDs of this client's client group.
205
+ *
206
+ * An adapter that supplies its own pokes MUST floor every
207
+ * `lastMutationIDChanges` entry with this. A poke naming any client —
208
+ * especially a SIBLING TAB — at a value below what is already durable
209
+ * wedges `persist` permanently: see `ReplicacheImpl.lastMutationIDs`
210
+ * for the full mechanism. Session-local bookkeeping cannot substitute,
211
+ * because it starts empty after every reload and never learns what a
212
+ * sibling made durable.
213
+ */
214
+ get currentLastMutationIDs(): Promise<Record<ClientID, number>>;
203
215
  /**
204
216
  * A rough heuristic for whether the client is currently online and
205
217
  * authenticated.
package/dist/zero.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  number,
7
7
  string,
8
8
  table
9
- } from "./chunk-UHDLB4MJ.js";
10
- import "./chunk-7WH525PL.js";
9
+ } from "./chunk-LBAN6SUK.js";
10
+ import "./chunk-SIMXYEFB.js";
11
11
 
12
12
  // src/adapters/convex.ts
13
13
  var ConvexSyncAdapter = class {
@@ -400,4 +400,3 @@ export {
400
400
  string,
401
401
  table
402
402
  };
403
- //# sourceMappingURL=zero.js.map
package/package.json CHANGED
@@ -1,26 +1,19 @@
1
1
  {
2
2
  "name": "ahmed-rivet-convex",
3
- "version": "2.2.3",
4
- "description": "Client-only Zero runtime used by Protocolbase for local-first Convex synchronization.",
3
+ "version": "2.2.4",
4
+ "description": "Client-only local-first data runtime for the browser: reactive queries over IndexedDB with optimistic writes.",
5
5
  "author": "Ahmed Banihani",
6
6
  "license": "Apache-2.0",
7
- "homepage": "https://zero.rocicorp.dev",
8
7
  "keywords": [
9
- "zero",
10
- "sync-engine",
11
8
  "local-first",
12
9
  "offline-first",
13
10
  "real-time",
14
- "query-batching",
15
- "compression",
16
- "messagepack",
17
- "gzip",
18
- "binary-protocol",
19
- "websocket",
20
11
  "reactive",
21
12
  "data-sync",
22
13
  "optimistic-ui",
23
- "serverless"
14
+ "indexeddb",
15
+ "websocket",
16
+ "messagepack"
24
17
  ],
25
18
  "scripts": {
26
19
  "build": "npm run build-client && npm run verify-package",
@@ -130,15 +123,10 @@
130
123
  },
131
124
  "files": [
132
125
  "dist/zero.js",
133
- "dist/zero.js.map",
134
126
  "dist/react.js",
135
- "dist/react.js.map",
136
127
  "dist/chunk-*.js",
137
- "dist/chunk-*.js.map",
138
128
  "dist/inspector-*.js",
139
- "dist/inspector-*.js.map",
140
129
  "dist/lazy-inspector-*.js",
141
- "dist/lazy-inspector-*.js.map",
142
130
  "dist/**/*.d.ts",
143
131
  "!*.tsbuildinfo"
144
132
  ],