@mdbase-dev/sdk 0.1.0-beta.156 → 0.1.0-beta.158

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.
@@ -955,6 +955,7 @@ var MdbaseSDK = (() => {
955
955
  fenceResult: () => fenceResult,
956
956
  fileChunk: () => fileChunk,
957
957
  fileInclusion: () => fileInclusion,
958
+ fileStreamFailure: () => fileStreamFailure,
958
959
  fileView: () => fileView,
959
960
  fmMap: () => fmMap,
960
961
  grantInfo: () => grantInfo,
@@ -1016,7 +1017,7 @@ var MdbaseSDK = (() => {
1016
1017
  function bad(ty) {
1017
1018
  throw new SchemaError(ty, "wrong type");
1018
1019
  }
1019
- var version, RECOVERY, recovery, severity, issue, problem, clientFrame, helloParams, ROLES, role, grantInfo, INCIDENT_KINDS, incident, progress, resyncing, confirmedHead, appliedPrefixParams, appliedPrefix, syncStatus, helloResult, blobRef, textOrBlob, HOLD_REASONS, holdReason, holdRef, hold, HOLD_RESOLUTIONS, holdResolution, recordState, linkResolution, linkView, authorRef, fmMap, recordView, include, viewRef, queryGroup, queryMetadata, queryResult, queryUpdate, change, changesResult, MEDIA_CLASSES, mediaClass, conflictMode, baseField, bodyEdit, docVersion, fileInclusion, listsByField, op, submitParams, CONFLICT_FORMS, conflictValue, conflict, publishState, preflight, receipt, submitResult, conflictEntry, fileContentProfile, knownFileView, fileView, listFilesResult, openUploadParams, openUploadResult, uploadChunkParams, fileChunk, TRANSFER_PHASES, transferProgress, materialization, peer, presencePush, fenceApply, fenceReport, fenceResult, PUSH_CODECS, opClock, mutation, confirmation, resourceView, listResourcesResult, backlinksResult, listViewsResult, viewSourceDocument, newTypeFile, describeResult, pendingOp, listPendingResult, target, queryParams, executeViewParams, TEMPORAL_HINTS, temporalHint, typingEntry, describeTypingResult, DESCRIBE_TYPING_MAX_TYPES, DESCRIBE_TYPING_MAX_PATHS;
1020
+ var version, RECOVERY, recovery, severity, issue, problem, clientFrame, helloParams, ROLES, role, grantInfo, INCIDENT_KINDS, incident, progress, resyncing, confirmedHead, appliedPrefixParams, appliedPrefix, syncStatus, helloResult, blobRef, textOrBlob, HOLD_REASONS, holdReason, holdRef, hold, HOLD_RESOLUTIONS, holdResolution, recordState, linkResolution, linkView, authorRef, fmMap, recordView, include, viewRef, queryGroup, queryMetadata, queryResult, queryUpdate, change, changesResult, MEDIA_CLASSES, mediaClass, conflictMode, baseField, bodyEdit, docVersion, fileInclusion, listsByField, op, submitParams, CONFLICT_FORMS, conflictValue, conflict, publishState, preflight, receipt, submitResult, conflictEntry, fileContentProfile, knownFileView, fileView, listFilesResult, openUploadParams, openUploadResult, uploadChunkParams, fileChunk, fileStreamFailure, TRANSFER_PHASES, transferProgress, materialization, peer, presencePush, fenceApply, fenceReport, fenceResult, PUSH_CODECS, opClock, mutation, confirmation, resourceView, listResourcesResult, backlinksResult, listViewsResult, viewSourceDocument, newTypeFile, describeResult, pendingOp, listPendingResult, target, queryParams, executeViewParams, TEMPORAL_HINTS, temporalHint, typingEntry, describeTypingResult, DESCRIBE_TYPING_MAX_TYPES, DESCRIBE_TYPING_MAX_PATHS;
1020
1021
  var init_wire = __esm({
1021
1022
  "src/wire.ts"() {
1022
1023
  "use strict";
@@ -1641,6 +1642,10 @@ var MdbaseSDK = (() => {
1641
1642
  [2, "bytes", { name: "bstr", enc: (v) => v, dec: (c) => c instanceof Uint8Array ? c : bad("bstr") }],
1642
1643
  [3, "last", bool]
1643
1644
  ]);
1645
+ fileStreamFailure = struct("file-stream-failure", [
1646
+ [0, "stream", uint],
1647
+ [1, "problem", problem]
1648
+ ]);
1644
1649
  TRANSFER_PHASES = [
1645
1650
  "receiving",
1646
1651
  "sealing",
@@ -1718,6 +1723,7 @@ var MdbaseSDK = (() => {
1718
1723
  conflicts: list(conflictEntry),
1719
1724
  presence: presencePush,
1720
1725
  file_chunk: fileChunk,
1726
+ file_stream_failed: fileStreamFailure,
1721
1727
  transfer_progress: transferProgress,
1722
1728
  changes: changesResult
1723
1729
  };
@@ -3619,6 +3625,7 @@ var MdbaseSDK = (() => {
3619
3625
  wired = /* @__PURE__ */ new WeakSet();
3620
3626
  opening = 0;
3621
3627
  early = /* @__PURE__ */ new Map();
3628
+ earlyFailures = /* @__PURE__ */ new Map();
3622
3629
  /** The current session's file actions and folder scope ({@link fileGrant}). */
3623
3630
  get grant() {
3624
3631
  const grant = fileGrant(this.client.hello), gate = gates.get(this);
@@ -3671,6 +3678,19 @@ var MdbaseSDK = (() => {
3671
3678
  } catch {
3672
3679
  }
3673
3680
  });
3681
+ s.onPush("file_stream_failed", (p) => {
3682
+ try {
3683
+ const { stream, problem: problem6 } = fileStreamFailure.dec(p);
3684
+ const st = this.streams.get(stream);
3685
+ if (st) {
3686
+ this.streams.delete(stream);
3687
+ st.onEnd(new MdbaseError(problem6));
3688
+ } else if (this.opening > 0 && this.earlyFailures.size < 16) {
3689
+ this.earlyFailures.set(stream, new MdbaseError(problem6));
3690
+ }
3691
+ } catch {
3692
+ }
3693
+ });
3674
3694
  s.onClose((e) => {
3675
3695
  for (const st of this.streams.values()) st.onEnd(e ?? mdbaseError("unavailable", "connection closed"));
3676
3696
  this.streams.clear();
@@ -3744,9 +3764,8 @@ var MdbaseSDK = (() => {
3744
3764
  if (o.onProgress) this.progress.set(transfer, o.onProgress);
3745
3765
  const busyUntil = Date.now() + REGION_BUSY_WAIT_MS;
3746
3766
  for (; ; ) {
3747
- const phase = { committing: false };
3748
3767
  try {
3749
- return await this.uploadOnce(source, size2, open2, o, phase);
3768
+ return await this.uploadOnce(source, size2, open2, o);
3750
3769
  } catch (e) {
3751
3770
  if (isMdbaseError(e, "unavailable") && this.client.link === "reconnecting") continue;
3752
3771
  if (regionBusy(e, busyUntil)) {
@@ -3754,13 +3773,13 @@ var MdbaseSDK = (() => {
3754
3773
  continue;
3755
3774
  }
3756
3775
  this.progress.delete(transfer);
3757
- if (!phase.committing) await this.abortUpload(transfer).catch(() => {
3776
+ await this.abortUpload(transfer).catch(() => {
3758
3777
  });
3759
3778
  throw withMutation(e, "upload", { mutationId: open2.mutationId });
3760
3779
  }
3761
3780
  }
3762
3781
  }
3763
- async uploadOnce(source, size2, open2, o, phase) {
3782
+ async uploadOnce(source, size2, open2, o) {
3764
3783
  const s = await this.session(o.signal);
3765
3784
  const sig = o.signal ? { signal: o.signal } : {};
3766
3785
  const opened = await s.request("open_upload", openUploadParams.enc(open2), { codec: openUploadResult, ...sig });
@@ -3793,7 +3812,6 @@ var MdbaseSDK = (() => {
3793
3812
  if (inflight.size >= 4) await Promise.race(inflight);
3794
3813
  }
3795
3814
  await Promise.all(inflight);
3796
- phase.committing = true;
3797
3815
  const r = await s.request("commit_upload", m([[0, uuid.enc(open2.transfer)]]), {
3798
3816
  codec: receipt,
3799
3817
  ...sig
@@ -3807,7 +3825,7 @@ var MdbaseSDK = (() => {
3807
3825
  }
3808
3826
  return w;
3809
3827
  }
3810
- /** Abort an upload; the replica discards its chunks. */
3828
+ /** Release the upload lane. An already captured write remains durable; use its receipt to resolve the outcome. */
3811
3829
  abortUpload(transferId) {
3812
3830
  return this.client.call("abort_upload", m([[0, uuid.enc(transferId)]])).then(() => {
3813
3831
  });
@@ -3895,8 +3913,13 @@ var MdbaseSDK = (() => {
3895
3913
  }
3896
3914
  streamId = uint.dec(r.get(0) ?? null);
3897
3915
  const early = self.early.get(streamId) ?? [];
3916
+ const earlyFailure = self.earlyFailures.get(streamId);
3898
3917
  self.early.delete(streamId);
3899
- if (self.opening === 0) self.early.clear();
3918
+ self.earlyFailures.delete(streamId);
3919
+ if (self.opening === 0) {
3920
+ self.early.clear();
3921
+ self.earlyFailures.clear();
3922
+ }
3900
3923
  if (cancelled3) {
3901
3924
  cancelRemote();
3902
3925
  finished = true;
@@ -3929,10 +3952,19 @@ var MdbaseSDK = (() => {
3929
3952
  }
3930
3953
  });
3931
3954
  for (const c of early) deliver(c);
3955
+ if (earlyFailure && !finished) {
3956
+ self.streams.delete(streamId);
3957
+ finished = true;
3958
+ detachAbort();
3959
+ ctrl.error(earlyFailure);
3960
+ }
3932
3961
  } catch (e) {
3933
3962
  finished = true;
3934
3963
  detachAbort();
3935
- if (self.opening === 0) self.early.clear();
3964
+ if (self.opening === 0) {
3965
+ self.early.clear();
3966
+ self.earlyFailures.clear();
3967
+ }
3936
3968
  cancelRemote();
3937
3969
  fileReject(e);
3938
3970
  ctrl.error(e);
@@ -6396,11 +6428,11 @@ var MdbaseSDK = (() => {
6396
6428
  return new _MdbaseClient(opts, session);
6397
6429
  } catch (e) {
6398
6430
  if (signal?.aborted) throw stopped();
6399
- const pending = nextRelay2 && isMdbaseError(e, "unavailable") && e.reason === "grant_inactive" && e.details instanceof Map && e.details.get("relayCloseCode") === 4e3;
6431
+ const pending = nextRelay2 && isMdbaseError(e, "unavailable") && (e.reason === "grant_lease_expired" || e.reason === "authorization_unavailable");
6400
6432
  if (!(pending || opts.waitForDevice && isMdbaseError(e, "unavailable") && e.reason === "no_device_online")) throw e;
6401
6433
  if (pending && !deadline2) {
6402
6434
  deadline2 = new AbortController();
6403
- timeout2 = mdbaseError("unavailable", "The approved grant did not become live within 30 seconds", { reason: "grant_activation_timeout", details: e.details });
6435
+ timeout2 = mdbaseError("unavailable", "The approved grant did not become live within 30 seconds", { reason: "grant_activation_timeout", details: e.toProblem().details });
6404
6436
  signal = opts.signal ? AbortSignal.any([opts.signal, deadline2.signal]) : deadline2.signal;
6405
6437
  timer2 = setTimeout(() => deadline2.abort(), 3e4);
6406
6438
  }
@@ -6434,7 +6466,7 @@ var MdbaseSDK = (() => {
6434
6466
  versions: API_VERSIONS,
6435
6467
  clientName: opts.app.name,
6436
6468
  clientVersion: opts.app.version,
6437
- features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1"])],
6469
+ features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1", "file-stream-failure-v1"])],
6438
6470
  ...tz ? { timezone: tz } : {}
6439
6471
  };
6440
6472
  }
@@ -10726,6 +10758,7 @@ var MdbaseSDK = (() => {
10726
10758
  case 4429:
10727
10759
  return error4("rate_limited", r ?? "relay: busy", r ?? "connector_busy", 5e3);
10728
10760
  case 4e3:
10761
+ if (r === "grant_lease_expired") return error4("unavailable", "grant lease expired", r, 1e3);
10729
10762
  if (r === "device_key_mismatch") return error4("unauthenticated", "relay: the routed key is not the device's", r);
10730
10763
  return error4("unavailable", `relay closed the pipe: ${r ?? "unknown"}`, r ?? "pipe_closed");
10731
10764
  default:
@@ -10862,7 +10895,7 @@ var MdbaseSDK = (() => {
10862
10895
  init_relay_close();
10863
10896
  init_cbor();
10864
10897
  MAX_PIPE_FRAME = 4 + 65535;
10865
- CLOSE_REASONS = new Set("unauthenticated grant_inactive connector_offline connector_busy device_mismatch device_key_mismatch closed client_closed handshake_timeout idle lifetime frame_too_large invalid_frame not_served relay_closing authorization_unavailable grant_revoked".split(" "));
10898
+ CLOSE_REASONS = new Set("unauthenticated grant_inactive connector_offline connector_busy device_mismatch device_key_mismatch closed client_closed handshake_timeout idle lifetime frame_too_large invalid_frame not_served relay_closing authorization_unavailable grant_revoked grant_lease_expired grant_pending_approval grant_revoked_on_device unknown_grant".split(" "));
10866
10899
  }
10867
10900
  });
10868
10901
 
@@ -11545,6 +11578,15 @@ var MdbaseSDK = (() => {
11545
11578
  }
11546
11579
  });
11547
11580
 
11581
+ // src/collection-quota-copy.generated.ts
11582
+ var ACCOUNT_COLLECTION_QUOTA_MESSAGE;
11583
+ var init_collection_quota_copy_generated = __esm({
11584
+ "src/collection-quota-copy.generated.ts"() {
11585
+ "use strict";
11586
+ ACCOUNT_COLLECTION_QUOTA_MESSAGE = "Your account has reached its synced collection limit. Open an existing collection, delete one you own if Delete is available, or contact mdbase support to raise your limit.";
11587
+ }
11588
+ });
11589
+
11548
11590
  // src/app-host/cp-problem.ts
11549
11591
  function isAppServerProblem(value2) {
11550
11592
  return typeof value2 === "object" && value2 !== null && genuine.has(value2);
@@ -11668,7 +11710,7 @@ var MdbaseSDK = (() => {
11668
11710
  if (typeof o.kind === "string" && "problem" in o && obj3(o.problem) && typeof obj3(o.problem).code === "string") return problemOf(obj3(o.problem).code, cpOrigin);
11669
11711
  const detail = obj3(o.problemDetail), server = sanitizeAppServerProblem(o.server ?? detail?.server, cpOrigin);
11670
11712
  const serverCodes = [server?.reason ?? null, server?.code ?? null].filter((c) => c !== null);
11671
- const extra = { retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin) };
11713
+ const extra = { retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin), hasServer: o.server != null || detail?.server != null };
11672
11714
  if ("problem" in o || "readiness" in o || "assessment" in o) {
11673
11715
  const own2 = str2(o.problem) ?? str2(obj3(o.problem)?.code);
11674
11716
  if (own2) return { codes: [...serverCodes, own2], ...extra, refusal: registrationRefusal(detail?.registration) };
@@ -11707,7 +11749,7 @@ var MdbaseSDK = (() => {
11707
11749
  if (!found) return null;
11708
11750
  const { key: key3, original } = resolve(found);
11709
11751
  if (key3 === null) return null;
11710
- const [title, message2, action, severity2, transient2 = false, label] = key3 === "unknown" ? GENERIC : COPY[key3];
11752
+ const [title, message2, action, severity2, transient2 = false, label] = key3 === "unknown" ? GENERIC : key3 === "refused" && !found.hasServer ? UNFINISHED_SIGN_IN : COPY[key3];
11711
11753
  let translated;
11712
11754
  try {
11713
11755
  const messages = options.messages;
@@ -11745,11 +11787,12 @@ var MdbaseSDK = (() => {
11745
11787
  const { key: key3, original } = resolve(found);
11746
11788
  return key3 === null ? null : diagnostic(key3, original, found.refusal ?? null);
11747
11789
  }
11748
- var LABELS, PROBLEM_CODES, GENERIC, BUSY, OFFLINE, UPDATE, CHOOSE, APPROVE, SET_UP, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
11790
+ var LABELS, PROBLEM_CODES, GENERIC, BUSY, OFFLINE, UPDATE, CHOOSE, APPROVE, SET_UP, UNFINISHED_SIGN_IN, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
11749
11791
  var init_describe_error = __esm({
11750
11792
  "src/describe-error.ts"() {
11751
11793
  "use strict";
11752
11794
  init_registration_refusal();
11795
+ init_collection_quota_copy_generated();
11753
11796
  init_collection_availability();
11754
11797
  init_cp_problem();
11755
11798
  LABELS = {
@@ -11895,6 +11938,7 @@ var MdbaseSDK = (() => {
11895
11938
  CHOOSE = ["Choose a collection", "Pick the collection you want this app to use.", "choose_collection", "info"];
11896
11939
  APPROVE = ["Approval needed", "This app needs your approval for extra access to your collection.", "approve", "info"];
11897
11940
  SET_UP = ["Set up this collection", "This collection needs a one-time setup before the app can use it.", "set_up", "info"];
11941
+ UNFINISHED_SIGN_IN = ["Sign-in wasn't finished", "Access wasn't approved. Sign in again when you're ready.", "sign_in", "info"];
11898
11942
  COPY = {
11899
11943
  // Private collections served by one of the account's computers (collection availability).
11900
11944
  device_offline: ["Your computer isn't online", "This collection is kept on your computer. Open the mdbase desktop app on a computer that has it, and this app connects as soon as it's online.", "wait", "info", true],
@@ -11923,8 +11967,8 @@ var MdbaseSDK = (() => {
11923
11967
  collection_invalid: ["Your collection needs repair", "Something in this collection isn't valid. Contact support if this keeps happening.", "contact_support", "error"],
11924
11968
  unavailable: OFFLINE,
11925
11969
  rate_limited: ["Too many requests", "Wait a moment, then try again.", "retry", "warning", true],
11926
- quota_exceeded: ["Out of storage", "Your collection has reached its storage limit. Free up space to keep saving.", "free_space", "error"],
11927
- account_collection_quota_exceeded: ["Synced collection limit reached", "Your account has reached its synced collection limit. Delete a synced collection before creating another.", "free_space", "error", false, "Manage collections"],
11970
+ quota_exceeded: ["Out of storage", "You've reached your storage limit. Free up space to keep saving.", "free_space", "error"],
11971
+ account_collection_quota_exceeded: ["Synced collection limit reached", ACCOUNT_COLLECTION_QUOTA_MESSAGE, "free_space", "error", false, "Manage collections"],
11928
11972
  too_large: ["That's too large", "This item is larger than mdbase allows.", "none", "warning"],
11929
11973
  outcome_unknown: ["Not sure that worked", "The connection dropped before mdbase confirmed it. Check whether it went through before trying again.", "resolve_outcome", "warning"],
11930
11974
  internal: GENERIC,
@@ -40923,12 +40967,12 @@ ${end.comment}` : end.comment;
40923
40967
  // src/application/asset-pins.json
40924
40968
  var asset_pins_default = {
40925
40969
  runtime: {
40926
- sha256: "b4e5b26f101072655d8c880c2355a044cb7afb6e4ffbbdef403db2dda9358010",
40927
- bytes: 3782199,
40928
- maxBytes: 3782199,
40970
+ sha256: "7d5cf20f69ef22db5eee56fa28a71a5cadab1d4014aedfc3ee5a12ccf21fff6b",
40971
+ bytes: 3798410,
40972
+ maxBytes: 3798410,
40929
40973
  source: {
40930
40974
  repository: "mdbase-dev/mdbase-connect",
40931
- commit: "1e6b83c6b338b8ce708de7e2cbddb05992d8dc11"
40975
+ commit: "056880a91db3971c10ff80cd5b5ed4a81a6b28db"
40932
40976
  }
40933
40977
  },
40934
40978
  sqlite: {
@@ -42808,10 +42852,13 @@ ${end.comment}` : end.comment;
42808
42852
  const sync = this.trackSync(phase, base.problem, base.transport ?? null, base.live ?? null);
42809
42853
  const writes = this.syncing?.writes() ?? null;
42810
42854
  const saveWarning = this.trackSaveWarning();
42811
- const value2 = Object.freeze({ ...base, selection, phase, sync, writes, storage: this.storagePolicy, saveWarning, links: this.links });
42855
+ const value2 = Object.freeze({ ...base, selection, phase, sync, writes, storage: this.storagePolicy, saveWarning, links: this.linksFor(id6) });
42812
42856
  this.composed = { base: raw, selection, revision: this.revision, hint, value: value2 };
42813
42857
  return value2;
42814
42858
  }
42859
+ linksFor(id6) {
42860
+ return this.links && id6 ? Object.freeze({ ...this.links, manageAccess: `${this.cpOrigin}/access?collection=${encodeURIComponent(id6)}` }) : this.links;
42861
+ }
42815
42862
  /** One grace window per continuously pending replica, not per edit or request. */
42816
42863
  trackSaveWarning() {
42817
42864
  const syncing = this.syncing, status = syncing?.status, count = status?.pending ?? 0;