@mdbase-dev/sdk 0.1.0-beta.187 → 0.1.0-beta.188
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 +188 -953
- package/dist/app-grant/client.js +7 -3
- package/dist/app-grant/client.js.map +1 -1
- package/dist/app-grant/setup.js +2 -2
- package/dist/app-grant/setup.js.map +1 -1
- package/dist/app-host/cloud-copy-host.js +1 -1
- package/dist/app-host/cloud-copy-host.js.map +1 -1
- package/dist/app-host/collection-readiness.js +10 -12
- package/dist/app-host/collection-readiness.js.map +1 -1
- package/dist/app-host/handover.js +1 -1
- package/dist/app-host/handover.js.map +1 -1
- package/dist/app-host/initial-sync.js +4 -4
- package/dist/app-host/initial-sync.js.map +1 -1
- package/dist/application/browser-capabilities.d.ts +1 -1
- package/dist/application/browser-capabilities.js +3 -2
- package/dist/application/browser-capabilities.js.map +1 -1
- package/dist/application/configuration.js +12 -12
- package/dist/application/configuration.js.map +1 -1
- package/dist/application/entry.d.ts +51 -107
- package/dist/application/entry.js +139 -86
- package/dist/application/entry.js.map +1 -1
- package/dist/application/front-door.d.ts +30 -12
- package/dist/application/front-door.js +2 -89
- package/dist/application/front-door.js.map +1 -1
- package/dist/application/phase.d.ts +4 -1
- package/dist/application/phase.js +5 -4
- package/dist/application/phase.js.map +1 -1
- package/dist/application/private-collections.js +2 -1
- package/dist/application/private-collections.js.map +1 -1
- package/dist/application/registration-refusal.d.ts +1 -1
- package/dist/application/registration-refusal.js +1 -3
- package/dist/application/registration-refusal.js.map +1 -1
- package/dist/application/registration.js +1 -4
- package/dist/application/registration.js.map +1 -1
- package/dist/application/setup.d.ts +6 -9
- package/dist/application/setup.js +16 -0
- package/dist/application/setup.js.map +1 -1
- package/dist/application/tabs.d.ts +15 -2
- package/dist/application/tabs.js +35 -13
- package/dist/application/tabs.js.map +1 -1
- package/dist/application/unsynced-transfer.d.ts +1 -1
- package/dist/application/unsynced-transfer.js +3 -3
- package/dist/application/unsynced-transfer.js.map +1 -1
- package/dist/application/worker.js +928 -449
- package/dist/browser/mdbase-sdk.js +21271 -20750
- package/dist/browser/mdbase-sdk.min.js +65 -65
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/browser.js.map +1 -1
- package/dist/client.d.ts +169 -81
- package/dist/client.js +236 -178
- package/dist/client.js.map +1 -1
- package/dist/codec.d.ts +15 -0
- package/dist/codec.js +44 -2
- package/dist/codec.js.map +1 -1
- package/dist/collection-api.d.ts +44 -0
- package/dist/collection-api.js +24 -0
- package/dist/collection-api.js.map +1 -0
- package/dist/collection-availability.js +1 -1
- package/dist/collection-availability.js.map +1 -1
- package/dist/contract-query.d.ts +22 -3
- package/dist/contract-query.js.map +1 -1
- package/dist/contract-records.d.ts +2 -1
- package/dist/contract-records.js.map +1 -1
- package/dist/describe-error.d.ts +1 -1
- package/dist/describe-error.js +7 -6
- package/dist/describe-error.js.map +1 -1
- package/dist/errors.d.ts +3 -5
- package/dist/errors.js +3 -8
- package/dist/errors.js.map +1 -1
- package/dist/files.d.ts +7 -5
- package/dist/files.js +16 -17
- package/dist/files.js.map +1 -1
- package/dist/holds.d.ts +2 -1
- package/dist/holds.js.map +1 -1
- package/dist/index.d.ts +7 -11
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/live.d.ts +2 -1
- package/dist/live.js.map +1 -1
- package/dist/manifest.d.ts +1 -1
- package/dist/manifest.js +1 -1
- package/dist/native/provenance.json +1 -1
- package/dist/people.js +3 -7
- package/dist/people.js.map +1 -1
- package/dist/plain.d.ts +102 -0
- package/dist/plain.js +62 -0
- package/dist/plain.js.map +1 -0
- package/dist/presence.d.ts +2 -1
- package/dist/presence.js +3 -3
- package/dist/presence.js.map +1 -1
- package/dist/read-helpers.d.ts +8 -6
- package/dist/read-helpers.js +20 -13
- package/dist/read-helpers.js.map +1 -1
- package/dist/record-set.d.ts +98 -0
- package/dist/record-set.js +347 -0
- package/dist/record-set.js.map +1 -0
- package/dist/records/session.d.ts +2 -1
- package/dist/records/session.js +22 -20
- package/dist/records/session.js.map +1 -1
- package/dist/records/types.d.ts +5 -3
- package/dist/records/witness.d.ts +7 -4
- package/dist/records/witness.js +13 -8
- package/dist/records/witness.js.map +1 -1
- package/dist/records.js +5 -2
- package/dist/records.js.map +1 -1
- package/dist/saved-views.d.ts +12 -4
- package/dist/saved-views.js +51 -43
- package/dist/saved-views.js.map +1 -1
- package/dist/settle.d.ts +62 -0
- package/dist/settle.js +119 -0
- package/dist/settle.js.map +1 -0
- package/dist/status.d.ts +84 -28
- package/dist/status.js +54 -48
- package/dist/status.js.map +1 -1
- package/dist/testing/application.d.ts +16 -9
- package/dist/testing/application.js +48 -45
- package/dist/testing/application.js.map +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/memory-contracts.d.ts +5 -0
- package/dist/testing/memory-contracts.js.map +1 -1
- package/dist/testing/memory-replica.d.ts +58 -5
- package/dist/testing/memory-replica.js +126 -19
- package/dist/testing/memory-replica.js.map +1 -1
- package/dist/testing/test-app.d.ts +9 -10
- package/dist/testing/test-app.js +8 -17
- package/dist/testing/test-app.js.map +1 -1
- package/dist/thin-client.d.ts +15 -38
- package/dist/thin-client.js +11 -20
- package/dist/thin-client.js.map +1 -1
- package/dist/transport/control-route.js +1 -1
- package/dist/transport/control-route.js.map +1 -1
- package/dist/transport/relay-close.d.ts +0 -1
- package/dist/transport/relay-close.js +4 -2
- package/dist/transport/relay-close.js.map +1 -1
- package/dist/transport/relay-pipe.js +2 -2
- package/dist/transport/relay-pipe.js.map +1 -1
- package/dist/type-packs.js +4 -4
- package/dist/type-packs.js.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +2 -2
- package/dist/validation.js.map +1 -1
- package/dist/values.d.ts +4 -20
- package/dist/values.js +3 -49
- package/dist/values.js.map +1 -1
- package/dist/view-sources.d.ts +2 -1
- package/dist/view-sources.js +1 -1
- package/dist/view-sources.js.map +1 -1
- package/dist/wire.d.ts +7 -3
- package/dist/wire.js +4 -4
- package/dist/wire.js.map +1 -1
- package/dist/write-ledger.d.ts +2 -1
- package/dist/write-ledger.js +3 -6
- package/dist/write-ledger.js.map +1 -1
- package/package.json +1 -1
|
@@ -63,10 +63,10 @@ function abytes(value2, length, title = "") {
|
|
|
63
63
|
const bytes10 = isBytes(value2);
|
|
64
64
|
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
65
65
|
const got = bytes10 ? `length=${value2.length}` : `type=${typeof value2}`;
|
|
66
|
-
const
|
|
66
|
+
const message2 = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
67
67
|
if (!bytes10)
|
|
68
|
-
throw new TypeError(
|
|
69
|
-
throw new RangeError(
|
|
68
|
+
throw new TypeError(message2);
|
|
69
|
+
throw new RangeError(message2);
|
|
70
70
|
}
|
|
71
71
|
function copyBytes(bytes10) {
|
|
72
72
|
return Uint8Array.from(abytes(bytes10));
|
|
@@ -1717,16 +1717,16 @@ function foldFlowLines(text6, indent, mode = "flow", { indentAtStart, lineWidth
|
|
|
1717
1717
|
onFold();
|
|
1718
1718
|
let res = text6.slice(0, folds[0]);
|
|
1719
1719
|
for (let i2 = 0; i2 < folds.length; ++i2) {
|
|
1720
|
-
const
|
|
1720
|
+
const fold2 = folds[i2];
|
|
1721
1721
|
const end2 = folds[i2 + 1] || text6.length;
|
|
1722
|
-
if (
|
|
1722
|
+
if (fold2 === 0)
|
|
1723
1723
|
res = `
|
|
1724
1724
|
${indent}${text6.slice(0, end2)}`;
|
|
1725
1725
|
else {
|
|
1726
|
-
if (mode === FOLD_QUOTED && escapedFolds[
|
|
1727
|
-
res += `${text6[
|
|
1726
|
+
if (mode === FOLD_QUOTED && escapedFolds[fold2])
|
|
1727
|
+
res += `${text6[fold2]}\\`;
|
|
1728
1728
|
res += `
|
|
1729
|
-
${indent}${text6.slice(
|
|
1729
|
+
${indent}${text6.slice(fold2 + 1, end2)}`;
|
|
1730
1730
|
}
|
|
1731
1731
|
}
|
|
1732
1732
|
return res;
|
|
@@ -1776,27 +1776,27 @@ function lineLengthOverLimit(str2, lineWidth, indentLength) {
|
|
|
1776
1776
|
return true;
|
|
1777
1777
|
}
|
|
1778
1778
|
function doubleQuotedString(value2, ctx) {
|
|
1779
|
-
const
|
|
1779
|
+
const json3 = JSON.stringify(value2);
|
|
1780
1780
|
if (ctx.options.doubleQuotedAsJSON)
|
|
1781
|
-
return
|
|
1781
|
+
return json3;
|
|
1782
1782
|
const { implicitKey } = ctx;
|
|
1783
1783
|
const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
|
|
1784
1784
|
const indent = ctx.indent || (containsDocumentMarker(value2) ? " " : "");
|
|
1785
1785
|
let str2 = "";
|
|
1786
1786
|
let start = 0;
|
|
1787
|
-
for (let i = 0, ch =
|
|
1788
|
-
if (ch === " " &&
|
|
1789
|
-
str2 +=
|
|
1787
|
+
for (let i = 0, ch = json3[i]; ch; ch = json3[++i]) {
|
|
1788
|
+
if (ch === " " && json3[i + 1] === "\\" && json3[i + 2] === "n") {
|
|
1789
|
+
str2 += json3.slice(start, i) + "\\ ";
|
|
1790
1790
|
i += 1;
|
|
1791
1791
|
start = i;
|
|
1792
1792
|
ch = "\\";
|
|
1793
1793
|
}
|
|
1794
1794
|
if (ch === "\\")
|
|
1795
|
-
switch (
|
|
1795
|
+
switch (json3[i + 1]) {
|
|
1796
1796
|
case "u":
|
|
1797
1797
|
{
|
|
1798
|
-
str2 +=
|
|
1799
|
-
const code =
|
|
1798
|
+
str2 += json3.slice(start, i);
|
|
1799
|
+
const code = json3.substr(i + 2, 4);
|
|
1800
1800
|
switch (code) {
|
|
1801
1801
|
case "0000":
|
|
1802
1802
|
str2 += "\\0";
|
|
@@ -1826,23 +1826,23 @@ function doubleQuotedString(value2, ctx) {
|
|
|
1826
1826
|
if (code.substr(0, 2) === "00")
|
|
1827
1827
|
str2 += "\\x" + code.substr(2);
|
|
1828
1828
|
else
|
|
1829
|
-
str2 +=
|
|
1829
|
+
str2 += json3.substr(i, 6);
|
|
1830
1830
|
}
|
|
1831
1831
|
i += 5;
|
|
1832
1832
|
start = i + 1;
|
|
1833
1833
|
}
|
|
1834
1834
|
break;
|
|
1835
1835
|
case "n":
|
|
1836
|
-
if (implicitKey ||
|
|
1836
|
+
if (implicitKey || json3[i + 2] === '"' || json3.length < minMultiLineLength) {
|
|
1837
1837
|
i += 1;
|
|
1838
1838
|
} else {
|
|
1839
|
-
str2 +=
|
|
1840
|
-
while (
|
|
1839
|
+
str2 += json3.slice(start, i) + "\n\n";
|
|
1840
|
+
while (json3[i + 2] === "\\" && json3[i + 3] === "n" && json3[i + 4] !== '"') {
|
|
1841
1841
|
str2 += "\n";
|
|
1842
1842
|
i += 2;
|
|
1843
1843
|
}
|
|
1844
1844
|
str2 += indent;
|
|
1845
|
-
if (
|
|
1845
|
+
if (json3[i + 2] === " ")
|
|
1846
1846
|
str2 += "\\";
|
|
1847
1847
|
i += 1;
|
|
1848
1848
|
start = i + 1;
|
|
@@ -1852,7 +1852,7 @@ function doubleQuotedString(value2, ctx) {
|
|
|
1852
1852
|
i += 1;
|
|
1853
1853
|
}
|
|
1854
1854
|
}
|
|
1855
|
-
str2 = start ? str2 +
|
|
1855
|
+
str2 = start ? str2 + json3.slice(start) : json3;
|
|
1856
1856
|
return implicitKey ? str2 : foldFlowLines(str2, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
1857
1857
|
}
|
|
1858
1858
|
function singleQuotedString(value2, ctx) {
|
|
@@ -3925,11 +3925,11 @@ var Document = class _Document {
|
|
|
3925
3925
|
throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
|
|
3926
3926
|
}
|
|
3927
3927
|
// json & jsonArg are only used from toJSON()
|
|
3928
|
-
toJS({ json:
|
|
3928
|
+
toJS({ json: json3, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
3929
3929
|
const ctx = {
|
|
3930
3930
|
anchors: /* @__PURE__ */ new Map(),
|
|
3931
3931
|
doc: this,
|
|
3932
|
-
keep: !
|
|
3932
|
+
keep: !json3,
|
|
3933
3933
|
mapAsMap: mapAsMap === true,
|
|
3934
3934
|
mapKeyWarned: false,
|
|
3935
3935
|
maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
|
|
@@ -3968,22 +3968,22 @@ function assertCollection(contents) {
|
|
|
3968
3968
|
|
|
3969
3969
|
// node_modules/yaml/browser/dist/errors.js
|
|
3970
3970
|
var YAMLError = class extends Error {
|
|
3971
|
-
constructor(name2, pos, code,
|
|
3971
|
+
constructor(name2, pos, code, message2) {
|
|
3972
3972
|
super();
|
|
3973
3973
|
this.name = name2;
|
|
3974
3974
|
this.code = code;
|
|
3975
|
-
this.message =
|
|
3975
|
+
this.message = message2;
|
|
3976
3976
|
this.pos = pos;
|
|
3977
3977
|
}
|
|
3978
3978
|
};
|
|
3979
3979
|
var YAMLParseError = class extends YAMLError {
|
|
3980
|
-
constructor(pos, code,
|
|
3981
|
-
super("YAMLParseError", pos, code,
|
|
3980
|
+
constructor(pos, code, message2) {
|
|
3981
|
+
super("YAMLParseError", pos, code, message2);
|
|
3982
3982
|
}
|
|
3983
3983
|
};
|
|
3984
3984
|
var YAMLWarning = class extends YAMLError {
|
|
3985
|
-
constructor(pos, code,
|
|
3986
|
-
super("YAMLWarning", pos, code,
|
|
3985
|
+
constructor(pos, code, message2) {
|
|
3986
|
+
super("YAMLWarning", pos, code, message2);
|
|
3987
3987
|
}
|
|
3988
3988
|
};
|
|
3989
3989
|
var prettifyError = (src, lc) => (error4) => {
|
|
@@ -4580,8 +4580,8 @@ function composeCollection(CN2, ctx, token, props, onError) {
|
|
|
4580
4580
|
const { anchor, newlineAfterProp: nl } = props;
|
|
4581
4581
|
const lastProp = anchor && tagToken ? anchor.offset > tagToken.offset ? anchor : tagToken : anchor ?? tagToken;
|
|
4582
4582
|
if (lastProp && (!nl || nl.offset < lastProp.offset)) {
|
|
4583
|
-
const
|
|
4584
|
-
onError(lastProp, "MISSING_CHAR",
|
|
4583
|
+
const message2 = "Missing newline after block sequence props";
|
|
4584
|
+
onError(lastProp, "MISSING_CHAR", message2);
|
|
4585
4585
|
}
|
|
4586
4586
|
}
|
|
4587
4587
|
const expType = token.type === "block-map" ? "map" : token.type === "block-seq" ? "seq" : token.start.source === "{" ? "map" : "seq";
|
|
@@ -4646,15 +4646,15 @@ function resolveBlockScalar(ctx, scalar, onError) {
|
|
|
4646
4646
|
trimIndent = indent.length;
|
|
4647
4647
|
} else {
|
|
4648
4648
|
if (indent.length < trimIndent) {
|
|
4649
|
-
const
|
|
4650
|
-
onError(offset + indent.length, "MISSING_CHAR",
|
|
4649
|
+
const message2 = "Block scalars with more-indented leading empty lines must use an explicit indentation indicator";
|
|
4650
|
+
onError(offset + indent.length, "MISSING_CHAR", message2);
|
|
4651
4651
|
}
|
|
4652
4652
|
if (header.indent === 0)
|
|
4653
4653
|
trimIndent = indent.length;
|
|
4654
4654
|
contentStart = i;
|
|
4655
4655
|
if (trimIndent === 0 && !ctx.atRoot) {
|
|
4656
|
-
const
|
|
4657
|
-
onError(offset, "BAD_INDENT",
|
|
4656
|
+
const message2 = "Block scalar values in collections must be indented";
|
|
4657
|
+
onError(offset, "BAD_INDENT", message2);
|
|
4658
4658
|
}
|
|
4659
4659
|
break;
|
|
4660
4660
|
}
|
|
@@ -4677,8 +4677,8 @@ function resolveBlockScalar(ctx, scalar, onError) {
|
|
|
4677
4677
|
content = content.slice(0, -1);
|
|
4678
4678
|
if (content && indent.length < trimIndent) {
|
|
4679
4679
|
const src = header.indent ? "explicit indentation indicator" : "first line";
|
|
4680
|
-
const
|
|
4681
|
-
onError(offset - content.length - (crlf ? 2 : 1), "BAD_INDENT",
|
|
4680
|
+
const message2 = `Block scalar lines must not be less indented than their ${src}`;
|
|
4681
|
+
onError(offset - content.length - (crlf ? 2 : 1), "BAD_INDENT", message2);
|
|
4682
4682
|
indent = "";
|
|
4683
4683
|
}
|
|
4684
4684
|
if (type === Scalar.BLOCK_LITERAL) {
|
|
@@ -4756,8 +4756,8 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
4756
4756
|
break;
|
|
4757
4757
|
case "comment":
|
|
4758
4758
|
if (strict && !hasSpace) {
|
|
4759
|
-
const
|
|
4760
|
-
onError(token, "MISSING_CHAR",
|
|
4759
|
+
const message2 = "Comments must be separated from other tokens by white space characters";
|
|
4760
|
+
onError(token, "MISSING_CHAR", message2);
|
|
4761
4761
|
}
|
|
4762
4762
|
length += token.source.length;
|
|
4763
4763
|
comment = token.source.substring(1);
|
|
@@ -4768,8 +4768,8 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
4768
4768
|
break;
|
|
4769
4769
|
/* istanbul ignore next should not happen */
|
|
4770
4770
|
default: {
|
|
4771
|
-
const
|
|
4772
|
-
onError(token, "UNEXPECTED_TOKEN",
|
|
4771
|
+
const message2 = `Unexpected token in block scalar header: ${token.type}`;
|
|
4772
|
+
onError(token, "UNEXPECTED_TOKEN", message2);
|
|
4773
4773
|
const ts = token.source;
|
|
4774
4774
|
if (ts && typeof ts === "string")
|
|
4775
4775
|
length += ts.length;
|
|
@@ -4901,8 +4901,8 @@ function doubleQuotedValue(source, onError) {
|
|
|
4901
4901
|
if (ch === "\r" && source[i + 1] === "\n")
|
|
4902
4902
|
continue;
|
|
4903
4903
|
if (ch === "\n") {
|
|
4904
|
-
const { fold, offset } = foldNewline(source, i);
|
|
4905
|
-
res +=
|
|
4904
|
+
const { fold: fold2, offset } = foldNewline(source, i);
|
|
4905
|
+
res += fold2;
|
|
4906
4906
|
i = offset;
|
|
4907
4907
|
} else if (ch === "\\") {
|
|
4908
4908
|
let next = source[++i];
|
|
@@ -4942,19 +4942,19 @@ function doubleQuotedValue(source, onError) {
|
|
|
4942
4942
|
return res;
|
|
4943
4943
|
}
|
|
4944
4944
|
function foldNewline(source, offset) {
|
|
4945
|
-
let
|
|
4945
|
+
let fold2 = "";
|
|
4946
4946
|
let ch = source[offset + 1];
|
|
4947
4947
|
while (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
4948
4948
|
if (ch === "\r" && source[offset + 2] !== "\n")
|
|
4949
4949
|
break;
|
|
4950
4950
|
if (ch === "\n")
|
|
4951
|
-
|
|
4951
|
+
fold2 += "\n";
|
|
4952
4952
|
offset += 1;
|
|
4953
4953
|
ch = source[offset + 1];
|
|
4954
4954
|
}
|
|
4955
|
-
if (!
|
|
4956
|
-
|
|
4957
|
-
return { fold, offset };
|
|
4955
|
+
if (!fold2)
|
|
4956
|
+
fold2 = " ";
|
|
4957
|
+
return { fold: fold2, offset };
|
|
4958
4958
|
}
|
|
4959
4959
|
var escapeCodes = {
|
|
4960
4960
|
"0": "\0",
|
|
@@ -5126,13 +5126,13 @@ function composeNode(ctx, token, props, onError) {
|
|
|
5126
5126
|
if (anchor)
|
|
5127
5127
|
node.anchor = anchor.source.substring(1);
|
|
5128
5128
|
} catch (error4) {
|
|
5129
|
-
const
|
|
5130
|
-
onError(token, "RESOURCE_EXHAUSTION",
|
|
5129
|
+
const message2 = error4 instanceof Error ? error4.message : String(error4);
|
|
5130
|
+
onError(token, "RESOURCE_EXHAUSTION", message2);
|
|
5131
5131
|
}
|
|
5132
5132
|
break;
|
|
5133
5133
|
default: {
|
|
5134
|
-
const
|
|
5135
|
-
onError(token, "UNEXPECTED_TOKEN",
|
|
5134
|
+
const message2 = token.type === "error" ? token.message : `Unsupported token (type: ${token.type})`;
|
|
5135
|
+
onError(token, "UNEXPECTED_TOKEN", message2);
|
|
5136
5136
|
isSrcToken = false;
|
|
5137
5137
|
}
|
|
5138
5138
|
}
|
|
@@ -5264,12 +5264,12 @@ var Composer = class {
|
|
|
5264
5264
|
this.prelude = [];
|
|
5265
5265
|
this.errors = [];
|
|
5266
5266
|
this.warnings = [];
|
|
5267
|
-
this.onError = (source, code,
|
|
5267
|
+
this.onError = (source, code, message2, warning2) => {
|
|
5268
5268
|
const pos = getErrorPos(source);
|
|
5269
5269
|
if (warning2)
|
|
5270
|
-
this.warnings.push(new YAMLWarning(pos, code,
|
|
5270
|
+
this.warnings.push(new YAMLWarning(pos, code, message2));
|
|
5271
5271
|
else
|
|
5272
|
-
this.errors.push(new YAMLParseError(pos, code,
|
|
5272
|
+
this.errors.push(new YAMLParseError(pos, code, message2));
|
|
5273
5273
|
};
|
|
5274
5274
|
this.directives = new Directives({ version: options.version || "1.2" });
|
|
5275
5275
|
this.options = options;
|
|
@@ -5337,10 +5337,10 @@ ${cb}` : comment;
|
|
|
5337
5337
|
*next(token) {
|
|
5338
5338
|
switch (token.type) {
|
|
5339
5339
|
case "directive":
|
|
5340
|
-
this.directives.add(token.source, (offset,
|
|
5340
|
+
this.directives.add(token.source, (offset, message2, warning2) => {
|
|
5341
5341
|
const pos = getErrorPos(token);
|
|
5342
5342
|
pos[0] += offset;
|
|
5343
|
-
this.onError(pos, "BAD_DIRECTIVE",
|
|
5343
|
+
this.onError(pos, "BAD_DIRECTIVE", message2, warning2);
|
|
5344
5344
|
});
|
|
5345
5345
|
this.prelude.push(token.source);
|
|
5346
5346
|
this.atDirectives = true;
|
|
@@ -6145,15 +6145,15 @@ var LineCounter = class {
|
|
|
6145
6145
|
};
|
|
6146
6146
|
|
|
6147
6147
|
// node_modules/yaml/browser/dist/parse/parser.js
|
|
6148
|
-
function includesToken(
|
|
6149
|
-
for (let i = 0; i <
|
|
6150
|
-
if (
|
|
6148
|
+
function includesToken(list4, type) {
|
|
6149
|
+
for (let i = 0; i < list4.length; ++i)
|
|
6150
|
+
if (list4[i].type === type)
|
|
6151
6151
|
return true;
|
|
6152
6152
|
return false;
|
|
6153
6153
|
}
|
|
6154
|
-
function findNonEmptyIndex(
|
|
6155
|
-
for (let i = 0; i <
|
|
6156
|
-
switch (
|
|
6154
|
+
function findNonEmptyIndex(list4) {
|
|
6155
|
+
for (let i = 0; i < list4.length; ++i) {
|
|
6156
|
+
switch (list4[i].type) {
|
|
6157
6157
|
case "space":
|
|
6158
6158
|
case "comment":
|
|
6159
6159
|
case "newline":
|
|
@@ -6281,8 +6281,8 @@ var Parser = class {
|
|
|
6281
6281
|
}
|
|
6282
6282
|
const type = tokenType(source);
|
|
6283
6283
|
if (!type) {
|
|
6284
|
-
const
|
|
6285
|
-
yield* this.pop({ type: "error", offset: this.offset, message, source });
|
|
6284
|
+
const message2 = `Not a YAML token: ${source}`;
|
|
6285
|
+
yield* this.pop({ type: "error", offset: this.offset, message: message2, source });
|
|
6286
6286
|
this.offset += source.length;
|
|
6287
6287
|
} else if (type === "scalar") {
|
|
6288
6288
|
this.atNewLine = false;
|
|
@@ -6372,8 +6372,8 @@ var Parser = class {
|
|
|
6372
6372
|
*pop(error4) {
|
|
6373
6373
|
const token = error4 ?? this.stack.pop();
|
|
6374
6374
|
if (!token) {
|
|
6375
|
-
const
|
|
6376
|
-
yield { type: "error", offset: this.offset, source: "", message };
|
|
6375
|
+
const message2 = "Tried to pop an empty stack";
|
|
6376
|
+
yield { type: "error", offset: this.offset, source: "", message: message2 };
|
|
6377
6377
|
} else if (this.stack.length === 0) {
|
|
6378
6378
|
yield token;
|
|
6379
6379
|
} else {
|
|
@@ -14609,22 +14609,22 @@ var MdbaseConnectError = class extends Error {
|
|
|
14609
14609
|
return this.problem.details;
|
|
14610
14610
|
}
|
|
14611
14611
|
};
|
|
14612
|
-
function connectProblem(code,
|
|
14612
|
+
function connectProblem(code, message2, ...[options = {}]) {
|
|
14613
14613
|
const definition = CONNECT_PROBLEM_CATALOG[code];
|
|
14614
14614
|
return {
|
|
14615
14615
|
problem_version: CONNECT_PROBLEM_VERSION,
|
|
14616
14616
|
code,
|
|
14617
14617
|
category: definition.category,
|
|
14618
14618
|
recovery: definition.recovery,
|
|
14619
|
-
message,
|
|
14619
|
+
message: message2,
|
|
14620
14620
|
...options.details === void 0 ? {} : { details: options.details },
|
|
14621
14621
|
...options.operationOutcome === void 0 ? {} : { operation_outcome: options.operationOutcome },
|
|
14622
14622
|
...options.traceId === void 0 ? {} : { trace_id: options.traceId }
|
|
14623
14623
|
};
|
|
14624
14624
|
}
|
|
14625
|
-
function connectError(code,
|
|
14625
|
+
function connectError(code, message2, ...args) {
|
|
14626
14626
|
const options = args[0];
|
|
14627
|
-
return new MdbaseConnectError(connectProblem(code,
|
|
14627
|
+
return new MdbaseConnectError(connectProblem(code, message2, ...args), {
|
|
14628
14628
|
status: options?.status,
|
|
14629
14629
|
cause: options?.cause
|
|
14630
14630
|
});
|
|
@@ -14656,9 +14656,9 @@ function semanticContractVersion(requirements) {
|
|
|
14656
14656
|
invalidAuthorizationSelection("Unsupported declared capability contract version.");
|
|
14657
14657
|
return version3;
|
|
14658
14658
|
}
|
|
14659
|
-
function invalidAuthorizationSelection(
|
|
14660
|
-
throw connectError("invalid_application_manifest",
|
|
14661
|
-
details: { issues: [{ path: "/requirements/capabilities", keyword: "authorizationSelection", message, params: {} }] }
|
|
14659
|
+
function invalidAuthorizationSelection(message2) {
|
|
14660
|
+
throw connectError("invalid_application_manifest", message2, {
|
|
14661
|
+
details: { issues: [{ path: "/requirements/capabilities", keyword: "authorizationSelection", message: message2, params: {} }] }
|
|
14662
14662
|
});
|
|
14663
14663
|
}
|
|
14664
14664
|
function validateAuthorizationSelection(requirements, options) {
|
|
@@ -15407,8 +15407,8 @@ function isLoopback(hostname) {
|
|
|
15407
15407
|
function invalid(issues) {
|
|
15408
15408
|
return { valid: false, issues };
|
|
15409
15409
|
}
|
|
15410
|
-
function issue(path, keyword,
|
|
15411
|
-
return { path, keyword, message, params: params2 };
|
|
15410
|
+
function issue(path, keyword, message2, params2 = {}) {
|
|
15411
|
+
return { path, keyword, message: message2, params: params2 };
|
|
15412
15412
|
}
|
|
15413
15413
|
function asObject(value2) {
|
|
15414
15414
|
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2) ? value2 : {};
|
|
@@ -15528,6 +15528,7 @@ var MdbaseError = class extends Error {
|
|
|
15528
15528
|
code;
|
|
15529
15529
|
recovery;
|
|
15530
15530
|
reason;
|
|
15531
|
+
/** Plain JSON, whatever the problem carries. Read one field with a narrowing check. */
|
|
15531
15532
|
details;
|
|
15532
15533
|
retryAfterMs;
|
|
15533
15534
|
issues;
|
|
@@ -15539,8 +15540,6 @@ var MdbaseError = class extends Error {
|
|
|
15539
15540
|
* dry runs, which capture nothing. Not part of {@link toProblem}.
|
|
15540
15541
|
*/
|
|
15541
15542
|
mutationId;
|
|
15542
|
-
/** Every original mutation of a failed partial batch, in op order. */
|
|
15543
|
-
mutationIds;
|
|
15544
15543
|
constructor(problem4, context = {}) {
|
|
15545
15544
|
super(problem4.message, context.cause === void 0 ? void 0 : { cause: context.cause });
|
|
15546
15545
|
this.name = "MdbaseError";
|
|
@@ -15551,10 +15550,7 @@ var MdbaseError = class extends Error {
|
|
|
15551
15550
|
if (problem4.retryAfterMs !== void 0) this.retryAfterMs = problem4.retryAfterMs;
|
|
15552
15551
|
if (problem4.issues !== void 0) this.issues = problem4.issues;
|
|
15553
15552
|
if (problem4.traceId !== void 0) this.traceId = problem4.traceId;
|
|
15554
|
-
|
|
15555
|
-
const id4 = context.mutationId ?? ids?.[0];
|
|
15556
|
-
if (id4 !== void 0) this.mutationId = id4;
|
|
15557
|
-
if (ids !== void 0) this.mutationIds = ids;
|
|
15553
|
+
if (context.mutationId !== void 0) this.mutationId = context.mutationId;
|
|
15558
15554
|
}
|
|
15559
15555
|
toProblem() {
|
|
15560
15556
|
const p = { code: this.code, recovery: this.recovery, message: this.message };
|
|
@@ -15566,9 +15562,9 @@ var MdbaseError = class extends Error {
|
|
|
15566
15562
|
return p;
|
|
15567
15563
|
}
|
|
15568
15564
|
};
|
|
15569
|
-
function mdbaseError(code,
|
|
15565
|
+
function mdbaseError(code, message2, extra = {}) {
|
|
15570
15566
|
const more = typeof extra === "string" ? { reason: extra } : extra;
|
|
15571
|
-
return new MdbaseError({ code, recovery: ERROR_CODES[code], message, ...more });
|
|
15567
|
+
return new MdbaseError({ code, recovery: ERROR_CODES[code], message: message2, ...more });
|
|
15572
15568
|
}
|
|
15573
15569
|
function isMdbaseError(e, code) {
|
|
15574
15570
|
return e instanceof MdbaseError && (code === void 0 || e.code === code);
|
|
@@ -15862,8 +15858,8 @@ var Float64 = class {
|
|
|
15862
15858
|
};
|
|
15863
15859
|
var MAX_DEPTH = 128;
|
|
15864
15860
|
var CborError = class extends Error {
|
|
15865
|
-
constructor(kind,
|
|
15866
|
-
super(
|
|
15861
|
+
constructor(kind, message2) {
|
|
15862
|
+
super(message2 ?? kind);
|
|
15867
15863
|
this.kind = kind;
|
|
15868
15864
|
this.name = "CborError";
|
|
15869
15865
|
}
|
|
@@ -16229,17 +16225,64 @@ function bytesEqual(a, b) {
|
|
|
16229
16225
|
return true;
|
|
16230
16226
|
}
|
|
16231
16227
|
|
|
16228
|
+
// src/plain.ts
|
|
16229
|
+
function toPlain(v) {
|
|
16230
|
+
if (v === null || typeof v === "boolean" || typeof v === "number" || typeof v === "string") return v;
|
|
16231
|
+
if (typeof v === "bigint") return v.toString();
|
|
16232
|
+
if (v instanceof Float64) return v.value;
|
|
16233
|
+
if (v instanceof Uint8Array) return toHex(v);
|
|
16234
|
+
if (Array.isArray(v)) return v.map(toPlain);
|
|
16235
|
+
return Object.fromEntries([...v].map(([k, x]) => [String(k), toPlain(x)]));
|
|
16236
|
+
}
|
|
16237
|
+
function fieldOf(value2, key3) {
|
|
16238
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2) && Object.hasOwn(value2, key3) ? value2[key3] : void 0;
|
|
16239
|
+
}
|
|
16240
|
+
function toValue(v) {
|
|
16241
|
+
if (v === void 0 || v === null) return null;
|
|
16242
|
+
if (typeof v !== "object") return v;
|
|
16243
|
+
if (v instanceof Float64) return v;
|
|
16244
|
+
if (Array.isArray(v)) return v.map(toValue);
|
|
16245
|
+
if (v instanceof Map) {
|
|
16246
|
+
const m3 = /* @__PURE__ */ new Map();
|
|
16247
|
+
for (const [k, x] of v) m3.set(k, toValue(x));
|
|
16248
|
+
return m3;
|
|
16249
|
+
}
|
|
16250
|
+
if (v instanceof Date) return v.toISOString();
|
|
16251
|
+
const m2 = /* @__PURE__ */ new Map();
|
|
16252
|
+
for (const [k, x] of Object.entries(v)) if (x !== void 0) m2.set(k, toValue(x));
|
|
16253
|
+
return m2;
|
|
16254
|
+
}
|
|
16255
|
+
|
|
16232
16256
|
// src/codec.ts
|
|
16233
16257
|
var SchemaError = class extends Error {
|
|
16234
|
-
constructor(ty,
|
|
16235
|
-
super(`${ty}: ${
|
|
16258
|
+
constructor(ty, message2, unknown2 = false) {
|
|
16259
|
+
super(`${ty}: ${message2}`);
|
|
16236
16260
|
this.ty = ty;
|
|
16237
|
-
this.unknown =
|
|
16261
|
+
this.unknown = unknown2;
|
|
16238
16262
|
this.name = "SchemaError";
|
|
16239
16263
|
}
|
|
16240
16264
|
ty;
|
|
16241
16265
|
unknown;
|
|
16242
16266
|
};
|
|
16267
|
+
var plainMode = false;
|
|
16268
|
+
function decodePlain(codec, c) {
|
|
16269
|
+
const was = plainMode;
|
|
16270
|
+
plainMode = true;
|
|
16271
|
+
try {
|
|
16272
|
+
return codec.dec(c);
|
|
16273
|
+
} finally {
|
|
16274
|
+
plainMode = was;
|
|
16275
|
+
}
|
|
16276
|
+
}
|
|
16277
|
+
function plainAnswer(codec) {
|
|
16278
|
+
return {
|
|
16279
|
+
name: codec.name,
|
|
16280
|
+
enc: () => {
|
|
16281
|
+
throw new SchemaError(codec.name, "an answer is decoded, never encoded");
|
|
16282
|
+
},
|
|
16283
|
+
dec: (c) => decodePlain(codec, c)
|
|
16284
|
+
};
|
|
16285
|
+
}
|
|
16243
16286
|
function kindOf(c) {
|
|
16244
16287
|
if (c === null) return "null";
|
|
16245
16288
|
if (c instanceof Uint8Array) return "bytes";
|
|
@@ -16354,7 +16397,15 @@ var value = {
|
|
|
16354
16397
|
},
|
|
16355
16398
|
dec: (c) => {
|
|
16356
16399
|
checkValue(c);
|
|
16357
|
-
return c;
|
|
16400
|
+
return plainMode ? toPlain(c) : c;
|
|
16401
|
+
}
|
|
16402
|
+
};
|
|
16403
|
+
var json2 = {
|
|
16404
|
+
name: "value",
|
|
16405
|
+
enc: (v) => value.enc(toValue(v)),
|
|
16406
|
+
dec: (c) => {
|
|
16407
|
+
checkValue(c);
|
|
16408
|
+
return toPlain(c);
|
|
16358
16409
|
}
|
|
16359
16410
|
};
|
|
16360
16411
|
function checkValue(c, depth = 0) {
|
|
@@ -16404,7 +16455,7 @@ function dataMap(item) {
|
|
|
16404
16455
|
if (typeof k !== "string") throw new SchemaError(name2, "data map keys must be text");
|
|
16405
16456
|
m2.set(k, item.dec(x));
|
|
16406
16457
|
}
|
|
16407
|
-
return m2;
|
|
16458
|
+
return plainMode ? Object.fromEntries(m2) : m2;
|
|
16408
16459
|
}
|
|
16409
16460
|
};
|
|
16410
16461
|
}
|
|
@@ -16652,15 +16703,15 @@ function acquireNamedLease(locks, name2, signal) {
|
|
|
16652
16703
|
acquiredResolve = resolve;
|
|
16653
16704
|
acquiredReject = reject;
|
|
16654
16705
|
});
|
|
16655
|
-
let
|
|
16706
|
+
let cancelled3 = false;
|
|
16656
16707
|
const onAbort = () => {
|
|
16657
|
-
|
|
16708
|
+
cancelled3 = true;
|
|
16658
16709
|
acquiredReject(new AppReplicaOwnerError("aborted"));
|
|
16659
16710
|
};
|
|
16660
16711
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
16661
16712
|
const request3 = Promise.resolve().then(() => locks.request(name2, { mode: "exclusive", ifAvailable: true }, async (lock) => {
|
|
16662
16713
|
signal?.removeEventListener("abort", onAbort);
|
|
16663
|
-
if (
|
|
16714
|
+
if (cancelled3 || signal?.aborted) {
|
|
16664
16715
|
acquiredReject(new AppReplicaOwnerError("aborted"));
|
|
16665
16716
|
return;
|
|
16666
16717
|
}
|
|
@@ -17076,8 +17127,8 @@ var nonOkResponses = /* @__PURE__ */ new WeakSet();
|
|
|
17076
17127
|
var privateDeviceFieldRefused = /* @__PURE__ */ new WeakSet();
|
|
17077
17128
|
function unknownPrivateDeviceField(status, error4) {
|
|
17078
17129
|
if (status !== 400 || !error4 || typeof error4 !== "object" || Array.isArray(error4)) return false;
|
|
17079
|
-
const { code, message } = error4;
|
|
17080
|
-
return code === "invalid_request" && typeof
|
|
17130
|
+
const { code, message: message2 } = error4;
|
|
17131
|
+
return code === "invalid_request" && typeof message2 === "string" && message2.length <= 512 && /unrecognized key/i.test(message2) && message2.includes("requested_private_device");
|
|
17081
17132
|
}
|
|
17082
17133
|
var hex = (b) => Array.from(b, (v) => v.toString(16).padStart(2, "0")).join("");
|
|
17083
17134
|
var UUID3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
@@ -19776,34 +19827,9 @@ function waitForOpenRetry(milliseconds, signal) {
|
|
|
19776
19827
|
}
|
|
19777
19828
|
|
|
19778
19829
|
// src/values.ts
|
|
19779
|
-
function toValue(v) {
|
|
19780
|
-
if (v === void 0 || v === null) return null;
|
|
19781
|
-
if (typeof v !== "object") return v;
|
|
19782
|
-
if (v instanceof Float64) return v;
|
|
19783
|
-
if (Array.isArray(v)) return v.map(toValue);
|
|
19784
|
-
if (v instanceof Map) {
|
|
19785
|
-
const m3 = /* @__PURE__ */ new Map();
|
|
19786
|
-
for (const [k, x] of v) m3.set(k, toValue(x));
|
|
19787
|
-
return m3;
|
|
19788
|
-
}
|
|
19789
|
-
if (v instanceof Date) return v.toISOString();
|
|
19790
|
-
const m2 = /* @__PURE__ */ new Map();
|
|
19791
|
-
for (const [k, x] of Object.entries(v)) if (x !== void 0) m2.set(k, toValue(x));
|
|
19792
|
-
return m2;
|
|
19793
|
-
}
|
|
19794
19830
|
function toFmMap(v) {
|
|
19795
19831
|
return toValue(v);
|
|
19796
19832
|
}
|
|
19797
|
-
function toPlain(v) {
|
|
19798
|
-
if (v === null || typeof v === "boolean" || typeof v === "number" || typeof v === "string") return v;
|
|
19799
|
-
if (typeof v === "bigint") return v.toString();
|
|
19800
|
-
if (v instanceof Float64) return v.value;
|
|
19801
|
-
if (v instanceof Uint8Array) return toHex(v);
|
|
19802
|
-
if (Array.isArray(v)) return v.map(toPlain);
|
|
19803
|
-
const o = {};
|
|
19804
|
-
for (const [k, x] of v) o[String(k)] = toPlain(x);
|
|
19805
|
-
return o;
|
|
19806
|
-
}
|
|
19807
19833
|
function valueEquals(a, b) {
|
|
19808
19834
|
if (a === b) return true;
|
|
19809
19835
|
if (a instanceof Float64 && b instanceof Float64) return Object.is(a.value, b.value) || a.value === b.value;
|
|
@@ -19984,14 +20010,14 @@ var issue2 = struct("issue", [
|
|
|
19984
20010
|
[0, "code", tstr],
|
|
19985
20011
|
[1, "severity", severity],
|
|
19986
20012
|
[2, "message", tstr],
|
|
19987
|
-
[3, "details",
|
|
20013
|
+
[3, "details", json2, "opt"]
|
|
19988
20014
|
]);
|
|
19989
20015
|
var problem = struct("problem", [
|
|
19990
20016
|
[0, "code", tstr],
|
|
19991
20017
|
[1, "recovery", recovery],
|
|
19992
20018
|
[2, "message", tstr],
|
|
19993
20019
|
[3, "reason", tstr, "opt"],
|
|
19994
|
-
[4, "details",
|
|
20020
|
+
[4, "details", json2, "opt"],
|
|
19995
20021
|
[5, "retryAfterMs", uint, "opt"],
|
|
19996
20022
|
[6, "issues", list(issue2), "opt"],
|
|
19997
20023
|
[7, "traceId", tstr, "opt"]
|
|
@@ -20057,7 +20083,7 @@ var INCIDENT_KINDS = [
|
|
|
20057
20083
|
];
|
|
20058
20084
|
var incident = struct("incident", [
|
|
20059
20085
|
[0, "kind", enumOf("incident-kind", INCIDENT_KINDS)],
|
|
20060
|
-
[1, "details",
|
|
20086
|
+
[1, "details", json2, "opt"]
|
|
20061
20087
|
]);
|
|
20062
20088
|
var progress = struct("progress", [
|
|
20063
20089
|
[0, "done", uint],
|
|
@@ -20901,7 +20927,7 @@ var TEXT_MAX = 4096;
|
|
|
20901
20927
|
var ITEMS_MAX = 4096;
|
|
20902
20928
|
var ROWS_MAX = 65536;
|
|
20903
20929
|
var utf82 = new TextEncoder();
|
|
20904
|
-
var bad2 = (
|
|
20930
|
+
var bad2 = (message2, unknown2 = false) => new SchemaError("app-bases-v1", message2, unknown2);
|
|
20905
20931
|
function text2(c, max = TEXT_MAX) {
|
|
20906
20932
|
if (typeof c !== "string" || utf82.encode(c).length > max) throw bad2("bounded text required");
|
|
20907
20933
|
return c;
|
|
@@ -21257,7 +21283,7 @@ var validationIssue2 = struct("validation-issue", [
|
|
|
21257
21283
|
[0, "code", tstr],
|
|
21258
21284
|
[1, "severity", severity],
|
|
21259
21285
|
[2, "message", tstr],
|
|
21260
|
-
[3, "details",
|
|
21286
|
+
[3, "details", json2, "opt"],
|
|
21261
21287
|
[4, "location", tstr, "opt"],
|
|
21262
21288
|
[5, "typeName", tstr, "opt"],
|
|
21263
21289
|
[6, "tier", tier]
|
|
@@ -21269,7 +21295,7 @@ var row = struct("record-validation", [
|
|
|
21269
21295
|
[3, "revision", hash]
|
|
21270
21296
|
]);
|
|
21271
21297
|
var rows = list(row);
|
|
21272
|
-
var invalid3 = (
|
|
21298
|
+
var invalid3 = (message2) => new SchemaError("record-validations", message2);
|
|
21273
21299
|
var recordValidations = {
|
|
21274
21300
|
name: "record-validations",
|
|
21275
21301
|
enc: (v) => rows.enc(v),
|
|
@@ -21805,12 +21831,12 @@ var FilesApi = class {
|
|
|
21805
21831
|
if (version3.major !== 1 || version3.minor < 2) {
|
|
21806
21832
|
throw mdbaseError("upgrade_required", "this replica's change feed does not name files", "change_entity_unsupported");
|
|
21807
21833
|
}
|
|
21808
|
-
return this.client.watchChanges(
|
|
21834
|
+
return this.client.watchChanges((batch) => {
|
|
21809
21835
|
const changes = batch.changes.filter((c) => c.entity === "file" || c.entity === void 0 && c.kind === "remove");
|
|
21810
21836
|
const unclassified = batch.changes.some((c) => c.entity === void 0 && c.kind === "put");
|
|
21811
21837
|
if (unclassified) onChanges({ changes: [], cursor: batch.cursor, reset: true });
|
|
21812
21838
|
else if (changes.length || batch.reset) onChanges({ changes, cursor: batch.cursor, reset: batch.reset });
|
|
21813
|
-
});
|
|
21839
|
+
}, options);
|
|
21814
21840
|
}
|
|
21815
21841
|
wire(s) {
|
|
21816
21842
|
if (this.wired.has(s)) return;
|
|
@@ -21857,7 +21883,7 @@ var FilesApi = class {
|
|
|
21857
21883
|
});
|
|
21858
21884
|
}
|
|
21859
21885
|
async session(signal, read = false) {
|
|
21860
|
-
const s = await (read ? this.client.readyForRead(signal) : this.client.ready(signal));
|
|
21886
|
+
const s = await (read ? this.client.readyForRead(signal) : this.client.ready({ signal }));
|
|
21861
21887
|
this.wire(s);
|
|
21862
21888
|
return s;
|
|
21863
21889
|
}
|
|
@@ -21888,11 +21914,12 @@ var FilesApi = class {
|
|
|
21888
21914
|
cursor = page.cursor;
|
|
21889
21915
|
}
|
|
21890
21916
|
}
|
|
21891
|
-
|
|
21917
|
+
/** One file's handle by ID or path. `o.signal` cancels the read. */
|
|
21918
|
+
get(f, o = {}) {
|
|
21892
21919
|
return this.client.call("get_file", m([[0, fileRef(f)]]), {
|
|
21893
21920
|
codec: fileView,
|
|
21894
21921
|
retry: true,
|
|
21895
|
-
...signal ? { signal } : {}
|
|
21922
|
+
...o.signal ? { signal: o.signal } : {}
|
|
21896
21923
|
});
|
|
21897
21924
|
}
|
|
21898
21925
|
/**
|
|
@@ -21973,7 +22000,7 @@ var FilesApi = class {
|
|
|
21973
22000
|
}
|
|
21974
22001
|
await Promise.all(inflight);
|
|
21975
22002
|
const r = await s.request("commit_upload", m([[0, uuid2.enc(open2.transfer)]]), {
|
|
21976
|
-
codec: receipt,
|
|
22003
|
+
codec: plainAnswer(receipt),
|
|
21977
22004
|
...sig
|
|
21978
22005
|
});
|
|
21979
22006
|
const w = Object.assign(this.client._track(r), { fileId: opened.fileId });
|
|
@@ -22011,7 +22038,7 @@ var FilesApi = class {
|
|
|
22011
22038
|
const self = this;
|
|
22012
22039
|
const pending = new AbortController();
|
|
22013
22040
|
const cancelledError = mdbaseError("cancelled", "file download cancelled");
|
|
22014
|
-
let
|
|
22041
|
+
let cancelled3 = false;
|
|
22015
22042
|
let finished = false;
|
|
22016
22043
|
let cancelSent = false;
|
|
22017
22044
|
let detachAbort = () => {
|
|
@@ -22028,7 +22055,7 @@ var FilesApi = class {
|
|
|
22028
22055
|
};
|
|
22029
22056
|
const cancel = () => {
|
|
22030
22057
|
if (finished) return;
|
|
22031
|
-
|
|
22058
|
+
cancelled3 = true;
|
|
22032
22059
|
detachAbort();
|
|
22033
22060
|
fileReject(cancelledError);
|
|
22034
22061
|
pending.abort();
|
|
@@ -22037,7 +22064,7 @@ var FilesApi = class {
|
|
|
22037
22064
|
const stream = new ReadableStream({
|
|
22038
22065
|
async start(ctrl) {
|
|
22039
22066
|
const onAbort = () => {
|
|
22040
|
-
if (finished ||
|
|
22067
|
+
if (finished || cancelled3) return;
|
|
22041
22068
|
cancel();
|
|
22042
22069
|
ctrl.error(cancelledError);
|
|
22043
22070
|
};
|
|
@@ -22049,7 +22076,7 @@ var FilesApi = class {
|
|
|
22049
22076
|
}
|
|
22050
22077
|
try {
|
|
22051
22078
|
session = await self.session(pending.signal, true);
|
|
22052
|
-
if (
|
|
22079
|
+
if (cancelled3) return;
|
|
22053
22080
|
const p = m([[0, fileRef(f)]]);
|
|
22054
22081
|
if (o.range) p.set(1, [o.range[0], o.range[1]]);
|
|
22055
22082
|
if (o.revision) p.set(2, hash.enc(o.revision));
|
|
@@ -22080,7 +22107,7 @@ var FilesApi = class {
|
|
|
22080
22107
|
self.early.clear();
|
|
22081
22108
|
self.earlyFailures.clear();
|
|
22082
22109
|
}
|
|
22083
|
-
if (
|
|
22110
|
+
if (cancelled3) {
|
|
22084
22111
|
cancelRemote();
|
|
22085
22112
|
finished = true;
|
|
22086
22113
|
return;
|
|
@@ -22089,14 +22116,14 @@ var FilesApi = class {
|
|
|
22089
22116
|
fileResolve(view);
|
|
22090
22117
|
total = o.range ? o.range[1] : view.size;
|
|
22091
22118
|
const deliver = (c) => {
|
|
22092
|
-
if (
|
|
22119
|
+
if (cancelled3 || finished) return;
|
|
22093
22120
|
ctrl.enqueue(c.bytes);
|
|
22094
22121
|
received += c.bytes.length;
|
|
22095
22122
|
o.onProgress?.({ id: streamId, phase: "streaming", done: received, total });
|
|
22096
|
-
if (
|
|
22123
|
+
if (cancelled3 || finished) return;
|
|
22097
22124
|
void session.request("ack_chunks", m([[0, streamId], [1, c.offset + c.bytes.length]])).catch(() => {
|
|
22098
22125
|
});
|
|
22099
|
-
if (c.last && !
|
|
22126
|
+
if (c.last && !cancelled3 && !finished) {
|
|
22100
22127
|
finished = true;
|
|
22101
22128
|
detachAbort();
|
|
22102
22129
|
self.streams.delete(streamId);
|
|
@@ -22138,10 +22165,10 @@ var FilesApi = class {
|
|
|
22138
22165
|
* `downloadStream`). Includes canonical unindexed Markdown Blob sources;
|
|
22139
22166
|
* ordinary Blob support and AttachmentV1 behavior are unchanged. */
|
|
22140
22167
|
async download(f, o = {}) {
|
|
22141
|
-
const view = typeof f === "object" && "size" in f ? f : await this.get(f, o
|
|
22168
|
+
const view = typeof f === "object" && "size" in f ? f : await this.get(f, o);
|
|
22142
22169
|
if (view.size > MAX_CONVENIENCE_BYTES) {
|
|
22143
22170
|
throw mdbaseError("too_large", `file is ${view.size} bytes; use downloadStream`, {
|
|
22144
|
-
details:
|
|
22171
|
+
details: { limit: MAX_CONVENIENCE_BYTES }
|
|
22145
22172
|
});
|
|
22146
22173
|
}
|
|
22147
22174
|
const out = new Uint8Array(view.size);
|
|
@@ -22155,9 +22182,9 @@ var FilesApi = class {
|
|
|
22155
22182
|
}
|
|
22156
22183
|
return out.subarray(0, off);
|
|
22157
22184
|
}
|
|
22158
|
-
/** Materialize a remote file on this device. */
|
|
22159
|
-
fetch(f,
|
|
22160
|
-
return this.client.call("fetch_file", m([[0, uuid2.enc(fileId(f))]]), { retry: true, ...signal ? { signal } : {} }).then(() => {
|
|
22185
|
+
/** Materialize a remote file on this device. `o.signal` cancels the request. */
|
|
22186
|
+
fetch(f, o = {}) {
|
|
22187
|
+
return this.client.call("fetch_file", m([[0, uuid2.enc(fileId(f))]]), { retry: true, ...o.signal ? { signal: o.signal } : {} }).then(() => {
|
|
22161
22188
|
});
|
|
22162
22189
|
}
|
|
22163
22190
|
/** Drop the local copy of a confirmed, unheld file (hosting app only). */
|
|
@@ -22176,8 +22203,7 @@ var FilesApi = class {
|
|
|
22176
22203
|
async move(f, to, o = {}) {
|
|
22177
22204
|
gates.get(this)?.check("move");
|
|
22178
22205
|
const op2 = { kind: "file_move", id: f.id, from: f.path, to, updateRefs: o.updateRefs ?? true };
|
|
22179
|
-
|
|
22180
|
-
return w;
|
|
22206
|
+
return this.client.submit([o.ifRevision ? { ...op2, ifRevision: o.ifRevision } : op2], o);
|
|
22181
22207
|
}
|
|
22182
22208
|
/** Delete a file. With a FileView, a concurrent replacement supersedes the delete. */
|
|
22183
22209
|
async delete(f, o = {}) {
|
|
@@ -22185,17 +22211,114 @@ var FilesApi = class {
|
|
|
22185
22211
|
const op2 = { kind: "file_delete", id: fileId(f) };
|
|
22186
22212
|
if (typeof f === "object" && "digest" in f) op2.base = f.digest;
|
|
22187
22213
|
if (o.ifRevision) op2.ifRevision = o.ifRevision;
|
|
22188
|
-
|
|
22189
|
-
return w;
|
|
22214
|
+
return this.client.submit([op2], o);
|
|
22190
22215
|
}
|
|
22191
22216
|
};
|
|
22192
22217
|
|
|
22218
|
+
// src/settle.ts
|
|
22219
|
+
var DEFAULT_WAIT_MS = 3e3;
|
|
22220
|
+
var cancelled = (e) => isMdbaseError(e, "cancelled");
|
|
22221
|
+
var message = (e) => e instanceof Error ? e.message : String(e);
|
|
22222
|
+
function unknown(mutationId, reason, text6, receipt3) {
|
|
22223
|
+
const problem4 = { code: "outcome_unknown", recovery: "resolve_outcome", reason, message: text6 };
|
|
22224
|
+
return Object.freeze({ outcome: "unknown", mutationId, ...receipt3 ? { receipt: receipt3 } : {}, problem: problem4 });
|
|
22225
|
+
}
|
|
22226
|
+
async function settleWrite(client, input, options = {}) {
|
|
22227
|
+
const signal = options.signal;
|
|
22228
|
+
let write;
|
|
22229
|
+
let mutationId;
|
|
22230
|
+
let receipt3;
|
|
22231
|
+
if (typeof input === "string") {
|
|
22232
|
+
mutationId = input;
|
|
22233
|
+
try {
|
|
22234
|
+
receipt3 = await client.receipt(mutationId, { signal });
|
|
22235
|
+
} catch (e) {
|
|
22236
|
+
if (cancelled(e)) throw e;
|
|
22237
|
+
if (isMdbaseError(e, "not_found")) return Object.freeze({ outcome: "rejected", mutationId, problem: e.toProblem() });
|
|
22238
|
+
return unknown(mutationId, "receipt_unavailable", `The write's result could not be read: ${message(e)}`);
|
|
22239
|
+
}
|
|
22240
|
+
} else {
|
|
22241
|
+
try {
|
|
22242
|
+
write = await input;
|
|
22243
|
+
mutationId = write.mutationId;
|
|
22244
|
+
receipt3 = write.receipt;
|
|
22245
|
+
} catch (e) {
|
|
22246
|
+
if (!(e instanceof MdbaseError) || cancelled(e)) throw e;
|
|
22247
|
+
if (e.mutationId === void 0) return Object.freeze({ outcome: "rejected", problem: e.toProblem() });
|
|
22248
|
+
mutationId = e.mutationId;
|
|
22249
|
+
try {
|
|
22250
|
+
receipt3 = await client.receipt(mutationId, { signal });
|
|
22251
|
+
} catch (lookup) {
|
|
22252
|
+
if (cancelled(lookup)) throw lookup;
|
|
22253
|
+
if (isMdbaseError(lookup, "not_found")) return Object.freeze({ outcome: "rejected", mutationId, problem: e.toProblem() });
|
|
22254
|
+
return unknown(mutationId, "receipt_unavailable", `The write may have been saved: ${e.message}`);
|
|
22255
|
+
}
|
|
22256
|
+
}
|
|
22257
|
+
}
|
|
22258
|
+
if (receipt3.state === "pending") {
|
|
22259
|
+
try {
|
|
22260
|
+
receipt3 = await client.awaitReceipt(mutationId, { timeoutMs: options.timeoutMs ?? DEFAULT_WAIT_MS, signal });
|
|
22261
|
+
write?.update(receipt3);
|
|
22262
|
+
} catch (e) {
|
|
22263
|
+
if (cancelled(e)) throw e;
|
|
22264
|
+
receipt3 = write?.receipt ?? receipt3;
|
|
22265
|
+
}
|
|
22266
|
+
}
|
|
22267
|
+
if (receipt3.mutation !== mutationId) {
|
|
22268
|
+
throw new MdbaseError(
|
|
22269
|
+
{ code: "internal", recovery: "contact_support", message: "the replica answered with another mutation's receipt" },
|
|
22270
|
+
{ mutationId }
|
|
22271
|
+
);
|
|
22272
|
+
}
|
|
22273
|
+
if (receipt3.state === "unknown") {
|
|
22274
|
+
const problem4 = receipt3.problem ?? { code: "outcome_unknown", recovery: "resolve_outcome", message: "The write's result is not known." };
|
|
22275
|
+
return Object.freeze({ outcome: "unknown", mutationId, receipt: receipt3, problem: problem4 });
|
|
22276
|
+
}
|
|
22277
|
+
if (receipt3.state === "rejected") {
|
|
22278
|
+
const problem4 = receipt3.problem ?? { code: "internal", recovery: "contact_support", message: "The write was rejected without a reason." };
|
|
22279
|
+
return Object.freeze({ outcome: "rejected", mutationId, receipt: receipt3, problem: problem4 });
|
|
22280
|
+
}
|
|
22281
|
+
let read;
|
|
22282
|
+
if (options.read) {
|
|
22283
|
+
const how = options.read === true ? {} : options.read;
|
|
22284
|
+
const named = receipt3.records?.length === 1 ? receipt3.records[0].id : void 0;
|
|
22285
|
+
const ref = how.record ?? write?.recordId ?? named;
|
|
22286
|
+
if (ref === void 0) {
|
|
22287
|
+
throw new MdbaseError(
|
|
22288
|
+
{ code: "invalid_request", recovery: "fix_request", message: "settle cannot tell which record to read back; pass read.record" },
|
|
22289
|
+
{ mutationId }
|
|
22290
|
+
);
|
|
22291
|
+
}
|
|
22292
|
+
try {
|
|
22293
|
+
read = await readBack(client, ref, how, signal);
|
|
22294
|
+
} catch (e) {
|
|
22295
|
+
if (cancelled(e)) throw e;
|
|
22296
|
+
return unknown(mutationId, "readback_failed", `The write was kept, but the record could not be read back: ${message(e)}`, receipt3);
|
|
22297
|
+
}
|
|
22298
|
+
}
|
|
22299
|
+
const kept = { mutationId, receipt: receipt3, ...read };
|
|
22300
|
+
if (receipt3.state === "pending") return Object.freeze({ outcome: "saved_on_device", ...kept });
|
|
22301
|
+
if (receipt3.status === "conflicted") return Object.freeze({ outcome: "conflicted", ...kept, conflicts: Object.freeze([...receipt3.conflicts ?? []]) });
|
|
22302
|
+
return Object.freeze({ outcome: "confirmed", ...kept });
|
|
22303
|
+
}
|
|
22304
|
+
async function readBack(client, ref, how, signal) {
|
|
22305
|
+
let record3;
|
|
22306
|
+
try {
|
|
22307
|
+
record3 = await client.get(ref, { include: how.include, signal });
|
|
22308
|
+
} catch (e) {
|
|
22309
|
+
if (!isMdbaseError(e, "not_found")) throw e;
|
|
22310
|
+
return how.contract ? { record: null, contractRecord: null } : { record: null };
|
|
22311
|
+
}
|
|
22312
|
+
return how.contract ? { record: record3, contractRecord: await client.getContract(record3, how.contract, { signal }) } : { record: record3 };
|
|
22313
|
+
}
|
|
22314
|
+
|
|
22193
22315
|
// src/read-helpers.ts
|
|
22194
22316
|
var READ_MANY_MAX_REFS = 1e3;
|
|
22195
22317
|
var READ_MANY_MAX_CONCURRENCY = 16;
|
|
22196
|
-
async function readMany(client, refs,
|
|
22318
|
+
async function readMany(client, refs, o = {}) {
|
|
22319
|
+
const { include: include3, signal } = o;
|
|
22197
22320
|
signal?.throwIfAborted();
|
|
22198
|
-
const concurrency =
|
|
22321
|
+
const concurrency = o.concurrency ?? 8;
|
|
22199
22322
|
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > READ_MANY_MAX_CONCURRENCY) {
|
|
22200
22323
|
throw mdbaseError(
|
|
22201
22324
|
"invalid_request",
|
|
@@ -22212,6 +22335,10 @@ async function readMany(client, refs, include3, signal, options = {}) {
|
|
|
22212
22335
|
}
|
|
22213
22336
|
const selections2 = Array.from(refs, capture);
|
|
22214
22337
|
const capturedInclude = include3 ? Object.freeze({ ...include3 }) : void 0;
|
|
22338
|
+
const read = {
|
|
22339
|
+
...capturedInclude ? { include: capturedInclude } : {},
|
|
22340
|
+
...signal ? { signal } : {}
|
|
22341
|
+
};
|
|
22215
22342
|
const records2 = new Array(selections2.length);
|
|
22216
22343
|
let next = 0, failed = false, failure2;
|
|
22217
22344
|
async function worker() {
|
|
@@ -22219,11 +22346,7 @@ async function readMany(client, refs, include3, signal, options = {}) {
|
|
|
22219
22346
|
try {
|
|
22220
22347
|
signal?.throwIfAborted();
|
|
22221
22348
|
const index = next++, selected = selections2[index];
|
|
22222
|
-
const record3 = await client.get(
|
|
22223
|
-
selected,
|
|
22224
|
-
capturedInclude,
|
|
22225
|
-
signal
|
|
22226
|
-
);
|
|
22349
|
+
const record3 = await client.get(selected, read);
|
|
22227
22350
|
signal?.throwIfAborted();
|
|
22228
22351
|
if (failed) return;
|
|
22229
22352
|
if (typeof selected === "string" && record3.id !== selected) {
|
|
@@ -22272,8 +22395,8 @@ function capture(ref) {
|
|
|
22272
22395
|
}
|
|
22273
22396
|
return Object.freeze({ path: ref.path });
|
|
22274
22397
|
}
|
|
22275
|
-
function queryPages(client, query,
|
|
22276
|
-
return client.pages(query,
|
|
22398
|
+
function queryPages(client, query, o = {}) {
|
|
22399
|
+
return client.pages(query, o);
|
|
22277
22400
|
}
|
|
22278
22401
|
|
|
22279
22402
|
// src/records/witness.ts
|
|
@@ -22294,14 +22417,14 @@ function complete(record3, id4) {
|
|
|
22294
22417
|
);
|
|
22295
22418
|
}
|
|
22296
22419
|
}
|
|
22297
|
-
function
|
|
22420
|
+
function isProtected(record3) {
|
|
22298
22421
|
return record3.state.hold !== void 0 || record3.state.unresolved !== void 0 && record3.state.unresolved !== 0;
|
|
22299
22422
|
}
|
|
22300
22423
|
function confirmed(record3) {
|
|
22301
|
-
return record3.state.state === "confirmed" && !
|
|
22424
|
+
return record3.state.state === "confirmed" && !isProtected(record3);
|
|
22302
22425
|
}
|
|
22303
|
-
function copy(
|
|
22304
|
-
return
|
|
22426
|
+
function copy(data) {
|
|
22427
|
+
return structuredClone(data);
|
|
22305
22428
|
}
|
|
22306
22429
|
function problem2(error4) {
|
|
22307
22430
|
if (error4 instanceof MdbaseError) return error4.toProblem();
|
|
@@ -22312,16 +22435,19 @@ function problem2(error4) {
|
|
|
22312
22435
|
error4 instanceof Error ? error4.message : "record session failure"
|
|
22313
22436
|
).toProblem();
|
|
22314
22437
|
}
|
|
22315
|
-
function refusal(code,
|
|
22438
|
+
function refusal(code, message2, reason) {
|
|
22316
22439
|
return new MdbaseError({
|
|
22317
22440
|
code,
|
|
22318
|
-
message,
|
|
22441
|
+
message: message2,
|
|
22319
22442
|
reason,
|
|
22320
22443
|
recovery: code === "conflict" ? "resolve_conflict" : code === "outcome_unknown" ? "resolve_outcome" : "retry"
|
|
22321
22444
|
});
|
|
22322
22445
|
}
|
|
22323
|
-
function
|
|
22324
|
-
return
|
|
22446
|
+
function retainedBytes(data) {
|
|
22447
|
+
return JSON.stringify(
|
|
22448
|
+
data,
|
|
22449
|
+
(_key, v) => typeof v === "bigint" ? v.toString() : v instanceof Uint8Array ? toHex(v) : v
|
|
22450
|
+
).length * 2;
|
|
22325
22451
|
}
|
|
22326
22452
|
function textBytes(text6) {
|
|
22327
22453
|
if (text6.length > MAX_BYTES)
|
|
@@ -22351,7 +22477,7 @@ var RecordSessionImpl = class {
|
|
|
22351
22477
|
complete(record3);
|
|
22352
22478
|
this.base = copy(record3);
|
|
22353
22479
|
this.body = record3.body;
|
|
22354
|
-
this.state =
|
|
22480
|
+
this.state = isProtected(record3) ? "conflict" : resting(record3);
|
|
22355
22481
|
this.publish();
|
|
22356
22482
|
}
|
|
22357
22483
|
client;
|
|
@@ -22456,7 +22582,7 @@ var RecordSessionImpl = class {
|
|
|
22456
22582
|
const next = new Map(this.patch);
|
|
22457
22583
|
for (const [key3, input] of patch instanceof Map ? patch : Object.entries(patch)) {
|
|
22458
22584
|
const value2 = input === void 0 ? void 0 : decode(encode(toValue(input)));
|
|
22459
|
-
const before = this.base.frontmatter.
|
|
22585
|
+
const before = Object.hasOwn(this.base.frontmatter, key3) ? toValue(this.base.frontmatter[key3]) : void 0;
|
|
22460
22586
|
if (!this.captured?.patch.has(key3) && (value2 === void 0 && before === void 0 || value2 !== void 0 && before !== void 0 && equal5(value2, before)))
|
|
22461
22587
|
next.delete(key3);
|
|
22462
22588
|
else next.set(key3, value2);
|
|
@@ -22474,35 +22600,35 @@ var RecordSessionImpl = class {
|
|
|
22474
22600
|
this.schedule();
|
|
22475
22601
|
}
|
|
22476
22602
|
charge(body = this.body, patch = this.patch, base = this.base, remote = this.remote, receipt3 = this.lastReceipt, captured = this.captured) {
|
|
22477
|
-
let bytes10 =
|
|
22478
|
-
if (remote) bytes10 +=
|
|
22603
|
+
let bytes10 = retainedBytes(base) + textBytes(body) + encode(new Map([...patch].map(([k, v]) => [k, v ?? null]))).byteLength * 2;
|
|
22604
|
+
if (remote) bytes10 += retainedBytes(remote);
|
|
22479
22605
|
if (captured)
|
|
22480
22606
|
bytes10 += textBytes(captured.body) + encode(
|
|
22481
22607
|
new Map(
|
|
22482
22608
|
[...captured.patch].map(([k, v]) => [k, v ?? null])
|
|
22483
22609
|
)
|
|
22484
22610
|
).byteLength * 2;
|
|
22485
|
-
if (receipt3) bytes10 +=
|
|
22611
|
+
if (receipt3) bytes10 += retainedBytes(receipt3);
|
|
22486
22612
|
this.reserve(bytes10);
|
|
22487
22613
|
}
|
|
22488
22614
|
publish() {
|
|
22489
22615
|
this.charge();
|
|
22490
|
-
const fm = new Map(
|
|
22616
|
+
const fm = new Map(
|
|
22617
|
+
Object.entries(this.base.frontmatter)
|
|
22618
|
+
);
|
|
22491
22619
|
for (const [k, v] of this.patch) {
|
|
22492
22620
|
if (v === void 0) fm.delete(k);
|
|
22493
|
-
else fm.set(k, v);
|
|
22621
|
+
else fm.set(k, toPlain(v));
|
|
22494
22622
|
}
|
|
22495
22623
|
this.snapshot = Object.freeze({
|
|
22496
22624
|
state: this.state,
|
|
22497
22625
|
body: this.body,
|
|
22498
|
-
frontmatter:
|
|
22626
|
+
frontmatter: structuredClone(Object.fromEntries(fm)),
|
|
22499
22627
|
record: copy(this.base),
|
|
22500
22628
|
remote: this.remote ? copy(this.remote) : null,
|
|
22501
22629
|
dirty: this.dirty,
|
|
22502
22630
|
problem: this.why,
|
|
22503
|
-
lastReceipt: this.lastReceipt ?
|
|
22504
|
-
decode(encode(receipt.enc(this.lastReceipt)))
|
|
22505
|
-
) : null,
|
|
22631
|
+
lastReceipt: this.lastReceipt ? copy(this.lastReceipt) : null,
|
|
22506
22632
|
recovery: this.captured ? Object.freeze({ ...this.captured.recovery }) : null
|
|
22507
22633
|
});
|
|
22508
22634
|
for (const listener of [...this.listeners]) {
|
|
@@ -22527,7 +22653,7 @@ var RecordSessionImpl = class {
|
|
|
22527
22653
|
}
|
|
22528
22654
|
}
|
|
22529
22655
|
async read(signal) {
|
|
22530
|
-
const record3 = await this.client.get(this.id, include2, signal);
|
|
22656
|
+
const record3 = await this.client.get(this.id, { include: include2, signal });
|
|
22531
22657
|
signal.throwIfAborted();
|
|
22532
22658
|
complete(record3, this.id);
|
|
22533
22659
|
return record3;
|
|
@@ -22556,9 +22682,9 @@ var RecordSessionImpl = class {
|
|
|
22556
22682
|
this.base = copy(current2);
|
|
22557
22683
|
this.body = current2.body;
|
|
22558
22684
|
this.remote = null;
|
|
22559
|
-
this.state =
|
|
22685
|
+
this.state = isProtected(current2) ? "conflict" : resting(current2);
|
|
22560
22686
|
this.why = null;
|
|
22561
|
-
} else if (current2.revision !== this.base.revision ||
|
|
22687
|
+
} else if (current2.revision !== this.base.revision || isProtected(current2)) {
|
|
22562
22688
|
this.remote = copy(current2);
|
|
22563
22689
|
this.state = "conflict";
|
|
22564
22690
|
this.why = refusal(
|
|
@@ -22637,7 +22763,7 @@ var RecordSessionImpl = class {
|
|
|
22637
22763
|
saved: "on_device"
|
|
22638
22764
|
};
|
|
22639
22765
|
const current2 = await this.read(signal);
|
|
22640
|
-
if (
|
|
22766
|
+
if (isProtected(current2)) {
|
|
22641
22767
|
this.charge(this.body, this.patch, this.base, current2);
|
|
22642
22768
|
this.remote = copy(current2);
|
|
22643
22769
|
throw refusal(
|
|
@@ -22735,11 +22861,13 @@ var RecordSessionImpl = class {
|
|
|
22735
22861
|
}
|
|
22736
22862
|
async settle(signal, budget) {
|
|
22737
22863
|
const captured = this.captured, original = captured.recovery;
|
|
22738
|
-
const receipt3 = await this.client.awaitReceipt(
|
|
22739
|
-
|
|
22740
|
-
|
|
22864
|
+
const receipt3 = await this.client.awaitReceipt(original.mutationId, {
|
|
22865
|
+
timeoutMs: Math.max(
|
|
22866
|
+
1,
|
|
22867
|
+
budget.until - Date.now() - budget.margin
|
|
22868
|
+
),
|
|
22741
22869
|
signal
|
|
22742
|
-
);
|
|
22870
|
+
});
|
|
22743
22871
|
signal.throwIfAborted();
|
|
22744
22872
|
if (receipt3.mutation !== original.mutationId)
|
|
22745
22873
|
throw refusal(
|
|
@@ -22778,7 +22906,7 @@ var RecordSessionImpl = class {
|
|
|
22778
22906
|
}
|
|
22779
22907
|
const current2 = await this.read(signal);
|
|
22780
22908
|
const kept = receipt3.state === "pending";
|
|
22781
|
-
if (kept ?
|
|
22909
|
+
if (kept ? isProtected(current2) : !confirmed(current2))
|
|
22782
22910
|
throw refusal(
|
|
22783
22911
|
"outcome_unknown",
|
|
22784
22912
|
"confirmed receipt has pending/protected current readback",
|
|
@@ -22921,7 +23049,10 @@ var RecordsApi = class {
|
|
|
22921
23049
|
if (this.closed)
|
|
22922
23050
|
throw mdbaseError("unavailable", "record sessions client closed");
|
|
22923
23051
|
options.signal?.throwIfAborted();
|
|
22924
|
-
const current2 = await this.client.get(ref,
|
|
23052
|
+
const current2 = await this.client.get(ref, {
|
|
23053
|
+
include: include2,
|
|
23054
|
+
signal: options.signal
|
|
23055
|
+
});
|
|
22925
23056
|
options.signal?.throwIfAborted();
|
|
22926
23057
|
if (this.closed)
|
|
22927
23058
|
throw mdbaseError("unavailable", "record sessions client closed");
|
|
@@ -23051,7 +23182,7 @@ var RecordsApi = class {
|
|
|
23051
23182
|
}
|
|
23052
23183
|
startWatch() {
|
|
23053
23184
|
if (this.watch) return;
|
|
23054
|
-
const watch = this.client.watchChanges(
|
|
23185
|
+
const watch = this.client.watchChanges((batch) => {
|
|
23055
23186
|
for (const [id4, slot] of this.slots)
|
|
23056
23187
|
if (slot.leases > 0 && (batch.reset || batch.changes.some((change3) => change3.id === id4)))
|
|
23057
23188
|
void slot.session.refresh();
|
|
@@ -23104,28 +23235,28 @@ var RecordsApi = class {
|
|
|
23104
23235
|
|
|
23105
23236
|
// src/saved-views.ts
|
|
23106
23237
|
var SAVED_VIEW_CONTRACT = Object.freeze({ id: "mdbase.view", version: "1.0.0" });
|
|
23107
|
-
var map3 = (v) => v
|
|
23238
|
+
var map3 = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
23239
|
+
var list3 = (v) => Array.isArray(v) ? v : [];
|
|
23108
23240
|
var text3 = (v) => typeof v === "string" ? v : void 0;
|
|
23109
|
-
var warning = (code,
|
|
23241
|
+
var warning = (code, message2, path) => ({ code, severity: "warning", message: message2, details: { path } });
|
|
23110
23242
|
var notFound = (e, path) => {
|
|
23111
23243
|
if (isMdbaseError(e, "not_found")) throw mdbaseError("not_found", `saved view source '${path}' was not found`, "view_not_found");
|
|
23112
23244
|
throw e;
|
|
23113
23245
|
};
|
|
23114
23246
|
var refPath = (ref) => typeof ref === "string" ? ref : ref.path;
|
|
23115
23247
|
function properties(record3, view) {
|
|
23116
|
-
const metadata2 = map3(record3
|
|
23248
|
+
const metadata2 = map3(fieldOf(record3, "properties"));
|
|
23117
23249
|
const out = [];
|
|
23118
|
-
const
|
|
23119
|
-
for (const selection of select) {
|
|
23250
|
+
for (const selection of list3(fieldOf(view, "select"))) {
|
|
23120
23251
|
const object9 = map3(selection);
|
|
23121
23252
|
const selector = text3(selection);
|
|
23122
|
-
const key3 = object9 ? text3(object9
|
|
23253
|
+
const key3 = object9 ? text3(fieldOf(object9, "name")) : selector?.slice(selector.lastIndexOf(".") + 1);
|
|
23123
23254
|
if (!key3) continue;
|
|
23124
|
-
const meta = map3(metadata2
|
|
23255
|
+
const meta = map3(fieldOf(metadata2, object9 || !selector ? key3 : selector)) ?? map3(fieldOf(metadata2, key3));
|
|
23125
23256
|
const property = { key: key3 };
|
|
23126
|
-
const label = text3(object9
|
|
23127
|
-
const description = text3(object9
|
|
23128
|
-
const format = text3(meta
|
|
23257
|
+
const label = text3(fieldOf(object9, "label")) ?? text3(fieldOf(meta, "label"));
|
|
23258
|
+
const description = text3(fieldOf(object9, "description")) ?? text3(fieldOf(meta, "description"));
|
|
23259
|
+
const format = text3(fieldOf(meta, "format")), hidden = fieldOf(meta, "hidden");
|
|
23129
23260
|
if (label !== void 0) property.label = label;
|
|
23130
23261
|
if (description !== void 0) property.description = description;
|
|
23131
23262
|
if (format !== void 0) property.format = format;
|
|
@@ -23134,7 +23265,8 @@ function properties(record3, view) {
|
|
|
23134
23265
|
}
|
|
23135
23266
|
return out;
|
|
23136
23267
|
}
|
|
23137
|
-
async function listSavedViews(client,
|
|
23268
|
+
async function listSavedViews(client, o = {}) {
|
|
23269
|
+
const { folder, signal } = o;
|
|
23138
23270
|
const sources = [], diagnostics = [];
|
|
23139
23271
|
const prefix = folder ? folder.replace(/\/?$/, "/") : "";
|
|
23140
23272
|
let cursor, complete2 = true;
|
|
@@ -23157,8 +23289,8 @@ async function listSavedViews(client, folder, signal) {
|
|
|
23157
23289
|
return;
|
|
23158
23290
|
}
|
|
23159
23291
|
const fields3 = projection.fields, views = [], ids = /* @__PURE__ */ new Set();
|
|
23160
|
-
for (const item of
|
|
23161
|
-
const view = map3(item), id4 = text3(view
|
|
23292
|
+
for (const item of list3(fieldOf(fields3, "views"))) {
|
|
23293
|
+
const view = map3(item), id4 = text3(fieldOf(view, "id")), name2 = text3(fieldOf(view, "name"));
|
|
23162
23294
|
if (!view || !id4 || !name2) continue;
|
|
23163
23295
|
if (ids.has(id4)) {
|
|
23164
23296
|
diagnostics.push(warning("invalid_view", "View record contains duplicate named-view IDs.", record3.path));
|
|
@@ -23166,13 +23298,14 @@ async function listSavedViews(client, folder, signal) {
|
|
|
23166
23298
|
}
|
|
23167
23299
|
ids.add(id4);
|
|
23168
23300
|
const descriptor = { id: id4, name: name2, properties: properties(fields3, view) };
|
|
23169
|
-
|
|
23301
|
+
const presentation = fieldOf(view, "presentation");
|
|
23302
|
+
if (presentation !== void 0) descriptor.presentation = presentation;
|
|
23170
23303
|
views.push(descriptor);
|
|
23171
23304
|
}
|
|
23172
23305
|
sources.push({
|
|
23173
23306
|
record: record3.id,
|
|
23174
|
-
id: text3(fields3
|
|
23175
|
-
name: text3(fields3
|
|
23307
|
+
id: text3(fieldOf(fields3, "id")) ?? record3.path,
|
|
23308
|
+
name: text3(fieldOf(fields3, "name")) ?? record3.path,
|
|
23176
23309
|
source: { path: record3.path, format: SAVED_VIEW_CONTRACT.id, revision: record3.revision, writable: true },
|
|
23177
23310
|
views
|
|
23178
23311
|
});
|
|
@@ -23184,68 +23317,73 @@ async function listSavedViews(client, folder, signal) {
|
|
|
23184
23317
|
}
|
|
23185
23318
|
async function executeSavedView(client, source, viewId, o = {}) {
|
|
23186
23319
|
const signal = o.signal;
|
|
23187
|
-
const record3 = await client.getContract(source, SAVED_VIEW_CONTRACT, signal).catch((e) => notFound(e, refPath(source)));
|
|
23320
|
+
const record3 = await client.getContract(source, SAVED_VIEW_CONTRACT, { signal }).catch((e) => notFound(e, refPath(source)));
|
|
23188
23321
|
const fields3 = record3.fields, path = record3.path;
|
|
23189
|
-
const views =
|
|
23190
|
-
const ids = views.map((view2) => text3(view2
|
|
23322
|
+
const views = list3(fieldOf(fields3, "views")).map(map3);
|
|
23323
|
+
const ids = views.map((view2) => text3(fieldOf(view2, "id")));
|
|
23191
23324
|
if (new Set(ids).size !== ids.length) throw mdbaseError("invalid_request", "View record contains duplicate named-view IDs.", "invalid_view");
|
|
23192
23325
|
const view = views[ids.indexOf(viewId)];
|
|
23193
23326
|
if (!view) throw mdbaseError("not_found", `named view '${viewId}' was not found`, "view_not_found");
|
|
23194
|
-
const shared = map3(fields3
|
|
23327
|
+
const shared = map3(fieldOf(fields3, "query"));
|
|
23195
23328
|
const query = /* @__PURE__ */ new Map();
|
|
23196
|
-
const types = view
|
|
23329
|
+
const types = fieldOf(view, "types") ?? fieldOf(shared, "types");
|
|
23197
23330
|
if (types !== void 0) query.set("types", types);
|
|
23198
|
-
const wheres = [text3(shared
|
|
23331
|
+
const wheres = [text3(fieldOf(shared, "where")), text3(fieldOf(view, "where"))].filter((w) => !!w);
|
|
23199
23332
|
if (wheres.length) query.set("where", wheres.length === 2 ? `(${wheres[0]}) && (${wheres[1]})` : wheres[0]);
|
|
23200
|
-
const projections = new Map(map3(shared
|
|
23201
|
-
for (const [name2, definition] of map3(view
|
|
23333
|
+
const projections = new Map(Object.entries(map3(fieldOf(shared, "projections")) ?? {}));
|
|
23334
|
+
for (const [name2, definition] of Object.entries(map3(fieldOf(view, "projections")) ?? {})) {
|
|
23202
23335
|
const existing = projections.get(name2);
|
|
23203
23336
|
if (existing !== void 0 && canonical(existing) !== canonical(definition))
|
|
23204
23337
|
throw mdbaseError("invalid_request", `Projection '${name2}' has conflicting definitions.`, "invalid_view");
|
|
23205
23338
|
projections.set(name2, definition);
|
|
23206
23339
|
}
|
|
23207
|
-
if (projections.size) query.set("projections", projections);
|
|
23208
|
-
for (const key3 of ["select", "order_by", "group_by", "summaries", "limit", "offset", "include_body", "frontmatter_mode"])
|
|
23209
|
-
|
|
23210
|
-
|
|
23340
|
+
if (projections.size) query.set("projections", Object.fromEntries(projections));
|
|
23341
|
+
for (const key3 of ["select", "order_by", "group_by", "summaries", "limit", "offset", "include_body", "frontmatter_mode"]) {
|
|
23342
|
+
const value2 = fieldOf(view, key3);
|
|
23343
|
+
if (value2 !== void 0) query.set(key3, value2);
|
|
23344
|
+
}
|
|
23345
|
+
const summaryFunctions = fieldOf(fields3, "summary_functions");
|
|
23346
|
+
if (summaryFunctions !== void 0) query.set("summary_functions", summaryFunctions);
|
|
23211
23347
|
if (o.limit !== void 0) query.set("limit", o.limit);
|
|
23212
23348
|
if (o.offset !== void 0) query.set("offset", o.offset);
|
|
23213
23349
|
if (o.timezone !== void 0) query.set("timezone", o.timezone);
|
|
23214
|
-
const declaration = map3(map3(view
|
|
23215
|
-
const onMissing = text3(declaration
|
|
23350
|
+
const declaration = map3(fieldOf(map3(fieldOf(view, "context") ?? fieldOf(shared, "context")), "this"));
|
|
23351
|
+
const onMissing = text3(fieldOf(declaration, "on_missing")) ?? "view";
|
|
23216
23352
|
let context = o.context;
|
|
23217
23353
|
if (context === void 0 && onMissing === "error") throw mdbaseError("invalid_request", "This named view requires an invocation context.", "context_required");
|
|
23218
23354
|
if (context === void 0 && onMissing === "view") context = { path };
|
|
23219
23355
|
if (context !== void 0) {
|
|
23220
|
-
const required =
|
|
23356
|
+
const required = list3(fieldOf(declaration, "types")).filter((t) => typeof t === "string");
|
|
23221
23357
|
let contextPath = typeof context === "string" ? void 0 : context.path;
|
|
23222
23358
|
if (required.length || contextPath === void 0) {
|
|
23223
|
-
const bound = await client.get(context,
|
|
23359
|
+
const bound = await client.get(context, { signal });
|
|
23224
23360
|
contextPath = bound.path;
|
|
23225
23361
|
if (required.length && !bound.types.some((t) => required.some((r) => r.toLowerCase() === t.toLowerCase())))
|
|
23226
23362
|
throw mdbaseError("invalid_request", "The invocation context does not match an allowed context type.", "context_type_mismatch");
|
|
23227
23363
|
}
|
|
23228
|
-
query.set("context",
|
|
23364
|
+
query.set("context", { this: { path: contextPath } });
|
|
23229
23365
|
}
|
|
23230
|
-
const result2 = await client.query(query, o.include, signal);
|
|
23366
|
+
const result2 = await client.query(Object.fromEntries(query), { include: o.include, signal });
|
|
23231
23367
|
return { ...result2, view: { path, view: viewId } };
|
|
23232
23368
|
}
|
|
23233
|
-
async function readSavedViewSource(client, source,
|
|
23234
|
-
const
|
|
23235
|
-
const
|
|
23369
|
+
async function readSavedViewSource(client, source, o = {}) {
|
|
23370
|
+
const signal = o.signal;
|
|
23371
|
+
const contract = await client.getContract(source, SAVED_VIEW_CONTRACT, { signal }).catch((e) => notFound(e, refPath(source)));
|
|
23372
|
+
const record3 = await client.get(contract.id, { include: { document: true }, signal });
|
|
23236
23373
|
if (record3.revision !== contract.revision || typeof record3.document !== "string")
|
|
23237
23374
|
throw mdbaseError("unavailable", "saved view source changed while it was read", "view_source_changed");
|
|
23238
23375
|
return { path: record3.path, format: SAVED_VIEW_CONTRACT.id, revision: record3.revision, document: record3.document, record: record3.id };
|
|
23239
23376
|
}
|
|
23240
23377
|
function canonical(v) {
|
|
23241
|
-
if (v instanceof Map) return `{${[...v].map(([k, x]) => [JSON.stringify(String(k)), canonical(x)]).sort((a, b) => a[0] < b[0] ? -1 : 1).map(([k, x]) => `${k}:${x}`).join(",")}}`;
|
|
23242
23378
|
if (Array.isArray(v)) return `[${v.map(canonical).join(",")}]`;
|
|
23243
|
-
|
|
23379
|
+
if (v !== null && typeof v === "object")
|
|
23380
|
+
return `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}`;
|
|
23381
|
+
return JSON.stringify(v);
|
|
23244
23382
|
}
|
|
23245
23383
|
|
|
23246
23384
|
// src/view-sources.ts
|
|
23247
|
-
function invalid4(
|
|
23248
|
-
return mdbaseError("invalid_request",
|
|
23385
|
+
function invalid4(message2) {
|
|
23386
|
+
return mdbaseError("invalid_request", message2, "view_source_witness_required");
|
|
23249
23387
|
}
|
|
23250
23388
|
function identity(id4) {
|
|
23251
23389
|
try {
|
|
@@ -23275,7 +23413,7 @@ function sourceOptions(options) {
|
|
|
23275
23413
|
async function readViewSourceRecord(client, source, options = {}) {
|
|
23276
23414
|
const expectedId = typeof source === "string" ? source : "id" in source ? source.id : void 0;
|
|
23277
23415
|
const expected = expectedId === void 0 ? void 0 : uuid2.dec(uuid2.enc(expectedId));
|
|
23278
|
-
const record3 = await client.get(source, { ...options.include, document: true }, options.signal);
|
|
23416
|
+
const record3 = await client.get(source, { include: { ...options.include, document: true }, signal: options.signal });
|
|
23279
23417
|
fullSource(record3);
|
|
23280
23418
|
if (expected !== void 0 && record3.id !== expected) throw invalid4("view source readback belongs to another record");
|
|
23281
23419
|
return record3;
|
|
@@ -23409,6 +23547,303 @@ var LiveResult = class {
|
|
|
23409
23547
|
}
|
|
23410
23548
|
};
|
|
23411
23549
|
|
|
23550
|
+
// src/record-set.ts
|
|
23551
|
+
var PAGE = 1e3;
|
|
23552
|
+
var REREAD_MAX = 500;
|
|
23553
|
+
var REREAD_CONCURRENCY = 8;
|
|
23554
|
+
var RETRY_MIN_MS = 250;
|
|
23555
|
+
var RETRY_MAX_MS = 3e4;
|
|
23556
|
+
function passing(e) {
|
|
23557
|
+
if (!(e instanceof MdbaseError)) return false;
|
|
23558
|
+
if (e.recovery === "retry") return true;
|
|
23559
|
+
return e.code === "invalid_request" && (e.reason === "cursor_stale" || e.reason === "cursor_expired") || e.code === "conflict" && e.reason === "collection_changed";
|
|
23560
|
+
}
|
|
23561
|
+
var problemOf = (e) => e instanceof MdbaseError ? e.toProblem() : { code: "internal", recovery: "contact_support", message: e instanceof Error ? e.message : String(e) };
|
|
23562
|
+
var fold = (type) => type.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
23563
|
+
var sameTypes = (a, b) => a.length === b.length && a.every((t, i) => t === b[i]);
|
|
23564
|
+
var unchanged = (a, b) => a.revision === b.revision && a.path === b.path && a.state.state === b.state.state && a.state.hold?.id === b.state.hold?.id && a.state.unresolved === b.state.unresolved && sameTypes(a.types, b.types);
|
|
23565
|
+
var RecordSet = class {
|
|
23566
|
+
/** @internal `MdbaseClient.recordSet`. */
|
|
23567
|
+
constructor(client, options = {}) {
|
|
23568
|
+
this.client = client;
|
|
23569
|
+
this.signal = options.signal;
|
|
23570
|
+
this.pending = client.status.pending;
|
|
23571
|
+
this.types = options.types?.length ? [...options.types] : void 0;
|
|
23572
|
+
this.folded = this.types?.map(fold);
|
|
23573
|
+
this.include = options.include ? { ...options.include } : void 0;
|
|
23574
|
+
this.ready = new Promise((resolve, reject) => {
|
|
23575
|
+
this.resolveReady = resolve;
|
|
23576
|
+
this.rejectReady = reject;
|
|
23577
|
+
});
|
|
23578
|
+
this.ready.catch(() => {
|
|
23579
|
+
});
|
|
23580
|
+
this.offStatus = client.onStatus((s) => {
|
|
23581
|
+
const settled = s.pending < this.pending;
|
|
23582
|
+
this.pending = s.pending;
|
|
23583
|
+
if (!settled) return;
|
|
23584
|
+
for (const r of this.byId.values()) if (r.state.state === "pending") this.queued.add(r.id);
|
|
23585
|
+
void this.work();
|
|
23586
|
+
});
|
|
23587
|
+
this.startWatch();
|
|
23588
|
+
this.signal?.addEventListener("abort", this.abort, { once: true });
|
|
23589
|
+
if (this.signal?.aborted) this.close();
|
|
23590
|
+
}
|
|
23591
|
+
client;
|
|
23592
|
+
/** Resolves when the set is first `current`; rejects if it fails or closes first. */
|
|
23593
|
+
ready;
|
|
23594
|
+
resolveReady;
|
|
23595
|
+
rejectReady;
|
|
23596
|
+
lifetime = new AbortController();
|
|
23597
|
+
listeners = /* @__PURE__ */ new Set();
|
|
23598
|
+
types;
|
|
23599
|
+
folded;
|
|
23600
|
+
include;
|
|
23601
|
+
byId = /* @__PURE__ */ new Map();
|
|
23602
|
+
view = Object.freeze({ records: Object.freeze([]), state: "loading", problem: null });
|
|
23603
|
+
/** Changed since `view.records` was built. */
|
|
23604
|
+
touched = false;
|
|
23605
|
+
state = "loading";
|
|
23606
|
+
problem = null;
|
|
23607
|
+
watch;
|
|
23608
|
+
offWatch = () => {
|
|
23609
|
+
};
|
|
23610
|
+
offStatus;
|
|
23611
|
+
abort = () => this.close();
|
|
23612
|
+
/** Where the change feed was last read to, so a replaced watch resumes there. */
|
|
23613
|
+
cursor;
|
|
23614
|
+
/** Records the feed named since they were last read. */
|
|
23615
|
+
queued = /* @__PURE__ */ new Set();
|
|
23616
|
+
/** A complete read has finished. */
|
|
23617
|
+
loaded = false;
|
|
23618
|
+
/** A complete read is needed. */
|
|
23619
|
+
dirty = true;
|
|
23620
|
+
working = false;
|
|
23621
|
+
/** A retry that is waiting, and what it will do. */
|
|
23622
|
+
timer;
|
|
23623
|
+
again;
|
|
23624
|
+
delay = RETRY_MIN_MS;
|
|
23625
|
+
pending;
|
|
23626
|
+
signal;
|
|
23627
|
+
getSnapshot = () => this.view;
|
|
23628
|
+
get(id4) {
|
|
23629
|
+
return this.byId.get(id4);
|
|
23630
|
+
}
|
|
23631
|
+
subscribe = (listener) => {
|
|
23632
|
+
if (this.state !== "closed") this.listeners.add(listener);
|
|
23633
|
+
return () => {
|
|
23634
|
+
this.listeners.delete(listener);
|
|
23635
|
+
};
|
|
23636
|
+
};
|
|
23637
|
+
/** Read every record again: after `failed`, or when something the change
|
|
23638
|
+
* feed does not report (a type definition) has changed. */
|
|
23639
|
+
reload() {
|
|
23640
|
+
if (this.state === "closed") return Promise.reject(mdbaseError("cancelled", "record set closed"));
|
|
23641
|
+
this.dirty = true;
|
|
23642
|
+
this.delay = RETRY_MIN_MS;
|
|
23643
|
+
if (this.state === "failed") {
|
|
23644
|
+
this.problem = null;
|
|
23645
|
+
this.publish(this.loaded ? "stale" : "loading");
|
|
23646
|
+
if (this.watch.state === "failed" || this.watch.state === "closed") this.startWatch();
|
|
23647
|
+
}
|
|
23648
|
+
return new Promise((resolve, reject) => {
|
|
23649
|
+
const off = this.subscribe(() => {
|
|
23650
|
+
if (this.state === "current" && !this.dirty) {
|
|
23651
|
+
off();
|
|
23652
|
+
resolve();
|
|
23653
|
+
} else if (this.state === "failed" || this.state === "closed") {
|
|
23654
|
+
off();
|
|
23655
|
+
reject(new MdbaseError(this.problem ?? { code: "cancelled", recovery: "none", message: "record set closed" }));
|
|
23656
|
+
}
|
|
23657
|
+
});
|
|
23658
|
+
this.resume();
|
|
23659
|
+
});
|
|
23660
|
+
}
|
|
23661
|
+
close() {
|
|
23662
|
+
if (this.state === "closed") return;
|
|
23663
|
+
this.lifetime.abort();
|
|
23664
|
+
this.cancelRetry();
|
|
23665
|
+
this.signal?.removeEventListener("abort", this.abort);
|
|
23666
|
+
this.offStatus();
|
|
23667
|
+
this.offWatch();
|
|
23668
|
+
this.watch();
|
|
23669
|
+
this.rejectReady(mdbaseError("cancelled", "record set closed"));
|
|
23670
|
+
this.publish("closed");
|
|
23671
|
+
this.listeners.clear();
|
|
23672
|
+
}
|
|
23673
|
+
startWatch() {
|
|
23674
|
+
this.offWatch();
|
|
23675
|
+
const watch = this.client.watchChanges((batch) => {
|
|
23676
|
+
if (this.watch === watch) this.changed(batch);
|
|
23677
|
+
}, { cursor: this.cursor });
|
|
23678
|
+
this.watch = watch;
|
|
23679
|
+
if (this.cursor === void 0) this.dirty = true;
|
|
23680
|
+
this.offWatch = watch.subscribe((state, error4) => {
|
|
23681
|
+
if (this.watch !== watch || this.state === "closed" || this.state === "failed") return;
|
|
23682
|
+
if (state === "active") {
|
|
23683
|
+
void this.work();
|
|
23684
|
+
return;
|
|
23685
|
+
}
|
|
23686
|
+
if (state === "stale") {
|
|
23687
|
+
if (this.loaded) this.publish("stale");
|
|
23688
|
+
return;
|
|
23689
|
+
}
|
|
23690
|
+
if (state === "closed") {
|
|
23691
|
+
this.close();
|
|
23692
|
+
return;
|
|
23693
|
+
}
|
|
23694
|
+
if (state === "failed") {
|
|
23695
|
+
if (error4 && passing(error4) && this.client.link !== "closed") this.retry(error4, () => this.startWatch());
|
|
23696
|
+
else this.fail(error4 ?? mdbaseError("unavailable", "the change watch stopped"));
|
|
23697
|
+
}
|
|
23698
|
+
});
|
|
23699
|
+
}
|
|
23700
|
+
changed(batch) {
|
|
23701
|
+
this.cursor = batch.cursor;
|
|
23702
|
+
if (batch.reset) this.dirty = true;
|
|
23703
|
+
for (const c of batch.changes) {
|
|
23704
|
+
if (c.entity === "file") continue;
|
|
23705
|
+
if (c.kind === "put" && this.types && c.types && !this.byId.has(c.id) && !this.member(c.types)) continue;
|
|
23706
|
+
if (c.kind === "remove" && !this.byId.has(c.id)) continue;
|
|
23707
|
+
this.queued.add(c.id);
|
|
23708
|
+
}
|
|
23709
|
+
void this.work();
|
|
23710
|
+
}
|
|
23711
|
+
member(types) {
|
|
23712
|
+
return !this.folded || types.some((t) => this.folded.includes(fold(t)));
|
|
23713
|
+
}
|
|
23714
|
+
/** One worker at a time: a complete read when one is needed, else rereads. */
|
|
23715
|
+
async work() {
|
|
23716
|
+
if (this.working || this.timer !== void 0) return;
|
|
23717
|
+
this.working = true;
|
|
23718
|
+
try {
|
|
23719
|
+
while (this.state !== "closed" && this.state !== "failed" && this.watch.state === "active" && (this.dirty || this.queued.size)) {
|
|
23720
|
+
if (!this.dirty && this.queued.size <= REREAD_MAX) await this.reread();
|
|
23721
|
+
else if (!await this.load()) {
|
|
23722
|
+
this.retry(null, () => void this.work());
|
|
23723
|
+
return;
|
|
23724
|
+
}
|
|
23725
|
+
this.delay = RETRY_MIN_MS;
|
|
23726
|
+
}
|
|
23727
|
+
} catch (e) {
|
|
23728
|
+
if (this.state === "closed" || isMdbaseError(e, "cancelled")) return;
|
|
23729
|
+
if (passing(e)) this.retry(e, () => void this.work());
|
|
23730
|
+
else this.fail(e);
|
|
23731
|
+
return;
|
|
23732
|
+
} finally {
|
|
23733
|
+
this.working = false;
|
|
23734
|
+
}
|
|
23735
|
+
if (this.state === "closed" || this.state === "failed" || this.watch.state !== "active") return;
|
|
23736
|
+
this.problem = null;
|
|
23737
|
+
this.publish("current");
|
|
23738
|
+
this.resolveReady();
|
|
23739
|
+
}
|
|
23740
|
+
retry(why, again) {
|
|
23741
|
+
this.problem = why?.toProblem() ?? null;
|
|
23742
|
+
this.publish(this.loaded ? "stale" : "loading");
|
|
23743
|
+
const delay = this.delay;
|
|
23744
|
+
this.delay = Math.min(delay * 2, RETRY_MAX_MS);
|
|
23745
|
+
clearTimeout(this.timer);
|
|
23746
|
+
this.again = again;
|
|
23747
|
+
this.timer = setTimeout(() => this.resume(), delay);
|
|
23748
|
+
}
|
|
23749
|
+
/** Do now what a waiting retry would do; without one, work. */
|
|
23750
|
+
resume() {
|
|
23751
|
+
clearTimeout(this.timer);
|
|
23752
|
+
this.timer = void 0;
|
|
23753
|
+
const again = this.again ?? (() => void this.work());
|
|
23754
|
+
this.again = void 0;
|
|
23755
|
+
if (this.state !== "closed") again();
|
|
23756
|
+
}
|
|
23757
|
+
cancelRetry() {
|
|
23758
|
+
clearTimeout(this.timer);
|
|
23759
|
+
this.timer = void 0;
|
|
23760
|
+
this.again = void 0;
|
|
23761
|
+
}
|
|
23762
|
+
fail(e) {
|
|
23763
|
+
this.cancelRetry();
|
|
23764
|
+
this.problem = problemOf(e);
|
|
23765
|
+
this.rejectReady(e instanceof MdbaseError ? e : new MdbaseError(this.problem));
|
|
23766
|
+
this.publish("failed");
|
|
23767
|
+
}
|
|
23768
|
+
/** One complete read. False when the replica could not answer completely. */
|
|
23769
|
+
async load() {
|
|
23770
|
+
const signal = this.lifetime.signal;
|
|
23771
|
+
this.dirty = false;
|
|
23772
|
+
this.queued.clear();
|
|
23773
|
+
this.publish(this.loaded ? "stale" : "loading");
|
|
23774
|
+
const next = /* @__PURE__ */ new Map();
|
|
23775
|
+
let complete2 = true;
|
|
23776
|
+
try {
|
|
23777
|
+
const query = { ...this.types ? { types: [...this.types] } : {}, limit: PAGE };
|
|
23778
|
+
for await (const page of this.client.pages(query, { include: this.include, signal })) {
|
|
23779
|
+
for (const r of page.records) next.set(r.id, r);
|
|
23780
|
+
complete2 &&= page.complete;
|
|
23781
|
+
if (!this.loaded) this.apply(page.records.map((r) => ({ record: r })), this.state);
|
|
23782
|
+
}
|
|
23783
|
+
} catch (e) {
|
|
23784
|
+
this.dirty = true;
|
|
23785
|
+
throw e;
|
|
23786
|
+
}
|
|
23787
|
+
const changes = [...next.values()].map((record3) => ({ record: record3 }));
|
|
23788
|
+
const removed = [...this.byId.keys()].filter((id4) => !next.has(id4)).map((id4) => ({ id: id4 }));
|
|
23789
|
+
this.loaded ||= complete2;
|
|
23790
|
+
if (!complete2) this.dirty = true;
|
|
23791
|
+
this.apply([...changes, ...removed], this.state);
|
|
23792
|
+
return complete2;
|
|
23793
|
+
}
|
|
23794
|
+
async reread() {
|
|
23795
|
+
const signal = this.lifetime.signal;
|
|
23796
|
+
const ids = [...this.queued];
|
|
23797
|
+
this.queued.clear();
|
|
23798
|
+
const read = new Array(ids.length);
|
|
23799
|
+
let next = 0;
|
|
23800
|
+
try {
|
|
23801
|
+
await Promise.all(Array.from({ length: Math.min(REREAD_CONCURRENCY, ids.length) }, async () => {
|
|
23802
|
+
while (next < ids.length) {
|
|
23803
|
+
const i = next++;
|
|
23804
|
+
read[i] = await this.client.find(ids[i], { include: this.include, signal });
|
|
23805
|
+
}
|
|
23806
|
+
}));
|
|
23807
|
+
} catch (e) {
|
|
23808
|
+
for (const id4 of ids) this.queued.add(id4);
|
|
23809
|
+
throw e;
|
|
23810
|
+
}
|
|
23811
|
+
this.apply(ids.map((id4, i) => read[i] && this.member(read[i].types) ? { record: read[i] } : { id: id4 }), this.state);
|
|
23812
|
+
}
|
|
23813
|
+
/** Put or remove records, then tell listeners what changed. */
|
|
23814
|
+
apply(entries, state) {
|
|
23815
|
+
const changes = [];
|
|
23816
|
+
for (const entry2 of entries) {
|
|
23817
|
+
const id4 = "record" in entry2 ? entry2.record.id : entry2.id;
|
|
23818
|
+
const previous = this.byId.get(id4);
|
|
23819
|
+
if ("record" in entry2) {
|
|
23820
|
+
this.byId.set(id4, entry2.record);
|
|
23821
|
+
if (!previous) changes.push({ kind: "put", record: entry2.record });
|
|
23822
|
+
else if (!unchanged(previous, entry2.record)) changes.push({ kind: "put", record: entry2.record, previous });
|
|
23823
|
+
} else if (previous) {
|
|
23824
|
+
this.byId.delete(id4);
|
|
23825
|
+
changes.push({ kind: "remove", previous });
|
|
23826
|
+
}
|
|
23827
|
+
}
|
|
23828
|
+
this.touched ||= entries.length > 0;
|
|
23829
|
+
this.publish(state, changes);
|
|
23830
|
+
}
|
|
23831
|
+
publish(state, changes = []) {
|
|
23832
|
+
if (this.state === "closed") return;
|
|
23833
|
+
const problem4 = state === "current" ? null : this.problem;
|
|
23834
|
+
if (!this.touched && state === this.state && problem4 === this.view.problem) return;
|
|
23835
|
+
this.state = state;
|
|
23836
|
+
this.view = Object.freeze({ records: this.touched ? Object.freeze([...this.byId.values()]) : this.view.records, state, problem: problem4 });
|
|
23837
|
+
this.touched = false;
|
|
23838
|
+
for (const listener of [...this.listeners]) {
|
|
23839
|
+
try {
|
|
23840
|
+
listener(changes);
|
|
23841
|
+
} catch {
|
|
23842
|
+
}
|
|
23843
|
+
}
|
|
23844
|
+
}
|
|
23845
|
+
};
|
|
23846
|
+
|
|
23412
23847
|
// src/presence.ts
|
|
23413
23848
|
var MAX_PRESENCE_STATE = 4096;
|
|
23414
23849
|
var MIN_INTERVAL_MS = 100;
|
|
@@ -23430,7 +23865,7 @@ var PresenceApi = class {
|
|
|
23430
23865
|
this.wired.add(s);
|
|
23431
23866
|
s.onPush("presence", (p) => {
|
|
23432
23867
|
try {
|
|
23433
|
-
const v = presencePush
|
|
23868
|
+
const v = decodePlain(presencePush, p);
|
|
23434
23869
|
for (const fn of this.watchers.get(v.record) ?? []) fn(v.peers);
|
|
23435
23870
|
} catch {
|
|
23436
23871
|
}
|
|
@@ -23445,7 +23880,7 @@ var PresenceApi = class {
|
|
|
23445
23880
|
check(state) {
|
|
23446
23881
|
const n = JSON.stringify(state, (_k, v) => typeof v === "bigint" ? v.toString() : v instanceof Map ? [...v] : v).length;
|
|
23447
23882
|
if (n > MAX_PRESENCE_STATE) {
|
|
23448
|
-
throw mdbaseError("too_large", "presence state over 4 KiB", { details:
|
|
23883
|
+
throw mdbaseError("too_large", "presence state over 4 KiB", { details: { limit: MAX_PRESENCE_STATE } });
|
|
23449
23884
|
}
|
|
23450
23885
|
}
|
|
23451
23886
|
async join(record3, state) {
|
|
@@ -23609,8 +24044,8 @@ function conflictMessage(r, adoptable) {
|
|
|
23609
24044
|
if (adoptable) return `${r.target} already exists with different content. Review it, then adopt it to let this pack manage it.`;
|
|
23610
24045
|
return r.reason ? `${r.target} can't be changed: ${r.reason}.` : `${r.target} can't be changed by this pack.`;
|
|
23611
24046
|
}
|
|
23612
|
-
function toPlan(
|
|
23613
|
-
const a = obj(
|
|
24047
|
+
function toPlan(assessment, pack, options) {
|
|
24048
|
+
const a = obj(assessment);
|
|
23614
24049
|
const resources = (Array.isArray(a.resources) ? a.resources : []).map(resource);
|
|
23615
24050
|
const summary = Object.fromEntries(ACTIONS.map((k) => [k, resources.filter((r) => r.action === k).map((r) => r.target)]));
|
|
23616
24051
|
const adoptable = {};
|
|
@@ -23714,7 +24149,7 @@ async function applyTypePack(client, plan, o = {}) {
|
|
|
23714
24149
|
const writes = r.writes ?? [];
|
|
23715
24150
|
if (!writes.length) return { outcome: "already_current", receipt: applied.desired };
|
|
23716
24151
|
const ops = writes.map((w) => w.doc === void 0 ? { kind: "resource_delete", path: w.path, ...opt("baseRevision", w.baseRevision) } : { kind: "resource_put", path: w.path, doc: w.doc, ...opt("baseRevision", w.baseRevision), ...w.mustNotExist ? { mustNotExist: true } : {} });
|
|
23717
|
-
const write =
|
|
24152
|
+
const write = await client.submit(ops, o);
|
|
23718
24153
|
const receipt3 = write.receipt;
|
|
23719
24154
|
if (receipt3.state === "rejected" || receipt3.state === "unknown") {
|
|
23720
24155
|
throw new MdbaseError(receipt3.problem ?? (receipt3.state === "unknown" ? { code: "outcome_unknown", recovery: "resolve_outcome", message: "The type pack install outcome is unknown." } : { code: "internal", recovery: "contact_support", message: "The type pack install was rejected." }), { mutationId: receipt3.mutation });
|
|
@@ -23846,8 +24281,8 @@ var WriteLedger = class {
|
|
|
23846
24281
|
}
|
|
23847
24282
|
}
|
|
23848
24283
|
/** @internal Persist intent BEFORE the write is submitted. */
|
|
23849
|
-
begin(
|
|
23850
|
-
return
|
|
24284
|
+
begin(mutationId, ops) {
|
|
24285
|
+
return this.set(entry(mutationId, targets(ops), "pending"));
|
|
23851
24286
|
}
|
|
23852
24287
|
/** @internal Apply a receipt from any source. */
|
|
23853
24288
|
observe(r) {
|
|
@@ -23899,10 +24334,7 @@ var WriteLedger = class {
|
|
|
23899
24334
|
}
|
|
23900
24335
|
if (added) this.changed();
|
|
23901
24336
|
}
|
|
23902
|
-
/** @internal A submit call failed: ask the replica whether it captured
|
|
23903
|
-
settleAll(ids) {
|
|
23904
|
-
return Promise.all(ids.map((id4) => this.settle(id4)));
|
|
23905
|
-
}
|
|
24337
|
+
/** @internal A submit call failed: ask the replica whether it captured the write. */
|
|
23906
24338
|
async settle(id4) {
|
|
23907
24339
|
try {
|
|
23908
24340
|
this.observe(await this.native.receipt(id4));
|
|
@@ -23936,6 +24368,7 @@ var WriteLedger = class {
|
|
|
23936
24368
|
};
|
|
23937
24369
|
|
|
23938
24370
|
// src/client.ts
|
|
24371
|
+
var CHANGES_PAGE = 1e3;
|
|
23939
24372
|
function snapshotQueryValue(value2) {
|
|
23940
24373
|
if (value2 instanceof Float64) return new Float64(value2.value);
|
|
23941
24374
|
if (value2 instanceof Date) return new Date(value2);
|
|
@@ -24011,6 +24444,8 @@ var Write = class {
|
|
|
24011
24444
|
* is a final non-publication, not success. Without files, settles at confirmation.
|
|
24012
24445
|
* Rejects rejected/unknown outcomes; not a native custody/durable ACK gate. */
|
|
24013
24446
|
published;
|
|
24447
|
+
/** The record a single-record write targets (create, update, replace, rename, delete). */
|
|
24448
|
+
recordId;
|
|
24014
24449
|
get mutationId() {
|
|
24015
24450
|
return this.receipt.mutation;
|
|
24016
24451
|
}
|
|
@@ -24099,8 +24534,11 @@ var LiveQuery = class {
|
|
|
24099
24534
|
fn(this, null);
|
|
24100
24535
|
return () => this.listeners.delete(fn);
|
|
24101
24536
|
}
|
|
24102
|
-
/** Change the query (for example a larger `limit` window). Re-subscribes.
|
|
24103
|
-
|
|
24537
|
+
/** Change the query (for example a larger `limit` window). Re-subscribes.
|
|
24538
|
+
* `o.include` replaces what each record carries; without it the current
|
|
24539
|
+
* include is kept. */
|
|
24540
|
+
async setQuery(query, o = {}) {
|
|
24541
|
+
const { include: include3 = this.include } = o;
|
|
24104
24542
|
this.query = query;
|
|
24105
24543
|
this.include = include3;
|
|
24106
24544
|
this.result.markStale();
|
|
@@ -24411,9 +24849,9 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24411
24849
|
}
|
|
24412
24850
|
/** Recheck session identity after waiting for catch-up (SDK-internal use). */
|
|
24413
24851
|
async readyForRead(signal, immediate = false) {
|
|
24414
|
-
if (!this.fenceReads) return immediate ? this.currentSession() : this.ready(signal);
|
|
24852
|
+
if (!this.fenceReads) return immediate ? this.currentSession() : this.ready({ signal });
|
|
24415
24853
|
for (; ; ) {
|
|
24416
|
-
const s = immediate ? this.currentSession() : await this.ready(signal);
|
|
24854
|
+
const s = immediate ? this.currentSession() : await this.ready({ signal });
|
|
24417
24855
|
await this.readFence(signal);
|
|
24418
24856
|
if (s === this.session && !s.closed && this.readFencedAt === null) return s;
|
|
24419
24857
|
if (immediate) this.currentSession();
|
|
@@ -24442,8 +24880,9 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24442
24880
|
}
|
|
24443
24881
|
return this.session;
|
|
24444
24882
|
}
|
|
24445
|
-
/** @internal Wait until a session is open (or the client closes). */
|
|
24446
|
-
async ready(
|
|
24883
|
+
/** @internal Wait until a session is open (or the client closes); `o.signal` cancels the wait. */
|
|
24884
|
+
async ready(o = {}) {
|
|
24885
|
+
const signal = o.signal;
|
|
24447
24886
|
for (; ; ) {
|
|
24448
24887
|
if (this.linkState === "closed") throw this.linkError ?? mdbaseError("unavailable", "client closed");
|
|
24449
24888
|
if (this.session && !this.session.closed) return this.session;
|
|
@@ -24454,17 +24893,16 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24454
24893
|
});
|
|
24455
24894
|
}
|
|
24456
24895
|
}
|
|
24457
|
-
/**
|
|
24458
|
-
* Advanced: run a request on the current session; on a dropped link, wait for the
|
|
24459
|
-
* reconnect and retry when `retry` (idempotent requests only).
|
|
24460
|
-
*/
|
|
24461
24896
|
async call(method, p, o = {}) {
|
|
24462
24897
|
const codec = o.codec;
|
|
24463
24898
|
const read = this.fenceReads && READ_METHODS.has(method);
|
|
24464
24899
|
for (; ; ) {
|
|
24465
|
-
const s = read ? await this.readyForRead(o.signal, !o.retry) : o.retry ? await this.ready(o.signal) : this.currentSession();
|
|
24900
|
+
const s = read ? await this.readyForRead(o.signal, !o.retry) : o.retry ? await this.ready({ signal: o.signal }) : this.currentSession();
|
|
24466
24901
|
try {
|
|
24467
|
-
const r = await s.request(method, p, {
|
|
24902
|
+
const r = await s.request(method, p, {
|
|
24903
|
+
...o.signal ? { signal: o.signal } : {},
|
|
24904
|
+
...codec ? { codec: plainAnswer(codec) } : {}
|
|
24905
|
+
});
|
|
24468
24906
|
if (read && (s !== this.session || s.closed || this.closing)) {
|
|
24469
24907
|
if (o.retry && !this.closing) continue;
|
|
24470
24908
|
throw mdbaseError("unavailable", "the session changed during the read", { reason: "reconnecting" });
|
|
@@ -24507,7 +24945,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24507
24945
|
if (this.fenceReads && this.session !== s) return;
|
|
24508
24946
|
let u;
|
|
24509
24947
|
try {
|
|
24510
|
-
u = queryUpdate
|
|
24948
|
+
u = decodePlain(queryUpdate, p);
|
|
24511
24949
|
} catch {
|
|
24512
24950
|
return;
|
|
24513
24951
|
}
|
|
@@ -24523,7 +24961,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24523
24961
|
});
|
|
24524
24962
|
s.onPush("receipt", (p) => {
|
|
24525
24963
|
try {
|
|
24526
|
-
const r = receipt
|
|
24964
|
+
const r = decodePlain(receipt, p);
|
|
24527
24965
|
if (this.session === s) this.noteReceipt(r);
|
|
24528
24966
|
const w = this.writes.get(r.mutation);
|
|
24529
24967
|
if (w) {
|
|
@@ -24552,7 +24990,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24552
24990
|
});
|
|
24553
24991
|
s.onPush("conflicts", (p) => {
|
|
24554
24992
|
try {
|
|
24555
|
-
this.emitConflicts(list(conflictEntry)
|
|
24993
|
+
this.emitConflicts(decodePlain(list(conflictEntry), p));
|
|
24556
24994
|
} catch {
|
|
24557
24995
|
}
|
|
24558
24996
|
});
|
|
@@ -24696,13 +25134,14 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24696
25134
|
* revalidate the authenticated session and all readiness gates after any await.
|
|
24697
25135
|
* Missing chain or any error means remain hosted; never substitute asOf or the
|
|
24698
25136
|
* current head/generations. Decoding does not authenticate a witness or switch.
|
|
25137
|
+
* `o.signal` cancels the read.
|
|
24699
25138
|
*/
|
|
24700
|
-
async appliedPrefix(seq2,
|
|
25139
|
+
async appliedPrefix(seq2, o = {}) {
|
|
24701
25140
|
const p = appliedPrefixParams.enc({ seq: seq2 });
|
|
24702
25141
|
const r = await this.call("applied_prefix", p, {
|
|
24703
25142
|
codec: appliedPrefix,
|
|
24704
25143
|
retry: false,
|
|
24705
|
-
...signal ? { signal } : {}
|
|
25144
|
+
...o.signal ? { signal: o.signal } : {}
|
|
24706
25145
|
});
|
|
24707
25146
|
if (r.seq !== seq2 || r.chain !== void 0 && (seq2 === 0 || r.appliedThrough < seq2)) {
|
|
24708
25147
|
throw mdbaseError("invalid_request", "applied_prefix: inconsistent historical proof", "prefix_response");
|
|
@@ -24734,9 +25173,9 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24734
25173
|
* definition and schema and each contract's schemas, bounded by the replica
|
|
24735
25174
|
* (`too_large` when over budget; read them with `resources.get` instead).
|
|
24736
25175
|
* A producer that cannot describe definitions fails `upgrade_required`.
|
|
25176
|
+
* `o.signal` cancels the read.
|
|
24737
25177
|
*/
|
|
24738
|
-
async describe(
|
|
24739
|
-
const o = options instanceof AbortSignal ? { signal: options } : options;
|
|
25178
|
+
async describe(o = {}) {
|
|
24740
25179
|
const result2 = await this.call("describe", o.definitions ? params([[0, true]]) : null, {
|
|
24741
25180
|
codec: describeResult,
|
|
24742
25181
|
retry: true,
|
|
@@ -24771,8 +25210,9 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24771
25210
|
* Core's temporal typing for top-level fields under a query's exact `types` OR list
|
|
24772
25211
|
* (`date` / `date_time` only when every type agrees; otherwise `none`). The answer is
|
|
24773
25212
|
* bound to a catalog generation; nested paths are `none`. The SDK never infers typing.
|
|
25213
|
+
* `o.signal` cancels the read.
|
|
24774
25214
|
*/
|
|
24775
|
-
describeTyping(types, paths,
|
|
25215
|
+
describeTyping(types, paths, o = {}) {
|
|
24776
25216
|
const strings = (a, max) => Array.isArray(a) && a.length <= max && a.every((s) => typeof s === "string" && s.length > 0 && s.length <= 1024);
|
|
24777
25217
|
if (!strings(types, DESCRIBE_TYPING_MAX_TYPES) || !strings(paths, DESCRIBE_TYPING_MAX_PATHS)) {
|
|
24778
25218
|
return Promise.reject(mdbaseError("invalid_request", "describe_typing: at most 64 types and 256 non-empty paths", "typing_bounds"));
|
|
@@ -24780,7 +25220,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24780
25220
|
return this.call("describe_typing", params([[0, [...types]], [1, [...paths]]]), {
|
|
24781
25221
|
codec: describeTypingResult,
|
|
24782
25222
|
retry: true,
|
|
24783
|
-
...signal ? { signal } : {}
|
|
25223
|
+
...o.signal ? { signal: o.signal } : {}
|
|
24784
25224
|
}).then((r) => {
|
|
24785
25225
|
if (r.fields.length !== paths.length || r.fields.some((f, i) => f.path !== paths[i])) {
|
|
24786
25226
|
throw mdbaseError("internal", "describe_typing answered for different paths", "invalid_typing_response");
|
|
@@ -24788,15 +25228,16 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24788
25228
|
return r;
|
|
24789
25229
|
});
|
|
24790
25230
|
}
|
|
24791
|
-
/** One record by ID or path. Throws `not_found`.
|
|
24792
|
-
|
|
25231
|
+
/** One record by ID or path. Throws `not_found`. `o.include` adds the body
|
|
25232
|
+
* and other parts to the record; `o.signal` cancels the read. */
|
|
25233
|
+
get(ref, o = {}) {
|
|
24793
25234
|
return this.call(
|
|
24794
25235
|
"get",
|
|
24795
25236
|
params([
|
|
24796
25237
|
[0, refValue(ref)],
|
|
24797
|
-
[1, includeValue(
|
|
25238
|
+
[1, includeValue(o.include)]
|
|
24798
25239
|
]),
|
|
24799
|
-
{ codec: recordView, retry: true, ...signal ? { signal } : {} }
|
|
25240
|
+
{ codec: recordView, retry: true, ...o.signal ? { signal: o.signal } : {} }
|
|
24800
25241
|
);
|
|
24801
25242
|
}
|
|
24802
25243
|
/**
|
|
@@ -24806,15 +25247,16 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24806
25247
|
* `invalid_request`/`data_contract_ambiguous` (select `type`; details: the types),
|
|
24807
25248
|
* `invalid_record`/`data_contract_record_invalid` (with issues), and
|
|
24808
25249
|
* `upgrade_required`/`contract_records_unsupported` from an older replica.
|
|
25250
|
+
* `o.signal` cancels the read.
|
|
24809
25251
|
*/
|
|
24810
|
-
async getContract(ref, contract,
|
|
25252
|
+
async getContract(ref, contract, o = {}) {
|
|
24811
25253
|
const r = await this.contractCall("get_contract_v1", params([
|
|
24812
25254
|
[0, 1],
|
|
24813
25255
|
[1, refValue(ref)],
|
|
24814
25256
|
[2, contract.id],
|
|
24815
25257
|
[3, contract.version],
|
|
24816
25258
|
[4, contract.type]
|
|
24817
|
-
]), contractRecordWire, signal);
|
|
25259
|
+
]), (answer) => decodePlain(contractRecordWire, answer), o.signal);
|
|
24818
25260
|
if (r.version !== 1) throw mdbaseError("upgrade_required", "unsupported contract record", "contract_records_unsupported");
|
|
24819
25261
|
return {
|
|
24820
25262
|
id: r.id,
|
|
@@ -24835,27 +25277,38 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24835
25277
|
[5, fields3],
|
|
24836
25278
|
[6, unset?.length ? unset : void 0],
|
|
24837
25279
|
[7, promote ? true : void 0]
|
|
24838
|
-
|
|
25280
|
+
// Exact: the plan's patch and base go back in an op unchanged.
|
|
25281
|
+
]), contractWritePlan.dec, signal);
|
|
24839
25282
|
if (plan.version !== 1) throw mdbaseError("upgrade_required", "unsupported contract write plan", "contract_records_unsupported");
|
|
24840
25283
|
return plan;
|
|
24841
25284
|
}
|
|
24842
|
-
contractCall(method, p,
|
|
24843
|
-
|
|
25285
|
+
async contractCall(method, p, decode3, signal) {
|
|
25286
|
+
let answer;
|
|
25287
|
+
try {
|
|
25288
|
+
answer = await this.call(method, p, { retry: true, ...signal ? { signal } : {} });
|
|
25289
|
+
} catch (e) {
|
|
24844
25290
|
if (isMdbaseError(e, "invalid_request") && e.reason === "unknown_method") {
|
|
24845
25291
|
throw mdbaseError("upgrade_required", "this replica does not serve contract-scoped records", "contract_records_unsupported");
|
|
24846
25292
|
}
|
|
24847
25293
|
throw e;
|
|
24848
|
-
}
|
|
25294
|
+
}
|
|
25295
|
+
try {
|
|
25296
|
+
return decode3(answer);
|
|
25297
|
+
} catch (e) {
|
|
25298
|
+
throw schemaToError(e, `${method} result`);
|
|
25299
|
+
}
|
|
24849
25300
|
}
|
|
24850
25301
|
/** Bounded ordered ordinary gets. Missing/refused reads fail the batch;
|
|
24851
|
-
* duplicate slots and the original signal are retained, not a snapshot.
|
|
24852
|
-
|
|
24853
|
-
|
|
24854
|
-
}
|
|
24855
|
-
|
|
24856
|
-
|
|
25302
|
+
* duplicate slots and the original signal are retained, not a snapshot.
|
|
25303
|
+
* `o.include` and `o.signal` apply to every get; `o.concurrency` bounds the
|
|
25304
|
+
* gets in flight. */
|
|
25305
|
+
readMany(refs, o = {}) {
|
|
25306
|
+
return readMany(this, refs, o);
|
|
25307
|
+
}
|
|
25308
|
+
/** One record, or `null` when there is none. `o` is as for {@link get}. */
|
|
25309
|
+
async find(ref, o = {}) {
|
|
24857
25310
|
try {
|
|
24858
|
-
return await this.get(ref,
|
|
25311
|
+
return await this.get(ref, o);
|
|
24859
25312
|
} catch (e) {
|
|
24860
25313
|
if (isMdbaseError(e, "not_found")) return null;
|
|
24861
25314
|
throw e;
|
|
@@ -24864,19 +25317,21 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24864
25317
|
/**
|
|
24865
25318
|
* One page of a query, evaluated by the replica (body predicates and links
|
|
24866
25319
|
* included, §4). Pass `result.cursor` back as `query.cursor` for the next.
|
|
24867
|
-
* `
|
|
25320
|
+
* `o.include` adds the body and other parts to each record; `o.signal`
|
|
25321
|
+
* cancels the read.
|
|
25322
|
+
* `o.contract` is not supported by the live replica dispatch. Supplying it
|
|
24868
25323
|
* returns `invalid_request` with reason `unknown_param`; no contract filter
|
|
24869
25324
|
* is applied. The option remains encoded unchanged for API compatibility.
|
|
24870
25325
|
*/
|
|
24871
|
-
query(query,
|
|
25326
|
+
query(query, o = {}) {
|
|
24872
25327
|
return this.call(
|
|
24873
25328
|
"query",
|
|
24874
25329
|
params([
|
|
24875
25330
|
[0, toValue(query)],
|
|
24876
|
-
[1, includeValue(
|
|
24877
|
-
[2,
|
|
25331
|
+
[1, includeValue(o.include)],
|
|
25332
|
+
[2, o.contract]
|
|
24878
25333
|
]),
|
|
24879
|
-
{ codec: queryResult, retry: true, ...signal ? { signal } : {} }
|
|
25334
|
+
{ codec: queryResult, retry: true, ...o.signal ? { signal: o.signal } : {} }
|
|
24880
25335
|
);
|
|
24881
25336
|
}
|
|
24882
25337
|
/** Canonical contract projections with validation issues and ordinary cursor
|
|
@@ -24958,7 +25413,8 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24958
25413
|
}
|
|
24959
25414
|
/** Definitions: `mdbase.yaml`, type files, contract files (§4.1). */
|
|
24960
25415
|
resources = {
|
|
24961
|
-
|
|
25416
|
+
/** One definition by path. `o.signal` cancels the read. */
|
|
25417
|
+
get: (path, o = {}) => this.call("get_resource", params([[0, path]]), { codec: resourceView, retry: true, ...o.signal ? { signal: o.signal } : {} }),
|
|
24962
25418
|
/** One bounded resource inventory page. Text defaults to false; limit defaults
|
|
24963
25419
|
* to 64 (maximum 128). Preserve folder/text/limit on continuation. Collect all
|
|
24964
25420
|
* pages before assessing a complete snapshot; stale/expired cursors require
|
|
@@ -24981,18 +25437,18 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
24981
25437
|
if (o.baseRevision && o.mustNotExist) {
|
|
24982
25438
|
return Promise.reject(mdbaseError("invalid_request", "baseRevision and mustNotExist are exclusive"));
|
|
24983
25439
|
}
|
|
24984
|
-
return this.
|
|
24985
|
-
{
|
|
25440
|
+
return this.submit(
|
|
25441
|
+
[{
|
|
24986
25442
|
kind: "resource_put",
|
|
24987
25443
|
path,
|
|
24988
25444
|
doc,
|
|
24989
25445
|
...o.baseRevision ? { baseRevision: o.baseRevision } : {},
|
|
24990
25446
|
...o.mustNotExist ? { mustNotExist: true } : {}
|
|
24991
|
-
},
|
|
25447
|
+
}],
|
|
24992
25448
|
o
|
|
24993
25449
|
);
|
|
24994
25450
|
},
|
|
24995
|
-
delete: (path, o = {}) => this.
|
|
25451
|
+
delete: (path, o = {}) => this.submit([{ kind: "resource_delete", path, ...o.baseRevision ? { baseRevision: o.baseRevision } : {} }], o)
|
|
24996
25452
|
};
|
|
24997
25453
|
/** Type packs: `plan` (writes nothing), review, then `apply(plan)` as one
|
|
24998
25454
|
* guarded all-or-nothing mutation (needs `definitions.manage`). */
|
|
@@ -25010,19 +25466,24 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25010
25466
|
updateSource: (seen, document, options) => updateViewSource(this, seen, document, options),
|
|
25011
25467
|
getSourceRecord: (source, options = {}) => readViewSourceRecord(this, source, options),
|
|
25012
25468
|
/** `mdbase.view` sources (spec 12 `list_views` shape), resolved over served
|
|
25013
|
-
* contract queries: the native runtime has no `list_views` RPC.
|
|
25014
|
-
|
|
25469
|
+
* contract queries: the native runtime has no `list_views` RPC. `o.folder`
|
|
25470
|
+
* keeps the sources under one folder; `o.signal` cancels the read. */
|
|
25471
|
+
list: (o = {}) => listSavedViews(this, o),
|
|
25015
25472
|
/** Spec 11 named-view resolution, executed as one ordinary native query. */
|
|
25016
25473
|
execute: (source, view, o = {}) => executeSavedView(this, source, view, o),
|
|
25017
|
-
|
|
25474
|
+
/** The current source document of one `mdbase.view` record. `o.signal`
|
|
25475
|
+
* cancels the read. */
|
|
25476
|
+
readSource: (source, o = {}) => readSavedViewSource(this, source, o)
|
|
25018
25477
|
};
|
|
25019
25478
|
/**
|
|
25020
25479
|
* Pending mutations of this session's owner (its grant, or the device), oldest
|
|
25021
25480
|
* first (§6): a new session after a reload sees writes made before it. Follow
|
|
25022
25481
|
* each with `awaitReceipt`, or keep the `mutationId` you chose and call
|
|
25023
|
-
* `receipt(id)` / `awaitReceipt(id)`. Pages through everything.
|
|
25482
|
+
* `receipt(id)` / `awaitReceipt(id)`. Pages through everything; `o.signal`
|
|
25483
|
+
* cancels the read.
|
|
25024
25484
|
*/
|
|
25025
|
-
async pendingWrites(
|
|
25485
|
+
async pendingWrites(o = {}) {
|
|
25486
|
+
const signal = o.signal;
|
|
25026
25487
|
const out = [];
|
|
25027
25488
|
let after;
|
|
25028
25489
|
for (; ; ) {
|
|
@@ -25048,27 +25509,30 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25048
25509
|
return this.preflight({ kind: "delete", id: refId(target2) });
|
|
25049
25510
|
}
|
|
25050
25511
|
async preflight(op2) {
|
|
25051
|
-
const
|
|
25052
|
-
const r = w.receipt;
|
|
25512
|
+
const r = (await this.submit([op2], { dryRun: true })).receipt;
|
|
25053
25513
|
if (r.state === "rejected") throw new MdbaseError(r.problem);
|
|
25054
25514
|
return r.preflight ?? { rewrites: [], broken: [] };
|
|
25055
25515
|
}
|
|
25056
|
-
/** Every page of a query.
|
|
25057
|
-
*
|
|
25058
|
-
|
|
25516
|
+
/** Every page of a query. `o.include` and `o.signal` apply to every page.
|
|
25517
|
+
* Cursor resets require explicit caller clearing through `o.onReset`;
|
|
25518
|
+
* otherwise cursor_expired/cursor_stale is thrown unchanged. The query and
|
|
25519
|
+
* `o` are captured when iteration starts. */
|
|
25520
|
+
async *pages(query, o = {}) {
|
|
25521
|
+
const { include: include3, signal, onReset } = o;
|
|
25059
25522
|
const original = snapshotQueryValue(query);
|
|
25060
25523
|
const originalInclude = include3 ? { ...include3 } : void 0;
|
|
25524
|
+
const read = { ...originalInclude ? { include: originalInclude } : {}, ...signal ? { signal } : {} };
|
|
25061
25525
|
let cursor = original.cursor, restarted = false, pagesYielded = 0;
|
|
25062
25526
|
delete original.cursor;
|
|
25063
25527
|
for (; ; ) {
|
|
25064
25528
|
signal?.throwIfAborted();
|
|
25065
25529
|
let page;
|
|
25066
25530
|
try {
|
|
25067
|
-
page = await this.query(cursor !== void 0 ? { ...original, cursor } : { ...original },
|
|
25531
|
+
page = await this.query(cursor !== void 0 ? { ...original, cursor } : { ...original }, read);
|
|
25068
25532
|
} catch (error4) {
|
|
25069
|
-
if (!
|
|
25533
|
+
if (!onReset || restarted || !isMdbaseError(error4, "invalid_request") || error4.recovery !== "fix_request" || error4.reason !== "cursor_expired" && error4.reason !== "cursor_stale") throw error4;
|
|
25070
25534
|
signal?.throwIfAborted();
|
|
25071
|
-
await
|
|
25535
|
+
await onReset({ reason: error4.reason, error: error4, pagesYielded, ...signal ? { signal } : {} });
|
|
25072
25536
|
signal?.throwIfAborted();
|
|
25073
25537
|
restarted = true;
|
|
25074
25538
|
cursor = void 0;
|
|
@@ -25085,16 +25549,29 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25085
25549
|
cursor = page.cursor;
|
|
25086
25550
|
}
|
|
25087
25551
|
}
|
|
25088
|
-
/** Shared alias of pages(): whole native pages, no implicit cursor reset.
|
|
25089
|
-
|
|
25090
|
-
|
|
25552
|
+
/** Shared alias of pages(): whole native pages, no implicit cursor reset.
|
|
25553
|
+
* `o.include` and `o.signal` apply to every page; `o.onReset` opts in to one
|
|
25554
|
+
* first-page restart. */
|
|
25555
|
+
queryPages(query, o = {}) {
|
|
25556
|
+
return queryPages(this, query, o);
|
|
25091
25557
|
}
|
|
25092
25558
|
/**
|
|
25093
|
-
*
|
|
25094
|
-
*
|
|
25559
|
+
* Every record of the chosen types (default: all), read completely and then
|
|
25560
|
+
* kept current: the set an app lists, searches and renders from. Close it
|
|
25561
|
+
* when done.
|
|
25095
25562
|
*/
|
|
25096
|
-
|
|
25097
|
-
|
|
25563
|
+
recordSet(options = {}) {
|
|
25564
|
+
return new RecordSet(this, options);
|
|
25565
|
+
}
|
|
25566
|
+
/**
|
|
25567
|
+
* A live query: one window of at most 1,000 records and 1 MiB, with the
|
|
25568
|
+
* replica's order and counts. Subscribe for pushes; keep lists cheap with a
|
|
25569
|
+
* `limit` window and no bodies, and widen the window with `setQuery`. For a
|
|
25570
|
+
* whole collection use `recordSet`. `o.include` adds the body and other
|
|
25571
|
+
* parts to each record.
|
|
25572
|
+
*/
|
|
25573
|
+
live(query, o = {}) {
|
|
25574
|
+
const l = new LiveQuery(this, query, o.include);
|
|
25098
25575
|
this.lives.add(l);
|
|
25099
25576
|
void this._resubscribeLive(l, true);
|
|
25100
25577
|
return l;
|
|
@@ -25145,25 +25622,28 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25145
25622
|
});
|
|
25146
25623
|
}
|
|
25147
25624
|
}
|
|
25148
|
-
/** One page of the change feed
|
|
25149
|
-
|
|
25625
|
+
/** One page of the change feed, from `o.cursor` (default: the start) and of
|
|
25626
|
+
* at most `o.limit` changes. A `reset: true` result means "re-read what you
|
|
25627
|
+
* cache". `o.signal` cancels the read. */
|
|
25628
|
+
changes(o = {}) {
|
|
25150
25629
|
return this.call(
|
|
25151
25630
|
"changes",
|
|
25152
25631
|
params([
|
|
25153
|
-
[0, cursor ?? null],
|
|
25154
|
-
[1, limit]
|
|
25632
|
+
[0, o.cursor ?? null],
|
|
25633
|
+
[1, o.limit]
|
|
25155
25634
|
]),
|
|
25156
|
-
{ codec: changesResult, retry: true, ...signal ? { signal } : {} }
|
|
25635
|
+
{ codec: changesResult, retry: true, ...o.signal ? { signal: o.signal } : {} }
|
|
25157
25636
|
);
|
|
25158
25637
|
}
|
|
25159
25638
|
/**
|
|
25160
|
-
* Follow the change feed from `cursor
|
|
25161
|
-
* means the app must re-read what it caches. Survives
|
|
25639
|
+
* Follow the change feed from `o.cursor` (default: the start). `onChanges` gets
|
|
25640
|
+
* every batch; `reset: true` means the app must re-read what it caches. Survives
|
|
25641
|
+
* reconnects.
|
|
25162
25642
|
* `ready` confirms the first watch ACK, not a complete/current collection cache.
|
|
25163
25643
|
* After reconnect, observe `state`; an already-resolved promise is not freshness.
|
|
25164
25644
|
*/
|
|
25165
|
-
watchChanges(
|
|
25166
|
-
let last = cursor, stopped = false, epoch = 0;
|
|
25645
|
+
watchChanges(onChanges, o = {}) {
|
|
25646
|
+
let last = o.cursor, stopped = false, epoch = 0;
|
|
25167
25647
|
let state = "starting", error4 = null;
|
|
25168
25648
|
let active = null, controller = null;
|
|
25169
25649
|
let offPush = null, offClose = null;
|
|
@@ -25284,10 +25764,16 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25284
25764
|
publish("starting");
|
|
25285
25765
|
if (!current2()) return;
|
|
25286
25766
|
try {
|
|
25287
|
-
|
|
25288
|
-
|
|
25289
|
-
|
|
25290
|
-
|
|
25767
|
+
let page = await s.request("changes", params([[0, last ?? null], [1, CHANGES_PAGE], [2, true]]), { codec: changesResult, signal });
|
|
25768
|
+
for (; ; ) {
|
|
25769
|
+
if (!current2()) return;
|
|
25770
|
+
last = page.cursor;
|
|
25771
|
+
if (page.changes.length || page.reset) deliver(page);
|
|
25772
|
+
if (!current2()) return;
|
|
25773
|
+
if (page.changes.length < CHANGES_PAGE) break;
|
|
25774
|
+
clearEarly();
|
|
25775
|
+
page = await s.request("changes", params([[0, last], [1, CHANGES_PAGE]]), { codec: changesResult, signal });
|
|
25776
|
+
}
|
|
25291
25777
|
while (early.length && current2()) deliver(early.shift());
|
|
25292
25778
|
clearEarly();
|
|
25293
25779
|
initial = false;
|
|
@@ -25316,13 +25802,15 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25316
25802
|
Object.defineProperties(watch, { state: { get: () => state }, error: { get: () => error4 } });
|
|
25317
25803
|
return Object.freeze(watch);
|
|
25318
25804
|
}
|
|
25319
|
-
/** Validate
|
|
25805
|
+
/** Validate `o.refs`, or every record without them. Every record is validated a
|
|
25320
25806
|
* page at a time when the replica grants `validate-page-v1`; each page is an
|
|
25321
25807
|
* independent READ, so records changed meanwhile may be missed or repeated.
|
|
25322
|
-
* Older replicas validate every record in one bounded request.
|
|
25323
|
-
|
|
25808
|
+
* Older replicas validate every record in one bounded request. `o.signal`
|
|
25809
|
+
* cancels the read. */
|
|
25810
|
+
async validate(o = {}) {
|
|
25811
|
+
const signal = o.signal;
|
|
25324
25812
|
signal?.throwIfAborted();
|
|
25325
|
-
const { targets: targets2, expected } = captureValidation(refs);
|
|
25813
|
+
const { targets: targets2, expected } = captureValidation(o.refs);
|
|
25326
25814
|
const call2 = (p) => this.call("validate", p, {
|
|
25327
25815
|
codec: recordValidations,
|
|
25328
25816
|
retry: true,
|
|
@@ -25344,8 +25832,10 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25344
25832
|
}
|
|
25345
25833
|
}
|
|
25346
25834
|
/** Independent native app-host Bases READ, exact original held session.
|
|
25347
|
-
* Unsupported transports refuse: no generic execute_view/data fallback.
|
|
25348
|
-
|
|
25835
|
+
* Unsupported transports refuse: no generic execute_view/data fallback.
|
|
25836
|
+
* `o.signal` cancels the read. */
|
|
25837
|
+
async executeAppBases(request3, o = {}) {
|
|
25838
|
+
const signal = o.signal;
|
|
25349
25839
|
const window = request3.window === void 0 ? null : { ...request3.window };
|
|
25350
25840
|
const bytes10 = encodeAppBasesRequest({ ...request3, ...window === null ? {} : { window } });
|
|
25351
25841
|
const session = await this.readyForRead(signal);
|
|
@@ -25361,11 +25851,13 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25361
25851
|
* `executeViewPages`). Each page is an independent READ; `changedSinceFirst`
|
|
25362
25852
|
* marks pages taken after the collection changed. */
|
|
25363
25853
|
executeAppBasesPages(request3, options = {}) {
|
|
25364
|
-
return appBasesPages((r, signal) => this.executeAppBases(r, signal), request3, options);
|
|
25854
|
+
return appBasesPages((r, signal) => this.executeAppBases(r, signal ? { signal } : {}), request3, options);
|
|
25365
25855
|
}
|
|
25366
25856
|
/** One bounded native discovery page. Empty views do not mean EOF when a
|
|
25367
|
-
* continuation is present. Supplied handles never silently restart/retry.
|
|
25368
|
-
|
|
25857
|
+
* continuation is present. Supplied handles never silently restart/retry.
|
|
25858
|
+
* `o.signal` cancels the read. */
|
|
25859
|
+
async listAppBasesViews(request3, o = {}) {
|
|
25860
|
+
const signal = o.signal;
|
|
25369
25861
|
const limit = request3.limit, bytes10 = encodeAppBasesDiscoveryRequest(request3);
|
|
25370
25862
|
const session = await this.readyForRead(signal);
|
|
25371
25863
|
const reply = await session.readAppBasesDiscovery("list-views", bytes10, signal);
|
|
@@ -25379,8 +25871,10 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25379
25871
|
}
|
|
25380
25872
|
}
|
|
25381
25873
|
/** Exact current source for one native UUID/SHA/original ordinal, never path
|
|
25382
|
-
* aliases, inferred catalog entries, generic RPC or cached document fallback.
|
|
25383
|
-
|
|
25874
|
+
* aliases, inferred catalog entries, generic RPC or cached document fallback.
|
|
25875
|
+
* `o.signal` cancels the read. */
|
|
25876
|
+
async readAppBasesViewSource(request3, o = {}) {
|
|
25877
|
+
const signal = o.signal;
|
|
25384
25878
|
const original = { ...request3 }, bytes10 = encodeAppBasesSourceRequest(original);
|
|
25385
25879
|
const session = await this.readyForRead(signal);
|
|
25386
25880
|
const reply = await session.readAppBasesDiscovery("read-view-source", bytes10, signal);
|
|
@@ -25394,15 +25888,12 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25394
25888
|
}
|
|
25395
25889
|
}
|
|
25396
25890
|
// ---------------------------------------------------------------- writes (§5, §6)
|
|
25397
|
-
/** Submit operations as one mutation
|
|
25891
|
+
/** Submit operations as one mutation: they apply together or not at all. */
|
|
25398
25892
|
async submit(ops, o = {}) {
|
|
25399
25893
|
if (this.hello.version.minor >= 3 && this.hello.grant.role === "viewer") throw mdbaseError("forbidden", "You have view access, so changes can't be saved.", "read_only");
|
|
25400
25894
|
if (o.intent !== void 0 && o.mutationId === void 0) o = { ...o, mutationId: (await intentIds(this.collectionId, o.intent))[0] };
|
|
25401
|
-
const
|
|
25402
|
-
|
|
25403
|
-
p.allowPartial = true;
|
|
25404
|
-
p.mutationIds = ops.map((_, i) => i === 0 ? p.mutationId : uuidv7());
|
|
25405
|
-
}
|
|
25895
|
+
const mutationId = o.mutationId ?? uuidv7();
|
|
25896
|
+
const p = { ops, mutationId };
|
|
25406
25897
|
if (o.conflictMode) p.conflictMode = o.conflictMode;
|
|
25407
25898
|
if (o.timezone) p.timezone = o.timezone;
|
|
25408
25899
|
if (o.dryRun) p.dryRun = true;
|
|
@@ -25411,25 +25902,26 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25411
25902
|
if (o.validation) p.validation = o.validation;
|
|
25412
25903
|
if (!o.dryRun) {
|
|
25413
25904
|
this.startLedger();
|
|
25414
|
-
await this.writeLedger.begin(
|
|
25905
|
+
await this.writeLedger.begin(mutationId, ops);
|
|
25415
25906
|
}
|
|
25416
|
-
let
|
|
25907
|
+
let receipt3;
|
|
25417
25908
|
try {
|
|
25418
|
-
receipts = await this.call("submit", submitParams.enc(p), {
|
|
25909
|
+
const receipts = await this.call("submit", submitParams.enc(p), {
|
|
25419
25910
|
codec: submitResult,
|
|
25420
25911
|
retry: true,
|
|
25421
25912
|
...o.signal ? { signal: o.signal } : {}
|
|
25422
25913
|
});
|
|
25914
|
+
if (receipts.length !== 1) throw mdbaseError("internal", "submit answered without exactly one receipt", "invalid_submit_response");
|
|
25915
|
+
receipt3 = receipts[0];
|
|
25423
25916
|
} catch (e) {
|
|
25424
25917
|
if (o.dryRun) throw e;
|
|
25425
|
-
void this.writeLedger.
|
|
25426
|
-
throw withMutation(e, "submit",
|
|
25918
|
+
void this.writeLedger.settle(mutationId);
|
|
25919
|
+
throw withMutation(e, "submit", { mutationId });
|
|
25427
25920
|
}
|
|
25428
|
-
return
|
|
25921
|
+
return o.dryRun ? new Write(receipt3) : this._track(receipt3);
|
|
25429
25922
|
}
|
|
25430
|
-
async
|
|
25431
|
-
|
|
25432
|
-
return w;
|
|
25923
|
+
async record(op2, o) {
|
|
25924
|
+
return Object.assign(await this.submit([op2], o), { recordId: op2.id });
|
|
25433
25925
|
}
|
|
25434
25926
|
/** Create a record. The ID is minted here, so the app can use it before confirmation. */
|
|
25435
25927
|
create(input, o = {}) {
|
|
@@ -25442,7 +25934,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25442
25934
|
if (input.frontmatter !== void 0) op2.frontmatter = toFmMap(input.frontmatter);
|
|
25443
25935
|
if (input.body !== void 0) op2.body = input.body;
|
|
25444
25936
|
if (input.document !== void 0) op2.document = input.document;
|
|
25445
|
-
return this.
|
|
25937
|
+
return this.record(op2, o);
|
|
25446
25938
|
}
|
|
25447
25939
|
async createThroughContract(input, contract, o) {
|
|
25448
25940
|
if (input.document !== void 0) throw mdbaseError("invalid_request", "a contract create takes frontmatter fields, not a document");
|
|
@@ -25454,7 +25946,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25454
25946
|
const op2 = { kind: "create", id: input.id ?? uuidv7(), type: plan.type, frontmatter: plan.patch };
|
|
25455
25947
|
if (input.path !== void 0) op2.path = input.path;
|
|
25456
25948
|
if (input.body !== void 0) op2.body = input.body;
|
|
25457
|
-
return
|
|
25949
|
+
return this.record(op2, o);
|
|
25458
25950
|
}
|
|
25459
25951
|
/**
|
|
25460
25952
|
* Update a record by field-level intent. Pass the `RecordView` you edited from, and
|
|
@@ -25463,7 +25955,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25463
25955
|
*/
|
|
25464
25956
|
update(target2, changes, o = {}) {
|
|
25465
25957
|
if (changes.contract) return this.updateThroughContract(target2, changes, changes.contract, o);
|
|
25466
|
-
return this.
|
|
25958
|
+
return this.record(this.updateOp(target2, changes), o);
|
|
25467
25959
|
}
|
|
25468
25960
|
async updateThroughContract(target2, c, contract, o) {
|
|
25469
25961
|
if (c.add || c.remove) {
|
|
@@ -25481,7 +25973,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25481
25973
|
if (plan.base.length) op2.base = plan.base;
|
|
25482
25974
|
if (c.updateRefs !== void 0) op2.updateRefs = c.updateRefs;
|
|
25483
25975
|
if (c.ifRevision) op2.ifRevision = c.ifRevision;
|
|
25484
|
-
return this.
|
|
25976
|
+
return this.record(op2, o);
|
|
25485
25977
|
}
|
|
25486
25978
|
/** Build an `update` op (exposed for batching with `submit`). */
|
|
25487
25979
|
updateOp(target2, c) {
|
|
@@ -25515,15 +26007,15 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25515
26007
|
const base = [];
|
|
25516
26008
|
const touched = [...op2.patch?.keys() ?? [], ...op2.unset ?? []];
|
|
25517
26009
|
for (const k of new Set(touched)) {
|
|
25518
|
-
const v = seen.frontmatter.
|
|
25519
|
-
base.push(v === void 0 ? { key: k } : { key: k, observed: v });
|
|
26010
|
+
const v = Object.hasOwn(seen.frontmatter, k) ? seen.frontmatter[k] : void 0;
|
|
26011
|
+
base.push(v === void 0 ? { key: k } : { key: k, observed: toValue(v) });
|
|
25520
26012
|
}
|
|
25521
26013
|
if (base.length) op2.base = base;
|
|
25522
26014
|
}
|
|
25523
26015
|
if (seen && op2.patch) {
|
|
25524
26016
|
for (const [k, v] of [...op2.patch]) {
|
|
25525
|
-
const cur = seen.frontmatter.
|
|
25526
|
-
if (cur !== void 0 && valueEquals(cur, v)) {
|
|
26017
|
+
const cur = Object.hasOwn(seen.frontmatter, k) ? seen.frontmatter[k] : void 0;
|
|
26018
|
+
if (cur !== void 0 && valueEquals(toValue(cur), v)) {
|
|
25527
26019
|
op2.patch.delete(k);
|
|
25528
26020
|
op2.base = op2.base?.filter((b) => b.key !== k);
|
|
25529
26021
|
}
|
|
@@ -25540,7 +26032,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25540
26032
|
if (!seen) throw mdbaseError("invalid_request", "replaceDocument needs the RecordView it was edited from");
|
|
25541
26033
|
if (seen.document !== void 0) op2.base = { path: seen.path, doc: seen.document };
|
|
25542
26034
|
if (o.ifRevision) op2.ifRevision = o.ifRevision;
|
|
25543
|
-
return this.
|
|
26035
|
+
return this.record(op2, o);
|
|
25544
26036
|
}
|
|
25545
26037
|
/**
|
|
25546
26038
|
* Delete a record. With a RecordView, a concurrent change supersedes the delete.
|
|
@@ -25553,13 +26045,13 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25553
26045
|
return this.contractPlan(contract, target2, void 0, void 0, o.signal).then((plan) => {
|
|
25554
26046
|
const op3 = { kind: "delete", id: plan.id, baseRevision: plan.revision };
|
|
25555
26047
|
if (rest.ifRevision) op3.ifRevision = rest.ifRevision;
|
|
25556
|
-
return this.
|
|
26048
|
+
return this.record(op3, rest);
|
|
25557
26049
|
});
|
|
25558
26050
|
}
|
|
25559
26051
|
const op2 = { kind: "delete", id: refId(target2) };
|
|
25560
26052
|
if (typeof target2 === "object" && "revision" in target2) op2.baseRevision = target2.revision;
|
|
25561
26053
|
if (o.ifRevision) op2.ifRevision = o.ifRevision;
|
|
25562
|
-
return this.
|
|
26054
|
+
return this.record(op2, o);
|
|
25563
26055
|
}
|
|
25564
26056
|
/** Rename (move) a record; `updateRefs` rewrites links to it (default true).
|
|
25565
26057
|
* With `contract`, the record must implement it, and moves from its current path. */
|
|
@@ -25570,7 +26062,7 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25570
26062
|
}
|
|
25571
26063
|
const op2 = { kind: "rename", id: target2.id, from: target2.path, to, updateRefs: o.updateRefs ?? true };
|
|
25572
26064
|
if (o.ifRevision) op2.ifRevision = o.ifRevision;
|
|
25573
|
-
return this.
|
|
26065
|
+
return this.record(op2, o);
|
|
25574
26066
|
}
|
|
25575
26067
|
/** @internal Track a receipt the replica returned outside `submit`. */
|
|
25576
26068
|
_track(r) {
|
|
@@ -25592,63 +26084,48 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25592
26084
|
return w;
|
|
25593
26085
|
}
|
|
25594
26086
|
/**
|
|
25595
|
-
* Settle a write for the
|
|
25596
|
-
*
|
|
25597
|
-
*
|
|
25598
|
-
*
|
|
26087
|
+
* Settle a write: wait for the sync service to confirm it (3 s by default),
|
|
26088
|
+
* and with `read`, read the record back as it now reads here.
|
|
26089
|
+
*
|
|
26090
|
+
* Pass the write, the promise of one, or the mutation ID of an earlier write
|
|
26091
|
+
* whose result was `unknown`. The answer is a {@link Settlement}; the only
|
|
26092
|
+
* rejections are cancellation and a call that cannot be settled as asked.
|
|
26093
|
+
* Nothing is ever submitted again.
|
|
26094
|
+
*
|
|
26095
|
+
* const saved = await db.settle(db.update(record, { patch }), { read: true });
|
|
26096
|
+
* if (saved.outcome === "rejected") show(describeError(saved.problem));
|
|
25599
26097
|
*/
|
|
25600
|
-
|
|
25601
|
-
|
|
25602
|
-
let r = w.receipt;
|
|
25603
|
-
if (r.state === "pending") {
|
|
25604
|
-
try {
|
|
25605
|
-
r = await this.awaitReceipt(w.mutationId, o.timeoutMs ?? 3e3, o.signal);
|
|
25606
|
-
w.update(r);
|
|
25607
|
-
} catch (e) {
|
|
25608
|
-
if (isMdbaseError(e, "cancelled")) throw e;
|
|
25609
|
-
r = w.receipt;
|
|
25610
|
-
}
|
|
25611
|
-
}
|
|
25612
|
-
const outcome = r.state === "confirmed" ? "confirmed" : r.state === "pending" ? "saved_on_device" : "rejected";
|
|
25613
|
-
const records2 = w.records;
|
|
25614
|
-
let record3 = records2[0];
|
|
25615
|
-
if (o.readBack && outcome !== "rejected" && record3) {
|
|
25616
|
-
record3 = await this.find(record3.id, void 0, o.signal).catch(() => null) ?? record3;
|
|
25617
|
-
}
|
|
25618
|
-
return Object.freeze({
|
|
25619
|
-
outcome,
|
|
25620
|
-
mutationId: w.mutationId,
|
|
25621
|
-
records: records2,
|
|
25622
|
-
...record3 ? { record: record3 } : {},
|
|
25623
|
-
...outcome === "rejected" && r.problem ? { problem: r.problem } : {}
|
|
25624
|
-
});
|
|
26098
|
+
settle(write, options = {}) {
|
|
26099
|
+
return settleWrite(this, write, options);
|
|
25625
26100
|
}
|
|
25626
|
-
/** The current receipt of a mutation. Failures carry `mutationId`. */
|
|
25627
|
-
receipt(mutation2,
|
|
26101
|
+
/** The current receipt of a mutation. Failures carry `mutationId`. `o.signal` cancels the read. */
|
|
26102
|
+
receipt(mutation2, o = {}) {
|
|
25628
26103
|
return this.call("receipt", params([[0, uuid2.enc(mutation2)]]), {
|
|
25629
26104
|
codec: receipt,
|
|
25630
26105
|
retry: true,
|
|
25631
|
-
...signal ? { signal } : {}
|
|
26106
|
+
...o.signal ? { signal: o.signal } : {}
|
|
25632
26107
|
}).catch((e) => {
|
|
25633
26108
|
throw withMutation(e, "receipt", { mutationId: mutation2 });
|
|
25634
26109
|
});
|
|
25635
26110
|
}
|
|
25636
|
-
/** Resolves when the receipt leaves `pending`, or at `timeoutMs` with the
|
|
25637
|
-
|
|
26111
|
+
/** Resolves when the receipt leaves `pending`, or at `o.timeoutMs` with the
|
|
26112
|
+
* pending receipt. `o.signal` cancels the wait. */
|
|
26113
|
+
awaitReceipt(mutation2, o = {}) {
|
|
25638
26114
|
return this.call(
|
|
25639
26115
|
"await",
|
|
25640
26116
|
params([
|
|
25641
26117
|
[0, uuid2.enc(mutation2)],
|
|
25642
|
-
[1, timeoutMs]
|
|
26118
|
+
[1, o.timeoutMs]
|
|
25643
26119
|
]),
|
|
25644
|
-
{ codec: receipt, retry: true, ...signal ? { signal } : {} }
|
|
26120
|
+
{ codec: receipt, retry: true, ...o.signal ? { signal: o.signal } : {} }
|
|
25645
26121
|
).catch((e) => {
|
|
25646
26122
|
throw withMutation(e, "await", { mutationId: mutation2 });
|
|
25647
26123
|
});
|
|
25648
26124
|
}
|
|
25649
26125
|
// ---------------------------------------------------------------- holds and conflicts (§8)
|
|
25650
|
-
|
|
25651
|
-
|
|
26126
|
+
/** The current holds. `o.signal` cancels the read. */
|
|
26127
|
+
listHolds(o = {}) {
|
|
26128
|
+
return this.call("list_holds", null, { codec: list(hold), retry: true, ...o.signal ? { signal: o.signal } : {} });
|
|
25652
26129
|
}
|
|
25653
26130
|
/** Call `fn` with the holds now and on every change. */
|
|
25654
26131
|
onHolds(fn) {
|
|
@@ -25680,11 +26157,12 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25680
26157
|
);
|
|
25681
26158
|
return this._track(r);
|
|
25682
26159
|
}
|
|
25683
|
-
|
|
25684
|
-
|
|
26160
|
+
/** The current conflicts, of `o.record` only when given. `o.signal` cancels the read. */
|
|
26161
|
+
listConflicts(o = {}) {
|
|
26162
|
+
return this.call("list_conflicts", o.record ? params([[0, uuid2.enc(o.record)]]) : null, {
|
|
25685
26163
|
codec: list(conflictEntry),
|
|
25686
26164
|
retry: true,
|
|
25687
|
-
...signal ? { signal } : {}
|
|
26165
|
+
...o.signal ? { signal: o.signal } : {}
|
|
25688
26166
|
});
|
|
25689
26167
|
}
|
|
25690
26168
|
onConflicts(fn) {
|
|
@@ -25705,18 +26183,17 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25705
26183
|
}
|
|
25706
26184
|
/** Accept what the record kept. */
|
|
25707
26185
|
dismissConflict(entry2, o = {}) {
|
|
25708
|
-
return this.
|
|
26186
|
+
return this.submit([{ kind: "conflict_dismiss", mutation: entry2.mutation, record: entry2.conflict.id }], o);
|
|
25709
26187
|
}
|
|
25710
26188
|
/** Resolve a field conflict with a chosen value, dismissing it in the same mutation. */
|
|
25711
|
-
|
|
25712
|
-
|
|
26189
|
+
resolveConflict(entry2, field, chosen, o = {}) {
|
|
26190
|
+
return this.submit(
|
|
25713
26191
|
[
|
|
25714
26192
|
{ kind: "update", id: entry2.conflict.id, patch: /* @__PURE__ */ new Map([[field, toValue(chosen)]]) },
|
|
25715
26193
|
{ kind: "conflict_dismiss", mutation: entry2.mutation, record: entry2.conflict.id }
|
|
25716
26194
|
],
|
|
25717
26195
|
o
|
|
25718
26196
|
);
|
|
25719
|
-
return w;
|
|
25720
26197
|
}
|
|
25721
26198
|
// ---------------------------------------------------------------- private collections (§8.3)
|
|
25722
26199
|
/**
|
|
@@ -25724,9 +26201,10 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25724
26201
|
* hosting the replica (no grant). `exchangeReady` is challenge/reveal readiness,
|
|
25725
26202
|
* NOT approval/key delivery. Once ready, `sas` is the host-only comparison code
|
|
25726
26203
|
* to display beside Allow; the user must check it matches on the other computer.
|
|
26204
|
+
* `o.signal` cancels the read.
|
|
25727
26205
|
*/
|
|
25728
|
-
pendingDevices(
|
|
25729
|
-
return this.call("pending_devices", null, { codec: list(pendingDevice), retry: true, ...signal ? { signal } : {} });
|
|
26206
|
+
pendingDevices(o = {}) {
|
|
26207
|
+
return this.call("pending_devices", null, { codec: list(pendingDevice), retry: true, ...o.signal ? { signal: o.signal } : {} });
|
|
25730
26208
|
}
|
|
25731
26209
|
/**
|
|
25732
26210
|
* Confirm with the six digits displayed for the current host exchange, only
|
|
@@ -25769,7 +26247,9 @@ var MdbaseClient = class _MdbaseClient {
|
|
|
25769
26247
|
accountSecret(secret);
|
|
25770
26248
|
await this.call("account_key_unlock", params([[0, secret]]));
|
|
25771
26249
|
},
|
|
25772
|
-
|
|
26250
|
+
/** Where an account-key unlock stands on this replica. `o.signal` cancels
|
|
26251
|
+
* the read. */
|
|
26252
|
+
status: (o = {}) => this.call("account_key_status", null, { codec: accountKeyStatus, retry: true, ...o.signal ? { signal: o.signal } : {} })
|
|
25773
26253
|
};
|
|
25774
26254
|
/** Recovery key for a private collection (hosting app only). */
|
|
25775
26255
|
recoveryKey = {
|
|
@@ -26593,13 +27073,12 @@ function keyWaitDetail(status) {
|
|
|
26593
27073
|
const found = status.incidents.find((incident2) => incident2.kind === "waiting_for_key");
|
|
26594
27074
|
if (!found) return null;
|
|
26595
27075
|
const out = { through: status.confirmedThrough, head: status.headKnown };
|
|
26596
|
-
const
|
|
26597
|
-
const get = (k) => d instanceof Map ? d.get(k) : d && typeof d === "object" ? d[k] : void 0;
|
|
27076
|
+
const get = (k) => fieldOf(found.details, k);
|
|
26598
27077
|
const reason = get("reason");
|
|
26599
27078
|
if (typeof reason === "string" && /^[a-z_]{1,32}$/.test(reason)) out.key = reason;
|
|
26600
27079
|
for (const k of ["position", "at"]) {
|
|
26601
27080
|
const v = get(k);
|
|
26602
|
-
if (typeof v === "number"
|
|
27081
|
+
if (typeof v === "number") out[k] = v;
|
|
26603
27082
|
}
|
|
26604
27083
|
return out;
|
|
26605
27084
|
}
|
|
@@ -27484,11 +27963,11 @@ var AppCpPrivateBootstrap = class {
|
|
|
27484
27963
|
const genesis = object6(result2.genesis);
|
|
27485
27964
|
if (genesis.seq !== 1) throw fail7("response");
|
|
27486
27965
|
const item = bytes6(genesis.item, 256 * 1024);
|
|
27487
|
-
const domain = new TextEncoder().encode("mdbase/v1/chain"),
|
|
27488
|
-
|
|
27489
|
-
|
|
27490
|
-
|
|
27491
|
-
const digest2 = new Uint8Array(await crypto.subtle.digest("SHA-256",
|
|
27966
|
+
const domain = new TextEncoder().encode("mdbase/v1/chain"), message2 = new Uint8Array(1 + domain.length + item.length);
|
|
27967
|
+
message2[0] = domain.length;
|
|
27968
|
+
message2.set(domain, 1);
|
|
27969
|
+
message2.set(item, 1 + domain.length);
|
|
27970
|
+
const digest2 = new Uint8Array(await crypto.subtle.digest("SHA-256", message2));
|
|
27492
27971
|
this.check(options.signal);
|
|
27493
27972
|
const metadata2 = this.copy({ collection: this.scope.collection, deviceId: this.scope.deviceId, logOrigin: this.scope.logOrigin, rootPublicKey: this.root, genesisItem: item, expectedGenesis: `sha256:${hex7(digest2)}`, approval: enrol ? "pending" : "creator", ...this.displayName === void 0 ? {} : { displayName: this.displayName } });
|
|
27494
27973
|
await this.persistence.completed(this.copy(metadata2), options);
|
|
@@ -27963,10 +28442,10 @@ function abytes2(value2, length, title = "") {
|
|
|
27963
28442
|
const bytes10 = isBytes2(value2);
|
|
27964
28443
|
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
27965
28444
|
const got = bytes10 ? `length=${value2.length}` : `type=${typeof value2}`;
|
|
27966
|
-
const
|
|
28445
|
+
const message2 = atitle2(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
27967
28446
|
if (!bytes10)
|
|
27968
|
-
throw new TypeError(
|
|
27969
|
-
throw new RangeError(
|
|
28447
|
+
throw new TypeError(message2);
|
|
28448
|
+
throw new RangeError(message2);
|
|
27970
28449
|
}
|
|
27971
28450
|
var aobject2 = (value2, label) => {
|
|
27972
28451
|
if (value2 === null || typeof value2 !== "object" || Array.isArray(value2))
|
|
@@ -31310,7 +31789,7 @@ var _HMAC = class {
|
|
|
31310
31789
|
}
|
|
31311
31790
|
};
|
|
31312
31791
|
var hmac = /* @__PURE__ */ (() => {
|
|
31313
|
-
const hmac_ = ((hash2, key3,
|
|
31792
|
+
const hmac_ = ((hash2, key3, message2) => new _HMAC(hash2, key3).update(message2).digest());
|
|
31314
31793
|
hmac_.create = (hash2, key3) => new _HMAC(hash2, key3);
|
|
31315
31794
|
return hmac_;
|
|
31316
31795
|
})();
|
|
@@ -31382,15 +31861,15 @@ var AccountKeyError = class extends Error {
|
|
|
31382
31861
|
/** A machine-readable detail: `too_short`, `too_long`, `strength`, `wrong_prefix`, `checksum`, …, or a control-plane error code. */
|
|
31383
31862
|
reason;
|
|
31384
31863
|
retryAfterMs;
|
|
31385
|
-
constructor(code,
|
|
31386
|
-
super(
|
|
31864
|
+
constructor(code, message2, extra = {}) {
|
|
31865
|
+
super(message2);
|
|
31387
31866
|
this.name = "AccountKeyError";
|
|
31388
31867
|
this.code = code;
|
|
31389
31868
|
if (extra.reason !== void 0) this.reason = extra.reason;
|
|
31390
31869
|
if (extra.retryAfterMs !== void 0) this.retryAfterMs = extra.retryAfterMs;
|
|
31391
31870
|
}
|
|
31392
31871
|
};
|
|
31393
|
-
var err = (code,
|
|
31872
|
+
var err = (code, message2, reason) => new AccountKeyError(code, message2, reason === void 0 ? {} : { reason });
|
|
31394
31873
|
var utf83 = new TextEncoder();
|
|
31395
31874
|
function domainHash(tag, m2) {
|
|
31396
31875
|
const t = utf83.encode(tag);
|
|
@@ -31504,8 +31983,8 @@ function deriveRecoveryDevice(secret, collection) {
|
|
|
31504
31983
|
const device = uuidText(domainHash("mdbase/v1/recovery-id", concat(c, signPk)).subarray(0, 16));
|
|
31505
31984
|
return { device, signSeed, signPk, kemSk, kemPk, noisePk: new Uint8Array(32) };
|
|
31506
31985
|
}
|
|
31507
|
-
function recoverySign(d,
|
|
31508
|
-
return ed25519.sign(
|
|
31986
|
+
function recoverySign(d, message2) {
|
|
31987
|
+
return ed25519.sign(message2, d.signSeed);
|
|
31509
31988
|
}
|
|
31510
31989
|
function wipeRecoveryDevice(d) {
|
|
31511
31990
|
wipe(d.signSeed, d.kemSk);
|
|
@@ -32325,16 +32804,16 @@ var PrivateAccount = class {
|
|
|
32325
32804
|
if (r.mode !== "password" || version2(r.version) !== expected + 1 || r.key_id !== keyIdHex) throw bad7("put");
|
|
32326
32805
|
}
|
|
32327
32806
|
async collections(signal) {
|
|
32328
|
-
let
|
|
32807
|
+
let list4;
|
|
32329
32808
|
try {
|
|
32330
|
-
|
|
32809
|
+
list4 = await this.replica.privateCollections({ signal });
|
|
32331
32810
|
} catch (e) {
|
|
32332
32811
|
throw mapPortError(e);
|
|
32333
32812
|
}
|
|
32334
32813
|
this.check(signal);
|
|
32335
|
-
if (!Array.isArray(
|
|
32336
|
-
for (const c of
|
|
32337
|
-
return
|
|
32814
|
+
if (!Array.isArray(list4) || list4.some((c) => typeof c !== "string") || new Set(list4).size !== list4.length) throw bad7("collections");
|
|
32815
|
+
for (const c of list4) uuidBytes(c);
|
|
32816
|
+
return list4;
|
|
32338
32817
|
}
|
|
32339
32818
|
/** Enrol and key the recovery device in each private collection; collect the ones that failed. */
|
|
32340
32819
|
async keyAll(secret, signal) {
|
|
@@ -34948,7 +35427,7 @@ var MAX_BODY = 64 * 1024;
|
|
|
34948
35427
|
var REQUEST_MS = 15e3;
|
|
34949
35428
|
var SETTLE_MS = 45e3;
|
|
34950
35429
|
var unavailable5 = (reason) => new AccountKeyError("unavailable", "The account key service refused or was unreachable.", { reason });
|
|
34951
|
-
var
|
|
35430
|
+
var cancelled2 = () => new AccountKeyError("cancelled", "Account key request cancelled.");
|
|
34952
35431
|
var unsupported = () => unavailable5("not_supported");
|
|
34953
35432
|
var hex9 = (b) => Array.from(b, (v) => v.toString(16).padStart(2, "0")).join("");
|
|
34954
35433
|
var HEX322 = /^[0-9a-f]{64}$/;
|
|
@@ -34975,7 +35454,7 @@ var AppCpAccountKeyControl = class {
|
|
|
34975
35454
|
fetchImpl;
|
|
34976
35455
|
now;
|
|
34977
35456
|
check(signal) {
|
|
34978
|
-
if (signal.aborted || this.lifetime.signal.aborted) throw
|
|
35457
|
+
if (signal.aborted || this.lifetime.signal.aborted) throw cancelled2();
|
|
34979
35458
|
let current2 = false;
|
|
34980
35459
|
try {
|
|
34981
35460
|
current2 = this.session.isCurrent() === true && this.session.accountId === this.accountId && this.session.deviceId === this.deviceId && this.session.cpOrigin === this.origin;
|
|
@@ -35123,7 +35602,7 @@ async function accountKeyStatus2(control, signal) {
|
|
|
35123
35602
|
} catch (error4) {
|
|
35124
35603
|
throw mapPortError(error4);
|
|
35125
35604
|
}
|
|
35126
|
-
if (signal.aborted) throw
|
|
35605
|
+
if (signal.aborted) throw cancelled2();
|
|
35127
35606
|
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {}, mode = r.mode;
|
|
35128
35607
|
if (mode !== "password" && mode !== "strict" && mode !== "none") throw unavailable5("response");
|
|
35129
35608
|
return {
|
|
@@ -35151,7 +35630,7 @@ async function unlockPrivateDevice(session, native, secret, options) {
|
|
|
35151
35630
|
if (password === recovery2 || typeof (password ? secret.password : secret.recoveryKey) !== "string" || !Number.isSafeInteger(settleMs) || settleMs < 1)
|
|
35152
35631
|
throw new AppAccountKeyUnlockError("unavailable", "binding");
|
|
35153
35632
|
const current2 = () => {
|
|
35154
|
-
if (signal.aborted) throw
|
|
35633
|
+
if (signal.aborted) throw cancelled2();
|
|
35155
35634
|
if (session.isCurrent() !== true) throw unavailable5("fenced");
|
|
35156
35635
|
};
|
|
35157
35636
|
current2();
|
|
@@ -37194,7 +37673,7 @@ var AppWebCloudCopyHost = class _AppWebCloudCopyHost {
|
|
|
37194
37673
|
}
|
|
37195
37674
|
try {
|
|
37196
37675
|
await Promise.race([
|
|
37197
|
-
this.readClient.query({ limit: 1 },
|
|
37676
|
+
this.readClient.query({ limit: 1 }, { signal: ctrl.signal }),
|
|
37198
37677
|
aborted
|
|
37199
37678
|
]);
|
|
37200
37679
|
this.checkCollection(signal);
|
|
@@ -37731,9 +38210,9 @@ async function otherDatabaseNames(scope, ledger, unlabelled) {
|
|
|
37731
38210
|
for (const purpose of ["create", "join"]) others.add(`${scoped[0]}${id4}.${purpose}`);
|
|
37732
38211
|
for (const purpose of ["create", "enrol"]) others.add(`${scoped[1]}${id4}.${purpose}`);
|
|
37733
38212
|
}
|
|
37734
|
-
const
|
|
37735
|
-
if (typeof
|
|
37736
|
-
const found = await bounded2(
|
|
38213
|
+
const list4 = indexedDB.databases;
|
|
38214
|
+
if (typeof list4 === "function") {
|
|
38215
|
+
const found = await bounded2(list4.call(indexedDB), []);
|
|
37737
38216
|
for (const { name: name2 } of found) if (name2 && scoped.some((p) => name2.startsWith(p))) others.add(name2);
|
|
37738
38217
|
}
|
|
37739
38218
|
}
|
|
@@ -41179,9 +41658,9 @@ async function appUnsyncedWork(databaseName, signal) {
|
|
|
41179
41658
|
return row2(databaseName, WORK, work, null, signal);
|
|
41180
41659
|
}
|
|
41181
41660
|
async function exists(databaseName, signal) {
|
|
41182
|
-
const
|
|
41183
|
-
if (typeof
|
|
41184
|
-
const names = await
|
|
41661
|
+
const list4 = globalThis.indexedDB?.databases;
|
|
41662
|
+
if (typeof list4 !== "function") return null;
|
|
41663
|
+
const names = await list4.call(globalThis.indexedDB);
|
|
41185
41664
|
signal.throwIfAborted();
|
|
41186
41665
|
return names.some((entry2) => entry2.name === databaseName);
|
|
41187
41666
|
}
|
|
@@ -42347,15 +42826,15 @@ async function initialize(event) {
|
|
|
42347
42826
|
const packaged = packagedApplicationAssets(declaration.environment, declaration.origin, anchor);
|
|
42348
42827
|
owner = new ApplicationWorkerHost(port, binding, declaration, packaged, globalThis.navigator.locks, storageNamespace);
|
|
42349
42828
|
const primary = binding;
|
|
42350
|
-
globalThis.addEventListener("message", (
|
|
42351
|
-
const data =
|
|
42829
|
+
globalThis.addEventListener("message", (message2) => {
|
|
42830
|
+
const data = message2.data;
|
|
42352
42831
|
if (!owner || !Array.isArray(data) || data.length !== 4 || data[0] !== APPLICATION_WORKER_PROTOCOL || data[1] !== primary || !applicationWorkerBinding(data[3])) {
|
|
42353
|
-
for (const input of
|
|
42832
|
+
for (const input of message2.ports) input.close();
|
|
42354
42833
|
return;
|
|
42355
42834
|
}
|
|
42356
|
-
if (data[2] === "attach" &&
|
|
42357
|
-
else if (data[2] === "detach" &&
|
|
42358
|
-
else for (const input of
|
|
42835
|
+
if (data[2] === "attach" && message2.ports.length === 1) owner.attach(message2.ports[0], data[3]);
|
|
42836
|
+
else if (data[2] === "detach" && message2.ports.length === 0) owner.detachClient(data[3]);
|
|
42837
|
+
else for (const input of message2.ports) input.close();
|
|
42359
42838
|
});
|
|
42360
42839
|
} catch (error4) {
|
|
42361
42840
|
try {
|