ahmed-rivet-convex 2.0.0 → 2.2.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/README.md +22 -4
- package/dist/{chunk-YBIF2FS4.js → chunk-7WH525PL.js} +4 -20
- package/dist/chunk-7WH525PL.js.map +7 -0
- package/dist/{chunk-VYCNX7GU.js → chunk-RIN53NKR.js} +112 -24
- package/dist/chunk-RIN53NKR.js.map +7 -0
- package/dist/{lazy-inspector-OFHXCXCQ.js → lazy-inspector-UQUFJWOZ.js} +2 -2
- package/dist/react.js +28 -51
- package/dist/react.js.map +3 -3
- package/dist/zero/src/adapters/convex.d.ts +63 -0
- package/dist/zero/src/protocolbase.d.ts +1 -0
- package/dist/zero-client/src/client/context.d.ts +2 -0
- package/dist/zero-client/src/client/zero-rep.d.ts +1 -1
- package/dist/zero-client/src/client/zero.d.ts +12 -0
- package/dist/zero-protocol/src/ast.d.ts +1 -1
- package/dist/zero.js +385 -2
- package/dist/zero.js.map +4 -4
- package/package.json +1 -1
- package/dist/chunk-VYCNX7GU.js.map +0 -7
- package/dist/chunk-YBIF2FS4.js.map +0 -7
- package/dist/shared/src/deep-clone.d.ts +0 -4
- /package/dist/{lazy-inspector-OFHXCXCQ.js.map → lazy-inspector-UQUFJWOZ.js.map} +0 -0
|
@@ -140,7 +140,7 @@ import {
|
|
|
140
140
|
withWrite,
|
|
141
141
|
withWriteNoImplicitCommit,
|
|
142
142
|
wrapIterable
|
|
143
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-7WH525PL.js";
|
|
144
144
|
|
|
145
145
|
// ../zero-schema/src/builder/table-builder.ts
|
|
146
146
|
function table(name) {
|
|
@@ -2573,16 +2573,32 @@ var IDB_RETRY_BASE_DELAY_MS = 500;
|
|
|
2573
2573
|
var LARGE_COMMIT_THRESHOLD = 500;
|
|
2574
2574
|
var LARGE_COMMIT_BATCH = 250;
|
|
2575
2575
|
var IDBStore = class {
|
|
2576
|
+
#name;
|
|
2576
2577
|
#db;
|
|
2577
2578
|
#closed = false;
|
|
2578
2579
|
#idbDeleted = false;
|
|
2579
2580
|
constructor(name) {
|
|
2581
|
+
this.#name = name;
|
|
2580
2582
|
this.#db = openDatabase(name);
|
|
2581
2583
|
}
|
|
2582
2584
|
read() {
|
|
2583
2585
|
if (this.#closed) {
|
|
2584
2586
|
return storeIsClosedRejection();
|
|
2585
2587
|
}
|
|
2588
|
+
const pre = globalThis.__pbIdbPrefetch;
|
|
2589
|
+
const slot = pre?.[this.#name];
|
|
2590
|
+
if (slot && !slot.done && slot.promise && getEarlyPrefetchPolicy() === "await-inflight") {
|
|
2591
|
+
return this.#readAfterPrefetch(slot);
|
|
2592
|
+
}
|
|
2593
|
+
return this.#withReopen(readImpl);
|
|
2594
|
+
}
|
|
2595
|
+
async #readAfterPrefetch(slot) {
|
|
2596
|
+
try {
|
|
2597
|
+
slot.value = await slot.promise ?? null;
|
|
2598
|
+
} catch {
|
|
2599
|
+
slot.value = null;
|
|
2600
|
+
}
|
|
2601
|
+
slot.done = true;
|
|
2586
2602
|
return this.#withReopen(readImpl);
|
|
2587
2603
|
}
|
|
2588
2604
|
write() {
|
|
@@ -2772,12 +2788,7 @@ var ReadImpl2 = class {
|
|
|
2772
2788
|
if (!(r && r.keys && r.vals)) {
|
|
2773
2789
|
return this.getAll();
|
|
2774
2790
|
}
|
|
2775
|
-
return buildMap(
|
|
2776
|
-
r.keys,
|
|
2777
|
-
r.vals,
|
|
2778
|
-
"early-await",
|
|
2779
|
-
nowMs() - awaitT0
|
|
2780
|
-
);
|
|
2791
|
+
return buildMap(r.keys, r.vals, "early-await", nowMs() - awaitT0);
|
|
2781
2792
|
},
|
|
2782
2793
|
() => this.getAll()
|
|
2783
2794
|
);
|
|
@@ -4479,7 +4490,7 @@ var GatherNotCachedVisitor = class extends Visitor {
|
|
|
4479
4490
|
|
|
4480
4491
|
// ../replicache/src/persist/refresh.ts
|
|
4481
4492
|
var GATHER_SIZE_LIMIT = 5 * 2 ** 20;
|
|
4482
|
-
var DELAY_MS =
|
|
4493
|
+
var DELAY_MS = 16;
|
|
4483
4494
|
async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, closed, formatVersion, zero2) {
|
|
4484
4495
|
if (closed()) {
|
|
4485
4496
|
return;
|
|
@@ -5150,9 +5161,9 @@ var version = "15.2.1";
|
|
|
5150
5161
|
// ../replicache/src/replicache-impl.ts
|
|
5151
5162
|
var MAX_REAUTH_TRIES = 8;
|
|
5152
5163
|
var PERSIST_IDLE_TIMEOUT_MS = 1e3;
|
|
5153
|
-
var REFRESH_IDLE_TIMEOUT_MS =
|
|
5164
|
+
var REFRESH_IDLE_TIMEOUT_MS = 16;
|
|
5154
5165
|
var PERSIST_THROTTLE_MS = 500;
|
|
5155
|
-
var REFRESH_THROTTLE_MS =
|
|
5166
|
+
var REFRESH_THROTTLE_MS = 32;
|
|
5156
5167
|
var LAZY_STORE_SOURCE_CHUNK_CACHE_SIZE_LIMIT = 100 * 2 ** 20;
|
|
5157
5168
|
var RECOVER_MUTATIONS_INTERVAL_MS = 5 * 60 * 1e3;
|
|
5158
5169
|
var noop2 = () => {
|
|
@@ -14203,6 +14214,12 @@ var ZeroContext = class {
|
|
|
14203
14214
|
#mainSources;
|
|
14204
14215
|
addServerQuery;
|
|
14205
14216
|
addCustomQuery;
|
|
14217
|
+
// Convex has no zero-cache gotQueries message. Adapters acknowledge
|
|
14218
|
+
// authority table-by-table after a successful, durable reconciliation.
|
|
14219
|
+
// Local IDB hydration is intentionally a separate public lifecycle signal:
|
|
14220
|
+
// warm rows may render immediately, but they are not authoritative yet.
|
|
14221
|
+
#readyTables = /* @__PURE__ */ new Set();
|
|
14222
|
+
#pendingGotCallbacks = /* @__PURE__ */ new Map();
|
|
14206
14223
|
updateServerQuery;
|
|
14207
14224
|
updateCustomQuery;
|
|
14208
14225
|
flushQueryChanges;
|
|
@@ -14218,16 +14235,54 @@ var ZeroContext = class {
|
|
|
14218
14235
|
addMetric;
|
|
14219
14236
|
constructor(lc, mainSources, addQuery, addCustomQuery, updateQuery, updateCustomQuery, flushQueryChanges, batchViewUpdates, addMetric, assertValidRunOptions3) {
|
|
14220
14237
|
this.#mainSources = mainSources;
|
|
14221
|
-
|
|
14238
|
+
const wrapGot = (table2, gotCallback) => {
|
|
14239
|
+
if (!gotCallback) return gotCallback;
|
|
14240
|
+
let real = false;
|
|
14241
|
+
const emit = (error) => gotCallback(real || this.#readyTables.has(table2), error);
|
|
14242
|
+
const wrapped = (got, error) => {
|
|
14243
|
+
real = got;
|
|
14244
|
+
emit(error);
|
|
14245
|
+
};
|
|
14246
|
+
if (this.#readyTables.has(table2)) {
|
|
14247
|
+
void Promise.resolve().then(() => emit());
|
|
14248
|
+
} else {
|
|
14249
|
+
this.#pendingGotCallbacks.set(wrapped, { table: table2, emit });
|
|
14250
|
+
}
|
|
14251
|
+
return wrapped;
|
|
14252
|
+
};
|
|
14253
|
+
this.addServerQuery = (ast, ttl, gotCallback) => {
|
|
14254
|
+
const wrapped = wrapGot(ast.table, gotCallback);
|
|
14255
|
+
const cleanup = addQuery(ast, ttl, wrapped);
|
|
14256
|
+
return () => {
|
|
14257
|
+
if (wrapped) this.#pendingGotCallbacks.delete(wrapped);
|
|
14258
|
+
cleanup();
|
|
14259
|
+
};
|
|
14260
|
+
};
|
|
14261
|
+
this.addCustomQuery = (ast, customQueryID, ttl, gotCallback) => {
|
|
14262
|
+
const wrapped = wrapGot(ast.table, gotCallback);
|
|
14263
|
+
const cleanup = addCustomQuery(ast, customQueryID, ttl, wrapped);
|
|
14264
|
+
return () => {
|
|
14265
|
+
if (wrapped) this.#pendingGotCallbacks.delete(wrapped);
|
|
14266
|
+
cleanup();
|
|
14267
|
+
};
|
|
14268
|
+
};
|
|
14222
14269
|
this.updateServerQuery = updateQuery;
|
|
14223
14270
|
this.updateCustomQuery = updateCustomQuery;
|
|
14224
14271
|
this.#batchViewUpdates = batchViewUpdates;
|
|
14225
14272
|
this.#lc = lc;
|
|
14226
14273
|
this.assertValidRunOptions = assertValidRunOptions3;
|
|
14227
|
-
this.addCustomQuery = addCustomQuery;
|
|
14228
14274
|
this.flushQueryChanges = flushQueryChanges;
|
|
14229
14275
|
this.addMetric = addMetric;
|
|
14230
14276
|
}
|
|
14277
|
+
/** Mark tables authoritatively reconciled by an external sync adapter. */
|
|
14278
|
+
markTablesReady(tables) {
|
|
14279
|
+
for (const table2 of tables) this.#readyTables.add(table2);
|
|
14280
|
+
for (const [callback, pending] of this.#pendingGotCallbacks) {
|
|
14281
|
+
if (!this.#readyTables.has(pending.table)) continue;
|
|
14282
|
+
this.#pendingGotCallbacks.delete(callback);
|
|
14283
|
+
pending.emit();
|
|
14284
|
+
}
|
|
14285
|
+
}
|
|
14231
14286
|
getSource(name) {
|
|
14232
14287
|
return this.#mainSources.getSource(name);
|
|
14233
14288
|
}
|
|
@@ -14400,19 +14455,20 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
|
|
|
14400
14455
|
}
|
|
14401
14456
|
function makeCRUDMutator(schema) {
|
|
14402
14457
|
return async function zeroCRUDMutator(tx, crudArg) {
|
|
14458
|
+
const ivmBranch = tx[zeroData]?.ivmSources;
|
|
14403
14459
|
for (const op of crudArg.ops) {
|
|
14404
14460
|
switch (op.op) {
|
|
14405
14461
|
case "insert":
|
|
14406
|
-
await insertImpl(tx, op, schema,
|
|
14462
|
+
await insertImpl(tx, op, schema, ivmBranch);
|
|
14407
14463
|
break;
|
|
14408
14464
|
case "upsert":
|
|
14409
|
-
await upsertImpl(tx, op, schema,
|
|
14465
|
+
await upsertImpl(tx, op, schema, ivmBranch);
|
|
14410
14466
|
break;
|
|
14411
14467
|
case "update":
|
|
14412
|
-
await updateImpl(tx, op, schema,
|
|
14468
|
+
await updateImpl(tx, op, schema, ivmBranch);
|
|
14413
14469
|
break;
|
|
14414
14470
|
case "delete":
|
|
14415
|
-
await deleteImpl(tx, op, schema,
|
|
14471
|
+
await deleteImpl(tx, op, schema, ivmBranch);
|
|
14416
14472
|
break;
|
|
14417
14473
|
}
|
|
14418
14474
|
}
|
|
@@ -14939,7 +14995,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
14939
14995
|
}
|
|
14940
14996
|
|
|
14941
14997
|
// ../zero-client/src/client/version.ts
|
|
14942
|
-
var version2 = "2.
|
|
14998
|
+
var version2 = "2.2.0";
|
|
14943
14999
|
|
|
14944
15000
|
// ../zero-client/src/client/log-options.ts
|
|
14945
15001
|
var LevelFilterLogSink = class {
|
|
@@ -16314,13 +16370,15 @@ var ZeroRep = class {
|
|
|
16314
16370
|
#ivmMain;
|
|
16315
16371
|
#customMutatorsEnabled;
|
|
16316
16372
|
#mutationTracker;
|
|
16373
|
+
#onLocalHydrationComplete;
|
|
16317
16374
|
#store;
|
|
16318
16375
|
#auth;
|
|
16319
|
-
constructor(context, ivmMain, customMutatorsEnabled, mutationTracker) {
|
|
16376
|
+
constructor(context, ivmMain, customMutatorsEnabled, mutationTracker, onLocalHydrationComplete) {
|
|
16320
16377
|
this.#context = context;
|
|
16321
16378
|
this.#ivmMain = ivmMain;
|
|
16322
16379
|
this.#customMutatorsEnabled = customMutatorsEnabled;
|
|
16323
16380
|
this.#mutationTracker = mutationTracker;
|
|
16381
|
+
this.#onLocalHydrationComplete = onLocalHydrationComplete;
|
|
16324
16382
|
}
|
|
16325
16383
|
set auth(auth) {
|
|
16326
16384
|
if (auth === "") {
|
|
@@ -16340,9 +16398,14 @@ var ZeroRep = class {
|
|
|
16340
16398
|
await lazyRead.prefetchSource();
|
|
16341
16399
|
}
|
|
16342
16400
|
if (shouldLogColdIdb()) {
|
|
16343
|
-
logColdIdbStage("init-prefetch", {
|
|
16401
|
+
logColdIdbStage("init-prefetch", {
|
|
16402
|
+
ms: Math.round(nowMs() - prefetchT0),
|
|
16403
|
+
atMs: ts()
|
|
16404
|
+
});
|
|
16405
|
+
}
|
|
16406
|
+
if (shouldLogColdIdb()) {
|
|
16407
|
+
console.log(`[ZERO-INIT] prefetch at +${ts()}ms`);
|
|
16344
16408
|
}
|
|
16345
|
-
console.log(`[ZERO-INIT] prefetch at +${ts()}ms`);
|
|
16346
16409
|
const read = await readFromHash(hash, dagRead, Latest);
|
|
16347
16410
|
const scanT0 = nowMs();
|
|
16348
16411
|
const scanAll = read.map.scanAll;
|
|
@@ -16377,7 +16440,9 @@ var ZeroRep = class {
|
|
|
16377
16440
|
atMs: ts()
|
|
16378
16441
|
});
|
|
16379
16442
|
}
|
|
16380
|
-
|
|
16443
|
+
if (shouldLogColdIdb()) {
|
|
16444
|
+
console.log(`[ZERO-INIT] scan: ${diffs.length} entities at +${ts()}ms`);
|
|
16445
|
+
}
|
|
16381
16446
|
});
|
|
16382
16447
|
this.#store = store;
|
|
16383
16448
|
const ivmT0 = nowMs();
|
|
@@ -16390,7 +16455,10 @@ var ZeroRep = class {
|
|
|
16390
16455
|
});
|
|
16391
16456
|
logColdIdbStage("init-done", { ms: ts(), entities: diffs.length });
|
|
16392
16457
|
}
|
|
16393
|
-
|
|
16458
|
+
if (shouldLogColdIdb()) {
|
|
16459
|
+
console.log(`[ZERO-INIT] done at +${ts()}ms`);
|
|
16460
|
+
}
|
|
16461
|
+
this.#onLocalHydrationComplete();
|
|
16394
16462
|
}
|
|
16395
16463
|
getTxData = (desiredHead, readOptions) => {
|
|
16396
16464
|
if (!this.#customMutatorsEnabled) {
|
|
@@ -16511,6 +16579,9 @@ var Zero = class _Zero {
|
|
|
16511
16579
|
};
|
|
16512
16580
|
#zeroContext;
|
|
16513
16581
|
queryDelegate;
|
|
16582
|
+
#localHydrationResolver = resolver9();
|
|
16583
|
+
/** Resolves after the persisted local DAG has populated the in-memory IVM. */
|
|
16584
|
+
localHydrationComplete = this.#localHydrationResolver.promise;
|
|
16514
16585
|
#connectResolver = resolver9();
|
|
16515
16586
|
#pendingPullsByRequestID = /* @__PURE__ */ new Map();
|
|
16516
16587
|
#lastMutationIDReceived = 0;
|
|
@@ -16728,7 +16799,8 @@ var Zero = class _Zero {
|
|
|
16728
16799
|
this.#zeroContext,
|
|
16729
16800
|
this.#ivmMain,
|
|
16730
16801
|
options.mutators !== void 0,
|
|
16731
|
-
this.#mutationTracker
|
|
16802
|
+
this.#mutationTracker,
|
|
16803
|
+
() => this.#localHydrationResolver.resolve()
|
|
16732
16804
|
)
|
|
16733
16805
|
};
|
|
16734
16806
|
const rep = new ReplicacheImpl(replicacheOptions, replicacheImplOptions);
|
|
@@ -17021,6 +17093,22 @@ var Zero = class _Zero {
|
|
|
17021
17093
|
*/
|
|
17022
17094
|
async pokeDirect(poke) {
|
|
17023
17095
|
await this.#rep.poke(poke);
|
|
17096
|
+
await this.#rep.persist();
|
|
17097
|
+
}
|
|
17098
|
+
/** Refresh this instance from the latest persisted shared-IDB head. */
|
|
17099
|
+
async refresh() {
|
|
17100
|
+
await this.#rep.refresh();
|
|
17101
|
+
}
|
|
17102
|
+
/** Read adapter-owned metadata stored in the same durable DAG as rows. */
|
|
17103
|
+
readLocalValue(key) {
|
|
17104
|
+
return this.#rep.query((tx) => tx.get(key));
|
|
17105
|
+
}
|
|
17106
|
+
/**
|
|
17107
|
+
* Tell client queries that Convex has authoritatively reconciled these
|
|
17108
|
+
* tables. Local hydration alone deliberately does not imply completeness.
|
|
17109
|
+
*/
|
|
17110
|
+
markTablesReady(tables) {
|
|
17111
|
+
this.#zeroContext.markTablesReady(tables);
|
|
17024
17112
|
}
|
|
17025
17113
|
/**
|
|
17026
17114
|
* Trigger the push loop to send all pending mutations to the server.
|
|
@@ -17985,4 +18073,4 @@ export {
|
|
|
17985
18073
|
pako/dist/pako.esm.mjs:
|
|
17986
18074
|
(*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
|
|
17987
18075
|
*/
|
|
17988
|
-
//# sourceMappingURL=chunk-
|
|
18076
|
+
//# sourceMappingURL=chunk-RIN53NKR.js.map
|