@mdbase-dev/sdk 0.2.106 → 0.3.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 +1 -0
- package/dist/app-host/cloud-copy-host.d.ts +3 -1
- package/dist/app-host/cloud-copy-host.js +27 -3
- package/dist/app-host/cloud-copy-host.js.map +1 -1
- package/dist/app-host/http-log.d.ts +12 -2
- package/dist/app-host/http-log.js +25 -0
- package/dist/app-host/http-log.js.map +1 -1
- package/dist/app-host/local-facade.js +3 -1
- package/dist/app-host/local-facade.js.map +1 -1
- package/dist/app-host/log-pump.js +4 -1
- package/dist/app-host/log-pump.js.map +1 -1
- package/dist/app-host/log-push.d.ts +12 -0
- package/dist/app-host/log-push.js +96 -3
- package/dist/app-host/log-push.js.map +1 -1
- package/dist/app-host/scoped-sign-in-session.d.ts +1 -0
- package/dist/app-host/scoped-sign-in-session.js +9 -0
- package/dist/app-host/scoped-sign-in-session.js.map +1 -1
- package/dist/app-host/wasm-runtime.d.ts +5 -0
- package/dist/app-host/wasm-runtime.js +9 -0
- package/dist/app-host/wasm-runtime.js.map +1 -1
- package/dist/app-host/web-sign-in-session.d.ts +8 -4
- package/dist/app-host/web-sign-in-session.js +7 -3
- package/dist/app-host/web-sign-in-session.js.map +1 -1
- package/dist/application/asset-pins.json +4 -4
- package/dist/application/entry.js +1 -1
- package/dist/application/entry.js.map +1 -1
- package/dist/application/file-access.js +14 -2
- package/dist/application/file-access.js.map +1 -1
- package/dist/application/front-door.d.ts +3 -1
- package/dist/application/front-door.js.map +1 -1
- package/dist/application/phase.d.ts +1 -1
- package/dist/application/phase.js +7 -2
- package/dist/application/phase.js.map +1 -1
- package/dist/application/private-collections.js +2 -0
- package/dist/application/private-collections.js.map +1 -1
- package/dist/application/worker.js +350 -47
- package/dist/browser/mdbase-sdk.js +383 -59
- package/dist/browser/mdbase-sdk.min.js +62 -62
- package/dist/client.d.ts +13 -2
- package/dist/client.js +28 -13
- package/dist/client.js.map +1 -1
- package/dist/collection-api.d.ts +1 -1
- package/dist/collection-api.js.map +1 -1
- package/dist/describe-error.d.ts +2 -2
- package/dist/describe-error.js +9 -5
- package/dist/describe-error.js.map +1 -1
- package/dist/files.d.ts +8 -0
- package/dist/files.js +82 -2
- package/dist/files.js.map +1 -1
- package/dist/native/provenance.json +5 -5
- package/dist/native/runtime.wasm +0 -0
- package/dist/presence.d.ts +12 -1
- package/dist/presence.js +23 -4
- package/dist/presence.js.map +1 -1
- package/dist/request-deadline.d.ts +4 -0
- package/dist/request-deadline.js +30 -0
- package/dist/request-deadline.js.map +1 -0
- package/dist/settle.js +5 -4
- package/dist/settle.js.map +1 -1
- package/dist/testing/memory-replica.d.ts +6 -1
- package/dist/testing/memory-replica.js +54 -29
- package/dist/testing/memory-replica.js.map +1 -1
- package/dist/wire.d.ts +4 -1
- package/dist/wire.js +3 -1
- package/dist/wire.js.map +1 -1
- package/dist/write-ledger.d.ts +1 -1
- package/dist/write-ledger.js +35 -21
- package/dist/write-ledger.js.map +1 -1
- package/package.json +1 -1
|
@@ -15703,12 +15703,12 @@ function appReleaseTrust() {
|
|
|
15703
15703
|
// src/application/asset-pins.json
|
|
15704
15704
|
var asset_pins_default = {
|
|
15705
15705
|
runtime: {
|
|
15706
|
-
sha256: "
|
|
15707
|
-
bytes:
|
|
15708
|
-
maxBytes:
|
|
15706
|
+
sha256: "30af71a27c5a97592a9380b3d9e3ce683542667fbced7fcd63a188e5d17ac643",
|
|
15707
|
+
bytes: 4261471,
|
|
15708
|
+
maxBytes: 4261471,
|
|
15709
15709
|
source: {
|
|
15710
15710
|
repository: "mdbase-dev/mdbase-connect",
|
|
15711
|
-
commit: "
|
|
15711
|
+
commit: "3af3e8e1bb878be36a4efc654c70590c413fdb44"
|
|
15712
15712
|
}
|
|
15713
15713
|
},
|
|
15714
15714
|
sqlite: {
|
|
@@ -17109,6 +17109,7 @@ var op = mapped(
|
|
|
17109
17109
|
(v) => v.kind === "update" && v.requireLive ? { ...v, kind: "update_live" } : v
|
|
17110
17110
|
);
|
|
17111
17111
|
var validationLevel = enumOf("level", ["off", "warn", "error"]);
|
|
17112
|
+
var mutationSource = enumOf("source", ["api", "external"]);
|
|
17112
17113
|
var submitParams = struct("submit-params", [
|
|
17113
17114
|
[0, "ops", list(op, { nonEmpty: true }), "req1"],
|
|
17114
17115
|
[1, "mutationId", uuid, "opt"],
|
|
@@ -17119,7 +17120,8 @@ var submitParams = struct("submit-params", [
|
|
|
17119
17120
|
[6, "dryRun", bool, "opt"],
|
|
17120
17121
|
[7, "include", include, "opt"],
|
|
17121
17122
|
[8, "wait", enumOf("wait-for", ["pending", "confirmed", "published"]), "opt"],
|
|
17122
|
-
[9, "validation", validationLevel, "opt"]
|
|
17123
|
+
[9, "validation", validationLevel, "opt"],
|
|
17124
|
+
[10, "source", mutationSource, "opt"]
|
|
17123
17125
|
]);
|
|
17124
17126
|
var CONFLICT_FORMS = ["missing", "value", "text", "blob", "deleted"];
|
|
17125
17127
|
var conflictValue = {
|
|
@@ -17387,7 +17389,7 @@ var mutation = struct("mutation", [
|
|
|
17387
17389
|
opClock
|
|
17388
17390
|
],
|
|
17389
17391
|
[4, "seed", b32],
|
|
17390
|
-
[5, "source",
|
|
17392
|
+
[5, "source", mutationSource],
|
|
17391
17393
|
[6, "ops", list(op, { nonEmpty: true }), "req1"],
|
|
17392
17394
|
[7, "onBehalf", uuid, "opt"],
|
|
17393
17395
|
[8, "conflictMode", conflictMode, "opt"],
|
|
@@ -18477,6 +18479,33 @@ var Session = class _Session {
|
|
|
18477
18479
|
}
|
|
18478
18480
|
};
|
|
18479
18481
|
|
|
18482
|
+
// src/request-deadline.ts
|
|
18483
|
+
async function withRequestDeadline(timeoutMs, caller, operation) {
|
|
18484
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2147483647) {
|
|
18485
|
+
throw mdbaseError("invalid_request", "Invalid request deadline.");
|
|
18486
|
+
}
|
|
18487
|
+
const cancelled3 = () => mdbaseError("cancelled", "Request cancelled.");
|
|
18488
|
+
if (caller?.aborted) throw cancelled3();
|
|
18489
|
+
const controller = new AbortController();
|
|
18490
|
+
const abort = () => controller.abort(cancelled3());
|
|
18491
|
+
let stop;
|
|
18492
|
+
const stopped = new Promise((_, reject) => {
|
|
18493
|
+
stop = () => reject(controller.signal.reason);
|
|
18494
|
+
controller.signal.addEventListener("abort", stop, { once: true });
|
|
18495
|
+
});
|
|
18496
|
+
caller?.addEventListener("abort", abort, { once: true });
|
|
18497
|
+
const timer = setTimeout(() => controller.abort(
|
|
18498
|
+
mdbaseError("outcome_unknown", "Request deadline elapsed.", "request_deadline")
|
|
18499
|
+
), timeoutMs);
|
|
18500
|
+
try {
|
|
18501
|
+
return await Promise.race([stopped, operation(controller.signal)]);
|
|
18502
|
+
} finally {
|
|
18503
|
+
clearTimeout(timer);
|
|
18504
|
+
caller?.removeEventListener("abort", abort);
|
|
18505
|
+
controller.signal.removeEventListener("abort", stop);
|
|
18506
|
+
}
|
|
18507
|
+
}
|
|
18508
|
+
|
|
18480
18509
|
// src/files.ts
|
|
18481
18510
|
var REGION_BUSY_WAIT_MS = 9e4;
|
|
18482
18511
|
function regionBusy(e, until) {
|
|
@@ -18664,6 +18693,69 @@ var FilesApi = class {
|
|
|
18664
18693
|
...o.signal ? { signal: o.signal } : {}
|
|
18665
18694
|
});
|
|
18666
18695
|
}
|
|
18696
|
+
/** Confirm a completed transfer and return its verified file metadata. The
|
|
18697
|
+
* default 30 s wait covers confirmation, publication and readback together.
|
|
18698
|
+
* On an uncertain outcome, resolve the original mutation before retrying. */
|
|
18699
|
+
async settle(write, options = {}) {
|
|
18700
|
+
const { mutationId, fileId: fileId2 } = write;
|
|
18701
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
18702
|
+
try {
|
|
18703
|
+
return await withRequestDeadline(timeoutMs, options.signal, async (signal) => {
|
|
18704
|
+
let receipt3 = write.receipt;
|
|
18705
|
+
if (receipt3.state === "pending") {
|
|
18706
|
+
try {
|
|
18707
|
+
receipt3 = await this.client.awaitReceipt(mutationId, { timeoutMs, signal });
|
|
18708
|
+
} catch (cause) {
|
|
18709
|
+
if (signal.aborted) throw signal.reason;
|
|
18710
|
+
throw new MdbaseError({ code: "outcome_unknown", recovery: "resolve_outcome", message: "Could not verify the upload receipt." }, { cause });
|
|
18711
|
+
}
|
|
18712
|
+
}
|
|
18713
|
+
if (receipt3.mutation !== mutationId) throw mdbaseError("internal", "Received an unrelated upload receipt.");
|
|
18714
|
+
if (receipt3.state === "rejected") throw new MdbaseError(receipt3.problem ?? {
|
|
18715
|
+
code: "conflict",
|
|
18716
|
+
recovery: "resolve_conflict",
|
|
18717
|
+
message: "The upload was rejected."
|
|
18718
|
+
});
|
|
18719
|
+
if (receipt3.state !== "confirmed" || receipt3.status !== "applied" || receipt3.conflicts?.length || receipt3.seq === void 0) {
|
|
18720
|
+
throw mdbaseError("outcome_unknown", "The upload has no confirmed applied receipt.");
|
|
18721
|
+
}
|
|
18722
|
+
const publication = write.receipt.published === "published" || write.receipt.published === "not_published" ? write.receipt.published : receipt3.published ?? write.receipt.published;
|
|
18723
|
+
if (publication === "publishing") {
|
|
18724
|
+
await new Promise((resolve, reject) => {
|
|
18725
|
+
const abort = () => {
|
|
18726
|
+
unsubscribe();
|
|
18727
|
+
reject(signal.reason);
|
|
18728
|
+
};
|
|
18729
|
+
const unsubscribe = write.onReceipt((updated) => {
|
|
18730
|
+
if (updated.state !== "rejected" && updated.state !== "unknown" && updated.published !== "published" && updated.published !== "not_published") return;
|
|
18731
|
+
unsubscribe();
|
|
18732
|
+
signal.removeEventListener("abort", abort);
|
|
18733
|
+
if (updated.state === "rejected" && updated.problem) reject(new MdbaseError(updated.problem));
|
|
18734
|
+
else if (updated.state !== "rejected" && updated.state !== "unknown" && updated.published === "published") resolve();
|
|
18735
|
+
else reject(mdbaseError("outcome_unknown", "The file publication was not confirmed."));
|
|
18736
|
+
});
|
|
18737
|
+
if (signal.aborted) abort();
|
|
18738
|
+
else signal.addEventListener("abort", abort, { once: true });
|
|
18739
|
+
});
|
|
18740
|
+
} else if (publication === "not_published") {
|
|
18741
|
+
throw mdbaseError("outcome_unknown", "The file was not published.");
|
|
18742
|
+
}
|
|
18743
|
+
let file;
|
|
18744
|
+
try {
|
|
18745
|
+
file = await this.get(fileId2, { signal });
|
|
18746
|
+
} catch (cause) {
|
|
18747
|
+
if (signal.aborted) throw signal.reason;
|
|
18748
|
+
throw new MdbaseError({ code: "outcome_unknown", recovery: "resolve_outcome", message: "Could not verify the uploaded file." }, { cause });
|
|
18749
|
+
}
|
|
18750
|
+
if (file.id !== fileId2 || file.confirmedSeq !== receipt3.seq || file.hold || file.state === "pending_upload") {
|
|
18751
|
+
throw mdbaseError("outcome_unknown", "The current file does not confirm this upload.");
|
|
18752
|
+
}
|
|
18753
|
+
return file;
|
|
18754
|
+
});
|
|
18755
|
+
} catch (error4) {
|
|
18756
|
+
throw withMutation(error4, "file settlement", { mutationId });
|
|
18757
|
+
}
|
|
18758
|
+
}
|
|
18667
18759
|
/**
|
|
18668
18760
|
* Upload a file. Resumable: on a dropped link it reconnects and sends only the chunks
|
|
18669
18761
|
* the replica lacks. Returns the `file_put` write: `confirmed` means the bytes are
|
|
@@ -18702,7 +18794,7 @@ var FilesApi = class {
|
|
|
18702
18794
|
continue;
|
|
18703
18795
|
}
|
|
18704
18796
|
this.progress.delete(transfer);
|
|
18705
|
-
await this.
|
|
18797
|
+
await this.releaseUpload(transfer, AbortSignal.timeout(1e3)).catch(() => {
|
|
18706
18798
|
});
|
|
18707
18799
|
throw withMutation(e, "upload", { mutationId: open2.mutationId });
|
|
18708
18800
|
}
|
|
@@ -18756,7 +18848,10 @@ var FilesApi = class {
|
|
|
18756
18848
|
}
|
|
18757
18849
|
/** Release the upload lane. An already captured write remains durable; use its receipt to resolve the outcome. */
|
|
18758
18850
|
abortUpload(transferId) {
|
|
18759
|
-
return this.
|
|
18851
|
+
return this.releaseUpload(transferId);
|
|
18852
|
+
}
|
|
18853
|
+
releaseUpload(transferId, signal) {
|
|
18854
|
+
return this.client.call("abort_upload", m([[0, uuid.enc(transferId)]]), { signal }).then(() => {
|
|
18760
18855
|
});
|
|
18761
18856
|
}
|
|
18762
18857
|
/**
|
|
@@ -19054,7 +19149,7 @@ function unknown(mutationId, reason, text6, receipt3) {
|
|
|
19054
19149
|
const problem4 = { code: "outcome_unknown", recovery: "resolve_outcome", reason, message: text6 };
|
|
19055
19150
|
return Object.freeze({ outcome: "unknown", mutationId, ...receipt3 ? { receipt: receipt3 } : {}, problem: problem4 });
|
|
19056
19151
|
}
|
|
19057
|
-
async function settleWrite(client, input, options = {}) {
|
|
19152
|
+
async function settleWrite(client, input, options = {}, mayHaveUnresolved) {
|
|
19058
19153
|
const signal = options.signal;
|
|
19059
19154
|
let write;
|
|
19060
19155
|
let mutationId;
|
|
@@ -19065,7 +19160,9 @@ async function settleWrite(client, input, options = {}) {
|
|
|
19065
19160
|
receipt3 = await client.receipt(mutationId, { signal });
|
|
19066
19161
|
} catch (e) {
|
|
19067
19162
|
if (cancelled(e)) throw e;
|
|
19068
|
-
if (isMdbaseError(e, "not_found")
|
|
19163
|
+
if (isMdbaseError(e, "not_found") && !mayHaveUnresolved?.(mutationId)) {
|
|
19164
|
+
return Object.freeze({ outcome: "rejected", mutationId, problem: e.toProblem() });
|
|
19165
|
+
}
|
|
19069
19166
|
return unknown(mutationId, "receipt_unavailable", `The write's result could not be read: ${message(e)}`);
|
|
19070
19167
|
}
|
|
19071
19168
|
} else {
|
|
@@ -19081,7 +19178,7 @@ async function settleWrite(client, input, options = {}) {
|
|
|
19081
19178
|
receipt3 = await client.receipt(mutationId, { signal });
|
|
19082
19179
|
} catch (lookup) {
|
|
19083
19180
|
if (cancelled(lookup)) throw lookup;
|
|
19084
|
-
if (isMdbaseError(lookup, "not_found")) return Object.freeze({ outcome: "rejected", mutationId, problem: e.toProblem() });
|
|
19181
|
+
if (isMdbaseError(lookup, "not_found") && e instanceof WriteRefusal) return Object.freeze({ outcome: "rejected", mutationId, problem: e.toProblem() });
|
|
19085
19182
|
return unknown(mutationId, "receipt_unavailable", `The write may have been saved: ${e.message}`);
|
|
19086
19183
|
}
|
|
19087
19184
|
}
|
|
@@ -20819,6 +20916,7 @@ var RecordSet = class {
|
|
|
20819
20916
|
|
|
20820
20917
|
// src/presence.ts
|
|
20821
20918
|
var MAX_PRESENCE_STATE = 4096;
|
|
20919
|
+
var PRESENCE_FEATURE = "presence-v1";
|
|
20822
20920
|
var MIN_INTERVAL_MS = 100;
|
|
20823
20921
|
var PresenceApi = class {
|
|
20824
20922
|
constructor(client) {
|
|
@@ -20856,6 +20954,13 @@ var PresenceApi = class {
|
|
|
20856
20954
|
throw mdbaseError("too_large", "presence state over 4 KiB", { details: { limit: MAX_PRESENCE_STATE } });
|
|
20857
20955
|
}
|
|
20858
20956
|
}
|
|
20957
|
+
/** Whether the connected replica serves presence. False on an older runtime
|
|
20958
|
+
* and on a collection served by the hosted replica: `join` then rejects with
|
|
20959
|
+
* `unavailable` and a subscription stays empty. */
|
|
20960
|
+
async supported() {
|
|
20961
|
+
return (await this.client.ready()).hello.features.includes(PRESENCE_FEATURE);
|
|
20962
|
+
}
|
|
20963
|
+
/** Show this session on a record with `state` (any plain value up to 4 KiB). */
|
|
20859
20964
|
async join(record3, state) {
|
|
20860
20965
|
const v = toValue(state);
|
|
20861
20966
|
this.check(v);
|
|
@@ -20887,7 +20992,10 @@ var PresenceApi = class {
|
|
|
20887
20992
|
await this.client.call("presence_leave", /* @__PURE__ */ new Map([[0, uuid.enc(record3)]])).catch(() => {
|
|
20888
20993
|
});
|
|
20889
20994
|
}
|
|
20890
|
-
/** Watch
|
|
20995
|
+
/** Watch who else is on a record: every session but this one, on this device
|
|
20996
|
+
* or another, each with a `session` pseudonym that lasts for its join, the
|
|
20997
|
+
* `account` and `app` the replica vouches for when it knows them, and its
|
|
20998
|
+
* state. Called at once and on every change. Returns an unsubscribe function. */
|
|
20891
20999
|
subscribe(record3, fn) {
|
|
20892
21000
|
let set2 = this.watchers.get(record3);
|
|
20893
21001
|
const first = !set2;
|
|
@@ -20901,8 +21009,10 @@ var PresenceApi = class {
|
|
|
20901
21009
|
});
|
|
20902
21010
|
}
|
|
20903
21011
|
return () => {
|
|
20904
|
-
set2.delete(fn);
|
|
20905
|
-
|
|
21012
|
+
if (!set2.delete(fn) || set2.size > 0 || this.watchers.get(record3) !== set2) return;
|
|
21013
|
+
this.watchers.delete(record3);
|
|
21014
|
+
void this.client.ready().then((s) => s.hello.features.includes(PRESENCE_FEATURE) ? s.request("unsubscribe_presence", /* @__PURE__ */ new Map([[0, uuid.enc(record3)]])) : void 0).catch(() => {
|
|
21015
|
+
});
|
|
20906
21016
|
};
|
|
20907
21017
|
}
|
|
20908
21018
|
};
|
|
@@ -21147,6 +21257,7 @@ var targets = (ops) => [...new Set(ops.flatMap((op2) => {
|
|
|
21147
21257
|
const o = op2, id4 = o.id ?? o.record;
|
|
21148
21258
|
return typeof id4 === "string" ? [id4] : [];
|
|
21149
21259
|
}))];
|
|
21260
|
+
var unresolved = (e) => e.state === "pending" || e.problem?.code === "outcome_unknown";
|
|
21150
21261
|
var entry = (mutationId, records2, state, problem4, createdAt = Date.now()) => problem4 ? { mutationId, records: records2, createdAt, state, problem: problem4 } : { mutationId, records: records2, createdAt, state };
|
|
21151
21262
|
var WriteLedger = class {
|
|
21152
21263
|
constructor(store2, native) {
|
|
@@ -21201,14 +21312,19 @@ var WriteLedger = class {
|
|
|
21201
21312
|
begin(mutationId, ops) {
|
|
21202
21313
|
return this.set(entry(mutationId, targets(ops), "pending"));
|
|
21203
21314
|
}
|
|
21315
|
+
/** A stored intent can precede a late submit from another tab. */
|
|
21316
|
+
mayHaveUnresolved(id4) {
|
|
21317
|
+
const e = this.entries.get(id4);
|
|
21318
|
+
return !this.restored || e !== void 0 && unresolved(e);
|
|
21319
|
+
}
|
|
21204
21320
|
/** @internal Apply a receipt from any source. */
|
|
21205
21321
|
observe(r) {
|
|
21206
21322
|
const e = this.entries.get(r.mutation), records2 = e?.records ?? (r.records ?? []).map((v) => v.id);
|
|
21207
21323
|
if (r.state === "confirmed") {
|
|
21208
21324
|
if (e) void this.drop(r.mutation);
|
|
21209
21325
|
} else if (r.state === "pending") {
|
|
21210
|
-
if (!e) void this.set(entry(r.mutation, records2, "pending"));
|
|
21211
|
-
} else if (e?.state
|
|
21326
|
+
if (!e || e.problem?.code === "outcome_unknown") void this.set(entry(r.mutation, records2, "pending", void 0, e?.createdAt));
|
|
21327
|
+
} else if (!e || e.state === "pending" || e.problem?.code === "outcome_unknown" && r.state === "rejected")
|
|
21212
21328
|
void this.set(entry(r.mutation, records2, "rejected", r.problem ?? (r.state === "unknown" ? { code: "outcome_unknown", recovery: "resolve_outcome", message: "mutation unknown" } : { code: "internal", recovery: "contact_support", message: "mutation rejected" }), e?.createdAt));
|
|
21213
21329
|
}
|
|
21214
21330
|
/** @internal Reconcile persisted entries with the replica (on open). */
|
|
@@ -21218,12 +21334,11 @@ var WriteLedger = class {
|
|
|
21218
21334
|
this.store.list().catch(() => []),
|
|
21219
21335
|
this.native.pendingWrites().catch(() => null)
|
|
21220
21336
|
]);
|
|
21221
|
-
for (const
|
|
21222
|
-
|
|
21223
|
-
for (const e of stored2) if (e.state === "rejected" || !this.entries.has(e.mutationId)) this.entries.set(e.mutationId, e);
|
|
21337
|
+
for (const e of stored2) if (!unresolved(e) || !this.entries.has(e.mutationId)) this.entries.set(e.mutationId, e);
|
|
21338
|
+
this.adoptPending(pending ?? []);
|
|
21224
21339
|
this.changed();
|
|
21225
21340
|
const live = new Set(pending?.map((p) => p.receipt.mutation));
|
|
21226
|
-
|
|
21341
|
+
await Promise.all(stored2.filter((e) => unresolved(e) && !live.has(e.mutationId)).map((e) => this.settle(e.mutationId)));
|
|
21227
21342
|
} finally {
|
|
21228
21343
|
this.restored = true;
|
|
21229
21344
|
this.changed();
|
|
@@ -21234,7 +21349,9 @@ var WriteLedger = class {
|
|
|
21234
21349
|
if (this.checking) return;
|
|
21235
21350
|
this.checking = true;
|
|
21236
21351
|
try {
|
|
21237
|
-
for (const e of this.
|
|
21352
|
+
for (const e of this.entries.values()) {
|
|
21353
|
+
if (unresolved(e)) await this.settle(e.mutationId, "ignore");
|
|
21354
|
+
}
|
|
21238
21355
|
} finally {
|
|
21239
21356
|
this.checking = false;
|
|
21240
21357
|
}
|
|
@@ -21243,20 +21360,29 @@ var WriteLedger = class {
|
|
|
21243
21360
|
* (another tab of the same session wrote them): list them as pending too. */
|
|
21244
21361
|
async adopt() {
|
|
21245
21362
|
const pending = await this.native.pendingWrites().catch(() => null);
|
|
21363
|
+
if (pending && this.adoptPending(pending)) this.changed();
|
|
21364
|
+
}
|
|
21365
|
+
adoptPending(pending) {
|
|
21246
21366
|
let added = false;
|
|
21247
|
-
for (const p of pending
|
|
21248
|
-
|
|
21249
|
-
|
|
21367
|
+
for (const p of pending) {
|
|
21368
|
+
const id4 = p.receipt.mutation, e = this.entries.get(id4);
|
|
21369
|
+
if (!e || e.problem?.code === "outcome_unknown") {
|
|
21370
|
+
this.entries.set(id4, entry(id4, targets(p.ops), "pending", void 0, e?.createdAt));
|
|
21250
21371
|
added = true;
|
|
21251
21372
|
}
|
|
21252
|
-
|
|
21373
|
+
}
|
|
21374
|
+
return added;
|
|
21253
21375
|
}
|
|
21254
|
-
/**
|
|
21255
|
-
|
|
21376
|
+
/** Only a definite submit refusal delivered to the caller can retire an
|
|
21377
|
+
* intent without a receipt. A status recheck can race an in-flight submit. */
|
|
21378
|
+
async settle(id4, missing = "unknown") {
|
|
21379
|
+
const e = this.entries.get(id4);
|
|
21256
21380
|
try {
|
|
21257
21381
|
this.observe(await this.native.receipt(id4));
|
|
21258
21382
|
} catch (error4) {
|
|
21259
|
-
if (isMdbaseError(error4, "not_found")
|
|
21383
|
+
if (!isMdbaseError(error4, "not_found") || !e || this.entries.get(id4) !== e || !unresolved(e)) return;
|
|
21384
|
+
if (missing === "refused") await this.drop(id4);
|
|
21385
|
+
else if (missing === "unknown" && e.state === "pending") this.observe({ mutation: id4, state: "unknown" });
|
|
21260
21386
|
}
|
|
21261
21387
|
}
|
|
21262
21388
|
set(e) {
|
|
@@ -21317,6 +21443,7 @@ var BASES_DISCOVERY_UNREADABLE = "bases-discovery-unreadable-v1";
|
|
|
21317
21443
|
var BASES_ROW_PROPERTIES = "bases-row-properties-v1";
|
|
21318
21444
|
var CONTRACT_QUERY_ORDER = "contract-query-order-v1";
|
|
21319
21445
|
var CONTRACT_QUERY_ORDER_MTIME = "contract-query-order-mtime-v1";
|
|
21446
|
+
var SUBMIT_EXTERNAL_SOURCE = "submit-external-source-v1";
|
|
21320
21447
|
function params(entries) {
|
|
21321
21448
|
const m2 = /* @__PURE__ */ new Map();
|
|
21322
21449
|
for (const [k, v] of entries) if (v !== void 0) m2.set(k, v);
|
|
@@ -21617,16 +21744,18 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
21617
21744
|
startLedger() {
|
|
21618
21745
|
if (this.ledgerStarted) return;
|
|
21619
21746
|
this.ledgerStarted = true;
|
|
21620
|
-
|
|
21747
|
+
const restored = this.writeLedger.restore();
|
|
21748
|
+
let previous = this.lastStatus;
|
|
21621
21749
|
this.onStatus((s) => {
|
|
21622
|
-
const
|
|
21623
|
-
|
|
21750
|
+
const settled = s.pending < previous.pending || s.confirmedThrough > previous.confirmedThrough;
|
|
21751
|
+
previous = s;
|
|
21624
21752
|
this.updateDeferred();
|
|
21625
|
-
|
|
21626
|
-
|
|
21753
|
+
void restored.then(async () => {
|
|
21754
|
+
if (settled) await this.writeLedger.recheck();
|
|
21755
|
+
if (this.lastStatus.pending > this.writeLedger.pendingCount) await this.writeLedger.adopt();
|
|
21756
|
+
});
|
|
21627
21757
|
});
|
|
21628
21758
|
this.onLink(() => this.updateDeferred());
|
|
21629
|
-
void this.writeLedger.restore();
|
|
21630
21759
|
}
|
|
21631
21760
|
updateDeferred() {
|
|
21632
21761
|
this.writeLedger.setDeferred(this.transportDeferred || this.linkState !== "open" || this.lastStatus.connection === "offline");
|
|
@@ -21722,7 +21851,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
21722
21851
|
versions: API_VERSIONS,
|
|
21723
21852
|
clientName: opts.app.name,
|
|
21724
21853
|
clientVersion: opts.app.version,
|
|
21725
|
-
features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1", "file-stream-failure-v1", VALIDATE_PAGE, BASES_DISCOVERY_UNREADABLE, BASES_ROW_PROPERTIES, CONTRACT_QUERY_ORDER, CONTRACT_QUERY_ORDER_MTIME])],
|
|
21854
|
+
features: [.../* @__PURE__ */ new Set([...opts.features ?? [], PRESENCE_FEATURE, "declared-collection-setup-v1", "file-stream-failure-v1", VALIDATE_PAGE, BASES_DISCOVERY_UNREADABLE, BASES_ROW_PROPERTIES, CONTRACT_QUERY_ORDER, CONTRACT_QUERY_ORDER_MTIME, SUBMIT_EXTERNAL_SOURCE])],
|
|
21726
21855
|
...tz ? { timezone: tz } : {}
|
|
21727
21856
|
};
|
|
21728
21857
|
}
|
|
@@ -22906,6 +23035,12 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
22906
23035
|
/** Submit operations as one mutation: they apply together or not at all. */
|
|
22907
23036
|
async submit(ops, o = {}) {
|
|
22908
23037
|
if (this.hello.version.minor >= 3 && this.hello.grant.role === "viewer") throw new WriteRefusal(mdbaseError("forbidden", "You have view access, so changes can't be saved.", "read_only"));
|
|
23038
|
+
if (o.source === "external" && !this.hello.features.includes(SUBMIT_EXTERNAL_SOURCE)) {
|
|
23039
|
+
if (this.hello.grant.grant !== void 0) {
|
|
23040
|
+
throw new WriteRefusal(mdbaseError("forbidden", "External-source submits require a local host session.", "external_source_forbidden"));
|
|
23041
|
+
}
|
|
23042
|
+
throw new WriteRefusal(mdbaseError("upgrade_required", "This collection's replica does not support external-source submits.", "external_source_unsupported"));
|
|
23043
|
+
}
|
|
22909
23044
|
if (o.intent !== void 0 && o.mutationId === void 0) o = { ...o, mutationId: (await intentIds(this.collectionId, o.intent))[0] };
|
|
22910
23045
|
const mutationId = o.mutationId ?? uuidv7();
|
|
22911
23046
|
const p = { ops, mutationId };
|
|
@@ -22915,6 +23050,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
22915
23050
|
if (o.include) p.include = o.include;
|
|
22916
23051
|
if (o.wait) p.wait = o.wait;
|
|
22917
23052
|
if (o.validation) p.validation = o.validation;
|
|
23053
|
+
if (o.source) p.source = o.source;
|
|
22918
23054
|
if (!o.dryRun) {
|
|
22919
23055
|
this.startLedger();
|
|
22920
23056
|
await this.writeLedger.begin(mutationId, ops);
|
|
@@ -22930,7 +23066,6 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
22930
23066
|
receipt3 = receipts[0];
|
|
22931
23067
|
} catch (e) {
|
|
22932
23068
|
if (o.dryRun) throw e;
|
|
22933
|
-
void this.writeLedger.settle(mutationId);
|
|
22934
23069
|
if (isReplicaResponseProblem(e) && [
|
|
22935
23070
|
"invalid_request",
|
|
22936
23071
|
"invalid_record",
|
|
@@ -22942,7 +23077,11 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
22942
23077
|
"rate_limited",
|
|
22943
23078
|
"too_large",
|
|
22944
23079
|
"upgrade_required"
|
|
22945
|
-
].includes(e.code))
|
|
23080
|
+
].includes(e.code)) {
|
|
23081
|
+
void this.writeLedger.settle(mutationId, "refused");
|
|
23082
|
+
throw new WriteRefusal(e, { mutationId });
|
|
23083
|
+
}
|
|
23084
|
+
void this.writeLedger.settle(mutationId);
|
|
22946
23085
|
throw withMutation(e, "submit", { mutationId });
|
|
22947
23086
|
}
|
|
22948
23087
|
return o.dryRun ? new Write(receipt3) : this._track(receipt3);
|
|
@@ -23125,7 +23264,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
23125
23264
|
* if (saved.outcome === "rejected") show(describeError(saved.problem));
|
|
23126
23265
|
*/
|
|
23127
23266
|
settle(write, options = {}) {
|
|
23128
|
-
return settleWrite(this, write, options);
|
|
23267
|
+
return settleWrite(this, write, options, (id4) => this.ledgerStarted && this.writeLedger.mayHaveUnresolved(id4));
|
|
23129
23268
|
}
|
|
23130
23269
|
/** The current receipt of a mutation. Failures carry `mutationId`. `o.signal` cancels the read. */
|
|
23131
23270
|
receipt(mutation2, o = {}) {
|
|
@@ -25599,9 +25738,12 @@ var SpareNonces = class {
|
|
|
25599
25738
|
var MAX_FRAME2 = 16 * 1024 * 1024;
|
|
25600
25739
|
var MAX_OBJECT = 9 * 1024 * 1024;
|
|
25601
25740
|
var METHODS = /* @__PURE__ */ new Set(["append", "read", "head", "subscribe", "unsubscribe", "put_object", "get_object", "has_objects", "put_snapshot", "get_snapshot", "endorse_snapshot", "stream_join", "stream_leave", "stream_send"]);
|
|
25741
|
+
var STREAM_METHODS = /* @__PURE__ */ new Set(["stream_join", "stream_leave", "stream_send"]);
|
|
25602
25742
|
var FORBIDDEN = /* @__PURE__ */ new Set(["host", "content-length", "transfer-encoding", "connection", "keep-alive", "upgrade", "te", "trailer", "expect", "range", "cookie", "authorization", "proxy-authorization", "origin", "referer", "accept-charset", "accept-encoding", "access-control-request-headers", "access-control-request-method", "date", "dnt", "permissions-policy", "set-cookie", "via"]);
|
|
25603
25743
|
var utf82 = new TextEncoder();
|
|
25604
25744
|
var AppHttpLogError = class extends Error {
|
|
25745
|
+
/** `no_stream`: a stream call had no live push socket to travel on or got no
|
|
25746
|
+
* answer there. It says nothing about the HTTPS path to the log. */
|
|
25605
25747
|
constructor(reason, server) {
|
|
25606
25748
|
super(`app log transport: ${reason}`);
|
|
25607
25749
|
this.reason = reason;
|
|
@@ -25710,6 +25852,12 @@ var AppHttpLogTransport = class {
|
|
|
25710
25852
|
spares;
|
|
25711
25853
|
responseId = 0;
|
|
25712
25854
|
receiving = /* @__PURE__ */ new Map();
|
|
25855
|
+
streams = null;
|
|
25856
|
+
/** HOST ONLY: the push socket of this same authenticated generation, or null
|
|
25857
|
+
* when there is none. Stream calls fail as unanswered without it. */
|
|
25858
|
+
setStreamRoute(route2) {
|
|
25859
|
+
this.streams = route2;
|
|
25860
|
+
}
|
|
25713
25861
|
/** Only active logical sends, with bytes admitted under the existing body /
|
|
25714
25862
|
* range caps. Provisional network activity, never authenticated sync progress. */
|
|
25715
25863
|
responseProgress() {
|
|
@@ -26012,6 +26160,20 @@ var AppHttpLogTransport = class {
|
|
|
26012
26160
|
sidecar = call2.sidecar?.slice() ?? null;
|
|
26013
26161
|
const request3 = this.request(frame);
|
|
26014
26162
|
if (sidecar && request3.method !== "put_object") throw error("shape");
|
|
26163
|
+
if (STREAM_METHODS.has(request3.method)) {
|
|
26164
|
+
const route2 = this.streams;
|
|
26165
|
+
if (!route2) throw error("no_stream");
|
|
26166
|
+
try {
|
|
26167
|
+
reply = await route2(frame, options);
|
|
26168
|
+
} catch {
|
|
26169
|
+
throw error(options.signal.aborted || !this.isCurrent() ? "fenced" : "no_stream");
|
|
26170
|
+
}
|
|
26171
|
+
this.check(options.signal);
|
|
26172
|
+
this.response(reply, request3.id);
|
|
26173
|
+
const out2 = reply;
|
|
26174
|
+
reply = null;
|
|
26175
|
+
return out2;
|
|
26176
|
+
}
|
|
26015
26177
|
if (request3.method === "put_object") {
|
|
26016
26178
|
const size2 = number(request3.params.get(3), MAX_OBJECT), ck = bytes3(request3.params.get(4), 32), inline = request3.params.get(5);
|
|
26017
26179
|
if (size2 === 0 || sidecar !== null && (inline !== void 0 || sidecar.length <= 1024 * 1024) || sidecar === null && size2 > 1024 * 1024) throw error("shape");
|
|
@@ -27039,6 +27201,10 @@ var OPEN_MS = 15e3;
|
|
|
27039
27201
|
var UNSIGNED_ATTEMPTS = 4;
|
|
27040
27202
|
var INLINE_BYTES = 64 * 1024;
|
|
27041
27203
|
var MAX_FRAME3 = 1024 * 1024;
|
|
27204
|
+
var STREAM_METHODS2 = /* @__PURE__ */ new Set(["stream_join", "stream_leave", "stream_send"]);
|
|
27205
|
+
var STREAM_REPLY_MS = 1e4;
|
|
27206
|
+
var MAX_STREAM_CALLS = 64;
|
|
27207
|
+
var MAX_STREAM_FRAME = 32 * 1024;
|
|
27042
27208
|
function wsOrigin(input, loopback) {
|
|
27043
27209
|
const u = new URL(input);
|
|
27044
27210
|
if (u.protocol === "https:") return `wss://${u.host}`;
|
|
@@ -27047,6 +27213,10 @@ function wsOrigin(input, loopback) {
|
|
|
27047
27213
|
}
|
|
27048
27214
|
var hex6 = (b) => [...b].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
27049
27215
|
var request = (id4, method, params2) => encode(/* @__PURE__ */ new Map([[0, 0], [1, id4], [2, method], [3, params2]]));
|
|
27216
|
+
function callKey(id4) {
|
|
27217
|
+
if (typeof id4 === "bigint" ? id4 < 0n : typeof id4 !== "number" || !Number.isSafeInteger(id4) || id4 < 0) throw new Error("app log push: id");
|
|
27218
|
+
return BigInt(id4).toString();
|
|
27219
|
+
}
|
|
27050
27220
|
function errorOf(m2) {
|
|
27051
27221
|
const e = m2.get(3);
|
|
27052
27222
|
if (!(e instanceof Map)) return null;
|
|
@@ -27088,6 +27258,11 @@ var AppLogPushChannel = class {
|
|
|
27088
27258
|
unsigned = 0;
|
|
27089
27259
|
life = new AbortController();
|
|
27090
27260
|
token = null;
|
|
27261
|
+
/** Which response the current socket owes next: its `hello` (id 1), its
|
|
27262
|
+
* `subscribe` (id 2), and after that only answers to stream calls, whose IDs
|
|
27263
|
+
* are the replica's own and may be any number. */
|
|
27264
|
+
phase = "hello";
|
|
27265
|
+
calls = /* @__PURE__ */ new Map();
|
|
27091
27266
|
/** Live: subscribed, so other devices' changes arrive as they commit. */
|
|
27092
27267
|
get live() {
|
|
27093
27268
|
return this.isLive;
|
|
@@ -27135,6 +27310,64 @@ var AppLogPushChannel = class {
|
|
|
27135
27310
|
this.clearRetry();
|
|
27136
27311
|
this.drop(1e3, "closed");
|
|
27137
27312
|
}
|
|
27313
|
+
/** Send one replica-made stream call and resolve with the service's response
|
|
27314
|
+
* frame, unread: the replica checks it against its own original call. Rejects
|
|
27315
|
+
* when the socket is not live, is lost before the answer, or the answer does
|
|
27316
|
+
* not come; all three are an unknown outcome to the replica, never a retry here. */
|
|
27317
|
+
request(frame, options) {
|
|
27318
|
+
return new Promise((resolve, reject) => {
|
|
27319
|
+
const no = (why) => reject(new Error(`app log push: ${why}`));
|
|
27320
|
+
const s = this.socket;
|
|
27321
|
+
if (!s || !this.isLive) {
|
|
27322
|
+
no("not live");
|
|
27323
|
+
return;
|
|
27324
|
+
}
|
|
27325
|
+
if (!(frame instanceof Uint8Array) || frame.length > MAX_STREAM_FRAME || this.calls.size >= MAX_STREAM_CALLS) {
|
|
27326
|
+
no("call");
|
|
27327
|
+
return;
|
|
27328
|
+
}
|
|
27329
|
+
let key3;
|
|
27330
|
+
try {
|
|
27331
|
+
const v = decode(frame);
|
|
27332
|
+
if (!(v instanceof Map)) throw new Error();
|
|
27333
|
+
const m2 = v;
|
|
27334
|
+
if (m2.get(0) !== 0 || !STREAM_METHODS2.has(m2.get(2))) throw new Error();
|
|
27335
|
+
key3 = callKey(m2.get(1));
|
|
27336
|
+
} catch {
|
|
27337
|
+
no("call");
|
|
27338
|
+
return;
|
|
27339
|
+
}
|
|
27340
|
+
if (this.calls.has(key3) || options.signal.aborted) {
|
|
27341
|
+
no("call");
|
|
27342
|
+
return;
|
|
27343
|
+
}
|
|
27344
|
+
const settle = () => {
|
|
27345
|
+
clearTimeout(call2.timer);
|
|
27346
|
+
options.signal.removeEventListener("abort", call2.stop);
|
|
27347
|
+
this.calls.delete(key3);
|
|
27348
|
+
};
|
|
27349
|
+
const call2 = {
|
|
27350
|
+
resolve: (reply) => {
|
|
27351
|
+
settle();
|
|
27352
|
+
resolve(reply);
|
|
27353
|
+
},
|
|
27354
|
+
reject: (error4) => {
|
|
27355
|
+
settle();
|
|
27356
|
+
reject(error4);
|
|
27357
|
+
},
|
|
27358
|
+
timer: setTimeout(() => call2.reject(new Error("app log push: no reply")), STREAM_REPLY_MS),
|
|
27359
|
+
stop: () => call2.reject(new Error("app log push: aborted"))
|
|
27360
|
+
};
|
|
27361
|
+
options.signal.addEventListener("abort", call2.stop, { once: true });
|
|
27362
|
+
this.calls.set(key3, call2);
|
|
27363
|
+
try {
|
|
27364
|
+
s.send(frame);
|
|
27365
|
+
} catch {
|
|
27366
|
+
call2.reject(new Error("app log push: send"));
|
|
27367
|
+
this.lost(s, 1006);
|
|
27368
|
+
}
|
|
27369
|
+
});
|
|
27370
|
+
}
|
|
27138
27371
|
clearRetry() {
|
|
27139
27372
|
if (this.retry !== null) clearTimeout(this.retry);
|
|
27140
27373
|
this.retry = null;
|
|
@@ -27177,6 +27410,7 @@ var AppLogPushChannel = class {
|
|
|
27177
27410
|
} catch {
|
|
27178
27411
|
}
|
|
27179
27412
|
}
|
|
27413
|
+
for (const call2 of [...this.calls.values()]) call2.reject(new Error("app log push: lost"));
|
|
27180
27414
|
this.setLive(false);
|
|
27181
27415
|
}
|
|
27182
27416
|
/** Full-jitter backoff, 1 s → 60 s; reset after a minute of a healthy socket. */
|
|
@@ -27226,6 +27460,7 @@ var AppLogPushChannel = class {
|
|
|
27226
27460
|
}
|
|
27227
27461
|
s.binaryType = "arraybuffer";
|
|
27228
27462
|
this.socket = s;
|
|
27463
|
+
this.phase = "hello";
|
|
27229
27464
|
const hello = request(1, "hello", /* @__PURE__ */ new Map([[0, [1, 0]], [1, token], [2, uuidToBytes(this.source.deviceId)], [3, sig]]));
|
|
27230
27465
|
sig.fill(0);
|
|
27231
27466
|
nonce.fill(0);
|
|
@@ -27279,11 +27514,23 @@ var AppLogPushChannel = class {
|
|
|
27279
27514
|
}
|
|
27280
27515
|
if (m2.get(0) !== 1) return;
|
|
27281
27516
|
const id4 = m2.get(1), error4 = errorOf(m2);
|
|
27282
|
-
if (
|
|
27517
|
+
if (this.phase === "live") {
|
|
27518
|
+
let key3;
|
|
27519
|
+
try {
|
|
27520
|
+
key3 = callKey(id4);
|
|
27521
|
+
} catch {
|
|
27522
|
+
return;
|
|
27523
|
+
}
|
|
27524
|
+
this.calls.get(key3)?.resolve(bytes10.slice());
|
|
27525
|
+
return;
|
|
27526
|
+
}
|
|
27527
|
+
if (this.phase === "hello") {
|
|
27528
|
+
if (id4 !== 1) return;
|
|
27283
27529
|
if (error4) {
|
|
27284
27530
|
this.refused(s, error4);
|
|
27285
27531
|
return;
|
|
27286
27532
|
}
|
|
27533
|
+
this.phase = "subscribe";
|
|
27287
27534
|
try {
|
|
27288
27535
|
s.send(request(2, "subscribe", /* @__PURE__ */ new Map([[0, this.collectionBytes], [1, 0], [2, INLINE_BYTES]])));
|
|
27289
27536
|
} catch {
|
|
@@ -27302,6 +27549,7 @@ var AppLogPushChannel = class {
|
|
|
27302
27549
|
return;
|
|
27303
27550
|
}
|
|
27304
27551
|
const head = result2.get(0), chain = result2.get(1);
|
|
27552
|
+
this.phase = "live";
|
|
27305
27553
|
this.startPing(s);
|
|
27306
27554
|
this.setLive(true);
|
|
27307
27555
|
if ((typeof head === "number" || typeof head === "bigint") && chain instanceof Uint8Array && chain.length === 32)
|
|
@@ -27901,7 +28149,23 @@ function bridge(channel, source, receive, ended, bases) {
|
|
|
27901
28149
|
current: current2
|
|
27902
28150
|
};
|
|
27903
28151
|
}
|
|
27904
|
-
var LOG_WORK = /* @__PURE__ */ new Set([
|
|
28152
|
+
var LOG_WORK = /* @__PURE__ */ new Set([
|
|
28153
|
+
"submit",
|
|
28154
|
+
"resolve_hold",
|
|
28155
|
+
"open_upload",
|
|
28156
|
+
"upload_chunk",
|
|
28157
|
+
"commit_upload",
|
|
28158
|
+
"abort_upload",
|
|
28159
|
+
"fetch_file",
|
|
28160
|
+
"read_file",
|
|
28161
|
+
"ack_chunks",
|
|
28162
|
+
// Presence joins a stream and sends on it: other people see it now, not on the next turn.
|
|
28163
|
+
"presence_join",
|
|
28164
|
+
"presence_update",
|
|
28165
|
+
"presence_leave",
|
|
28166
|
+
"subscribe_presence",
|
|
28167
|
+
"unsubscribe_presence"
|
|
28168
|
+
]);
|
|
27905
28169
|
function queuesLogWork(frame) {
|
|
27906
28170
|
if (!(frame instanceof Map)) return false;
|
|
27907
28171
|
const fields3 = frame;
|
|
@@ -33873,6 +34137,7 @@ function equal8(a, b) {
|
|
|
33873
34137
|
}
|
|
33874
34138
|
var UNORDERED = /* @__PURE__ */ new Set(["read", "head", "subscribe", "get_object", "has_objects", "put_object", "get_snapshot"]);
|
|
33875
34139
|
var MAX_CONCURRENT = 6;
|
|
34140
|
+
var STREAM = /* @__PURE__ */ new Set(["stream_join", "stream_leave", "stream_send"]);
|
|
33876
34141
|
function serverOf(e) {
|
|
33877
34142
|
try {
|
|
33878
34143
|
return e.server;
|
|
@@ -34073,7 +34338,7 @@ var AppLogPump = class {
|
|
|
34073
34338
|
continue;
|
|
34074
34339
|
}
|
|
34075
34340
|
if (this.runtime.acceptLogReply(c.id, reply) !== true) this.runtime.logNoResponse(c.id);
|
|
34076
|
-
else {
|
|
34341
|
+
else if (!STREAM.has(c.method)) {
|
|
34077
34342
|
this.problem = null;
|
|
34078
34343
|
this.health = null;
|
|
34079
34344
|
if (c.read) {
|
|
@@ -35839,6 +36104,14 @@ var AppWasmRuntime = class _AppWasmRuntime extends WasmRuntime {
|
|
|
35839
36104
|
owned?.fill(0);
|
|
35840
36105
|
}
|
|
35841
36106
|
}
|
|
36107
|
+
/** HOST ONLY: the push socket became subscribed (true) or was lost (false).
|
|
36108
|
+
* Ephemeral stream calls travel on that socket and the log drops a socket's
|
|
36109
|
+
* stream memberships with it, so the replica joins again on true and forgets
|
|
36110
|
+
* the people it had seen on false. False when unsupported or not bound. */
|
|
36111
|
+
setLogStreamLink(up) {
|
|
36112
|
+
if (!this.active || this.retired || !this.pump || typeof this.app.rt_app_log_stream_link !== "function") return false;
|
|
36113
|
+
return this.guard(() => this.app.rt_app_log_stream_link(up ? 1 : 0)) === 1;
|
|
36114
|
+
}
|
|
35842
36115
|
/** HOST ONLY wake AFTER fresh authenticated authority admission: drain/abort
|
|
35843
36116
|
* original pump before SAME-owner native session/generation replacement. May
|
|
35844
36117
|
* hang: owner must terminate Worker before releasing lease. Not readiness. */
|
|
@@ -38218,7 +38491,9 @@ var AppWebCloudCopyHost = class _AppWebCloudCopyHost {
|
|
|
38218
38491
|
}
|
|
38219
38492
|
/** The log's push socket for this collection, or null when the runtime cannot
|
|
38220
38493
|
* sign its `hello` (older native asset): then the caller wakes on events only.
|
|
38221
|
-
* Requires the started log. The socket
|
|
38494
|
+
* Requires the started log. The socket carries no log requests; it does carry
|
|
38495
|
+
* the replica's ephemeral stream calls (presence), whose memberships are the
|
|
38496
|
+
* socket's own, and tells the replica when that link comes and goes. */
|
|
38222
38497
|
openLogPush(events) {
|
|
38223
38498
|
this.checkCollection(this.lifetime);
|
|
38224
38499
|
const native = this.native, authority = this.authority, session = this.collectionSession, request3 = this.logRequest;
|
|
@@ -38232,7 +38507,8 @@ var AppWebCloudCopyHost = class _AppWebCloudCopyHost {
|
|
|
38232
38507
|
return false;
|
|
38233
38508
|
}
|
|
38234
38509
|
};
|
|
38235
|
-
|
|
38510
|
+
const transport = authority.logTransport();
|
|
38511
|
+
const channel = new AppLogPushChannel({
|
|
38236
38512
|
origin: origin4,
|
|
38237
38513
|
collection: authority.collection,
|
|
38238
38514
|
deviceId: session.deviceId,
|
|
@@ -38246,7 +38522,25 @@ var AppWebCloudCopyHost = class _AppWebCloudCopyHost {
|
|
|
38246
38522
|
return Uint8Array.from(text6.match(/../g).map((v) => parseInt(v, 16)));
|
|
38247
38523
|
},
|
|
38248
38524
|
signHello: (nonce, token) => current2() ? native.signLogHello(nonce, token) : null
|
|
38249
|
-
},
|
|
38525
|
+
}, {
|
|
38526
|
+
push: events.push,
|
|
38527
|
+
ended: events.ended,
|
|
38528
|
+
live: (live) => {
|
|
38529
|
+
try {
|
|
38530
|
+
if (current2()) native.setLogStreamLink(live);
|
|
38531
|
+
} catch {
|
|
38532
|
+
}
|
|
38533
|
+
events.live(live);
|
|
38534
|
+
if (live) {
|
|
38535
|
+
try {
|
|
38536
|
+
this.logWorkListener?.();
|
|
38537
|
+
} catch {
|
|
38538
|
+
}
|
|
38539
|
+
}
|
|
38540
|
+
}
|
|
38541
|
+
}, { allowLoopbackHttp: loopback });
|
|
38542
|
+
transport.setStreamRoute((frame, options) => channel.request(frame, options));
|
|
38543
|
+
return channel;
|
|
38250
38544
|
}
|
|
38251
38545
|
/** Ordinary foreground log drive. Quiet/head/ACK/status are NOT read/Saved. */
|
|
38252
38546
|
async driveCollection(options) {
|
|
@@ -39344,15 +39638,17 @@ var AppWebSignInSession = class {
|
|
|
39344
39638
|
}, true);
|
|
39345
39639
|
}
|
|
39346
39640
|
/** One read of the current file access request. Lost reads stay pending
|
|
39347
|
-
* until the request expires
|
|
39641
|
+
* until the request expires. A skipped or failed read rejects so callers can
|
|
39642
|
+
* distinguish it from a confirmed pending outcome. */
|
|
39348
39643
|
pollFileAccess(requestId) {
|
|
39349
39644
|
const request3 = this.fileAccess;
|
|
39350
|
-
if (!request3 || request3.requestId !== requestId ||
|
|
39645
|
+
if (!request3 || request3.requestId !== requestId || !this.flow || !this.installation) return Promise.resolve(this.getSnapshot());
|
|
39351
39646
|
return this.operation(async () => {
|
|
39352
39647
|
let outcome = { state: "pending" };
|
|
39353
39648
|
try {
|
|
39354
39649
|
outcome = await this.flow.exchangeFileAccess(this.installation, request3);
|
|
39355
|
-
} catch {
|
|
39650
|
+
} catch (error4) {
|
|
39651
|
+
if (Date.now() < request3.expiresAt) throw error4;
|
|
39356
39652
|
}
|
|
39357
39653
|
this.check();
|
|
39358
39654
|
if (this.fileAccess !== request3 || outcome.state === "pending" && Date.now() < request3.expiresAt) return this.getSnapshot();
|
|
@@ -40505,6 +40801,8 @@ var AppScopedSignInSession = class {
|
|
|
40505
40801
|
focus = null;
|
|
40506
40802
|
approvalOwner = null;
|
|
40507
40803
|
changingIdentity = false;
|
|
40804
|
+
// Erasing a scoped installation also erases its ability to retry revocation.
|
|
40805
|
+
scopedRevocationIncomplete = false;
|
|
40508
40806
|
foreground = true;
|
|
40509
40807
|
quarantined = /* @__PURE__ */ new Set();
|
|
40510
40808
|
closing = null;
|
|
@@ -40589,6 +40887,9 @@ var AppScopedSignInSession = class {
|
|
|
40589
40887
|
const account = this.original.getSnapshot().signIn?.accountId;
|
|
40590
40888
|
for (const child of this.activeChildren()) for (const c of child.session.getSnapshot().signIn?.nativeGrants ?? []) if (c.account_id === account) nativeGrants.set(c.collection_id, c);
|
|
40591
40889
|
const signIn = view.signIn ? Object.freeze({ ...view.signIn, nativeGrants: Object.freeze([...nativeGrants.values()]) }) : null;
|
|
40890
|
+
if (this.scopedRevocationIncomplete && view.signOutResult) {
|
|
40891
|
+
view = { ...view, signOutResult: Object.freeze({ ...view.signOutResult, server: "incomplete" }) };
|
|
40892
|
+
}
|
|
40592
40893
|
return Object.freeze({ ...view, signIn, collections: this.collections(), removedScopeIds, ...accountLabel ? { recoveryAccountLabel: accountLabel } : {} });
|
|
40593
40894
|
}
|
|
40594
40895
|
connection(id4 = this.focus) {
|
|
@@ -40622,6 +40923,7 @@ var AppScopedSignInSession = class {
|
|
|
40622
40923
|
}
|
|
40623
40924
|
async start() {
|
|
40624
40925
|
this.check();
|
|
40926
|
+
if (this.original.getSnapshot().signOutResult) this.scopedRevocationIncomplete = false;
|
|
40625
40927
|
await this.original.start();
|
|
40626
40928
|
this.check();
|
|
40627
40929
|
await this.restoreChildren();
|
|
@@ -40774,6 +41076,7 @@ var AppScopedSignInSession = class {
|
|
|
40774
41076
|
await this.restoreChildren(true);
|
|
40775
41077
|
for (const [reference, actor] of this.scoped) {
|
|
40776
41078
|
const result2 = await actor.session.signOut();
|
|
41079
|
+
if (result2.signOutResult?.server === "incomplete") this.scopedRevocationIncomplete = true;
|
|
40777
41080
|
if (result2.signOutResult?.local !== "erased") {
|
|
40778
41081
|
this.quarantined.add(reference);
|
|
40779
41082
|
throw new AppInstallationSignInError("recovery_required");
|