@mdbase-dev/sdk 0.1.0-beta.166 → 0.1.0-beta.168

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.
@@ -997,6 +997,7 @@ var MdbaseSDK = (() => {
997
997
  recordState: () => recordState,
998
998
  recordView: () => recordView,
999
999
  recovery: () => recovery,
1000
+ resolveLinksResult: () => resolveLinksResult,
1000
1001
  resourceView: () => resourceView,
1001
1002
  resyncing: () => resyncing,
1002
1003
  role: () => role,
@@ -1017,7 +1018,7 @@ var MdbaseSDK = (() => {
1017
1018
  function bad(ty) {
1018
1019
  throw new SchemaError(ty, "wrong type");
1019
1020
  }
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, validationLevel, 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;
1021
+ 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, validationLevel, 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, resolveLinksResult, listViewsResult, viewSourceDocument, newTypeFile, describeResult, pendingOp, listPendingResult, target, queryParams, executeViewParams, TEMPORAL_HINTS, temporalHint, typingEntry, describeTypingResult, DESCRIBE_TYPING_MAX_TYPES, DESCRIBE_TYPING_MAX_PATHS;
1021
1022
  var init_wire = __esm({
1022
1023
  "src/wire.ts"() {
1023
1024
  "use strict";
@@ -1230,7 +1231,8 @@ var MdbaseSDK = (() => {
1230
1231
  linkResolution = struct("link-resolution", [
1231
1232
  [0, "kind", enumOf("link-kind", ["record", "file", "ambiguous", "not_found", "invalid"])],
1232
1233
  [1, "target", uuid, "opt"],
1233
- [2, "path", tstr, "opt"]
1234
+ [2, "path", tstr, "opt"],
1235
+ [3, "candidates", list(tstr, { nonEmpty: true }), "opt"]
1234
1236
  ]);
1235
1237
  linkView = struct("link-view", [
1236
1238
  [0, "raw", tstr],
@@ -1787,6 +1789,11 @@ var MdbaseSDK = (() => {
1787
1789
  [2, "complete", bool],
1788
1790
  [3, "asOf", uint]
1789
1791
  ]);
1792
+ resolveLinksResult = struct("resolve-links-result", [
1793
+ [0, "resolutions", list(linkResolution)],
1794
+ [1, "asOf", uint],
1795
+ [2, "complete", bool]
1796
+ ]);
1790
1797
  listViewsResult = struct(
1791
1798
  "list-views-result",
1792
1799
  [
@@ -6080,7 +6087,7 @@ var MdbaseSDK = (() => {
6080
6087
  function connect(opts) {
6081
6088
  return MdbaseClient.connect(opts);
6082
6089
  }
6083
- var Write, LiveQuery, READ_METHODS, MdbaseClient;
6090
+ var VALIDATE_PAGE, Write, LiveQuery, READ_METHODS, MdbaseClient;
6084
6091
  var init_client = __esm({
6085
6092
  "src/client.ts"() {
6086
6093
  "use strict";
@@ -6108,6 +6115,7 @@ var MdbaseSDK = (() => {
6108
6115
  init_wire();
6109
6116
  init_write_ledger();
6110
6117
  init_wire();
6118
+ VALIDATE_PAGE = "validate-page-v1";
6111
6119
  Write = class {
6112
6120
  constructor(receipt4) {
6113
6121
  this.receipt = receipt4;
@@ -6468,7 +6476,7 @@ var MdbaseSDK = (() => {
6468
6476
  versions: API_VERSIONS,
6469
6477
  clientName: opts.app.name,
6470
6478
  clientVersion: opts.app.version,
6471
- features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1", "file-stream-failure-v1"])],
6479
+ features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1", "file-stream-failure-v1", VALIDATE_PAGE])],
6472
6480
  ...tz ? { timezone: tz } : {}
6473
6481
  };
6474
6482
  }
@@ -7019,7 +7027,17 @@ var MdbaseSDK = (() => {
7019
7027
  throw mdbaseError("unavailable", "invalid contract query record binding", "contract_query_response");
7020
7028
  return result2;
7021
7029
  }
7022
- /** Records whose links resolve to `target` (index-backed, §4.2). */
7030
+ /**
7031
+ * One page of the records whose links resolve to `target`, from the
7032
+ * replica's link index with Core resolution over the local view (pending
7033
+ * changes included; the target's links to itself excluded). Referrers come
7034
+ * in path order, each with its links to the target. Pass the returned
7035
+ * `cursor` for the next page (`limit` 1–1000, default 128); a page may hold
7036
+ * fewer than `limit`, and only an absent cursor ends the list. Any local
7037
+ * change between pages refuses the continuation with `cursor_stale`: start
7038
+ * again from the first page. A replica without the method refuses with
7039
+ * `upgrade_required` / `backlinks_unsupported` (§4.2).
7040
+ */
7023
7041
  backlinks(target2, o = {}) {
7024
7042
  return this.call(
7025
7043
  "backlinks",
@@ -7030,7 +7048,39 @@ var MdbaseSDK = (() => {
7030
7048
  [3, o.cursor]
7031
7049
  ]),
7032
7050
  { codec: backlinksResult, retry: true, ...o.signal ? { signal: o.signal } : {} }
7033
- );
7051
+ ).catch((e) => {
7052
+ if (isMdbaseError(e, "invalid_request") && e.reason === "unknown_method") {
7053
+ throw mdbaseError("upgrade_required", "This collection's replica can't list backlinks yet.", "backlinks_unsupported");
7054
+ }
7055
+ throw e;
7056
+ });
7057
+ }
7058
+ /**
7059
+ * Resolve link occurrences written in the note at `from`, exactly as the
7060
+ * replica resolves them for backlinks and rename: Core parsing and spec 08
7061
+ * resolution over the local view, pending changes included. `from` need not
7062
+ * exist yet (an unsaved draft). Each entry is one occurrence as written —
7063
+ * `[[target]]`, `![[target#anchor|alias]]`, `[text](path)`, `![alt](path)` —
7064
+ * and the result holds one resolution per entry, in order: a record or file
7065
+ * with its ID and path, `ambiguous` with sorted candidate paths, or
7066
+ * `not_found` / `invalid`. Titles and aliases are not link keys. 1–512
7067
+ * entries of at most 4096 bytes each. A replica without the method refuses
7068
+ * with `upgrade_required` / `resolve_links_unsupported` (§4.3).
7069
+ */
7070
+ resolveLinks(from, links, o = {}) {
7071
+ return this.call(
7072
+ "resolve_links",
7073
+ params([
7074
+ [0, from],
7075
+ [1, [...links]]
7076
+ ]),
7077
+ { codec: resolveLinksResult, retry: true, ...o.signal ? { signal: o.signal } : {} }
7078
+ ).catch((e) => {
7079
+ if (isMdbaseError(e, "invalid_request") && e.reason === "unknown_method") {
7080
+ throw mdbaseError("upgrade_required", "This collection's replica can't resolve links yet.", "resolve_links_unsupported");
7081
+ }
7082
+ throw e;
7083
+ });
7034
7084
  }
7035
7085
  /** Definitions: `mdbase.yaml`, type files, contract files (§4.1). */
7036
7086
  resources = {
@@ -7392,16 +7442,32 @@ var MdbaseSDK = (() => {
7392
7442
  Object.defineProperties(watch, { state: { get: () => state2 }, error: { get: () => error4 } });
7393
7443
  return Object.freeze(watch);
7394
7444
  }
7445
+ /** Validate these records, or every record. Every record is validated a
7446
+ * page at a time when the replica grants `validate-page-v1`; each page is an
7447
+ * independent READ, so records changed meanwhile may be missed or repeated.
7448
+ * Older replicas validate every record in one bounded request. */
7395
7449
  async validate(refs, signal) {
7396
7450
  signal?.throwIfAborted();
7397
7451
  const { targets: targets2, expected } = captureValidation(refs);
7398
- const result2 = await this.call("validate", params([[0, targets2]]), {
7452
+ const call2 = (p) => this.call("validate", p, {
7399
7453
  codec: recordValidations,
7400
7454
  retry: true,
7401
7455
  ...signal ? { signal } : {}
7402
7456
  });
7403
- signal?.throwIfAborted();
7404
- return bindValidation(result2, expected);
7457
+ if (targets2 !== void 0 || !this.hello.features.includes(VALIDATE_PAGE)) {
7458
+ const result2 = await call2(params([[0, targets2]]));
7459
+ signal?.throwIfAborted();
7460
+ return bindValidation(result2, expected);
7461
+ }
7462
+ const out = [];
7463
+ for (let after; ; ) {
7464
+ const page = await call2(params([[1, new Map(after === void 0 ? [] : [[0, uuid.enc(after)]])]]));
7465
+ signal?.throwIfAborted();
7466
+ const last = page[page.length - 1];
7467
+ if (last === void 0) return out;
7468
+ out.push(...page);
7469
+ after = last.id;
7470
+ }
7405
7471
  }
7406
7472
  /** Independent native app-host Bases READ, exact original held session.
7407
7473
  * Unsupported transports refuse: no generic execute_view/data fallback. */
@@ -12072,6 +12138,8 @@ var MdbaseSDK = (() => {
12072
12138
  describe_definitions_unsupported: "update_required",
12073
12139
  contract_records_unsupported: "update_required",
12074
12140
  record_links_unsupported: "update_required",
12141
+ backlinks_unsupported: "update_required",
12142
+ resolve_links_unsupported: "update_required",
12075
12143
  change_entity_unsupported: "update_required",
12076
12144
  timer_operation_recovery_unavailable: "update_required",
12077
12145
  contract_query_version: "update_required",
@@ -37210,6 +37278,9 @@ ${end.comment}` : end.comment;
37210
37278
  s.confirmedHead
37211
37279
  ]);
37212
37280
  }
37281
+ function localCommitSignal(status) {
37282
+ return status.mode === "local_only";
37283
+ }
37213
37284
  function catalogFingerprint(catalog) {
37214
37285
  return JSON.stringify(catalog, (_key, value2) => typeof value2 === "bigint" ? `${value2}n` : value2 instanceof Map ? [...value2.entries()] : value2 instanceof Uint8Array ? [...value2] : value2);
37215
37286
  }
@@ -37432,9 +37503,9 @@ ${end.comment}` : end.comment;
37432
37503
  this.stops.push(
37433
37504
  this.watch.subscribe(this.invalidate),
37434
37505
  this.client.onLink(this.invalidate),
37435
- this.client.onStatus(() => {
37506
+ this.client.onStatus((status) => {
37436
37507
  const next = statusStamp(this.client);
37437
- if (next !== this.lastStatus) {
37508
+ if (next !== this.lastStatus || localCommitSignal(status)) {
37438
37509
  this.lastStatus = next;
37439
37510
  this.invalidate();
37440
37511
  }
@@ -37872,6 +37943,7 @@ ${end.comment}` : end.comment;
37872
37943
  if (!this.current()) break;
37873
37944
  if (source) await source.refresh();
37874
37945
  }
37946
+ await this.reassessAfterSetup();
37875
37947
  return this.getSnapshot();
37876
37948
  }).finally(() => {
37877
37949
  if (this.pending !== pending) return;
@@ -37896,6 +37968,24 @@ ${end.comment}` : end.comment;
37896
37968
  return value2;
37897
37969
  });
37898
37970
  }
37971
+ /** The native witness is taken before configuration, which may then apply
37972
+ * setup (automatically for a new or unsynced collection). Its change notice
37973
+ * can arrive after this refresh settles, so a settled native setup_required
37974
+ * beside a configuration that settled ready is assessed once more here.
37975
+ * One extra READ at most: a genuine disagreement stays setup_required. */
37976
+ async reassessAfterSetup() {
37977
+ if (!this.native || !this.current()) return;
37978
+ const native = this.native.getSnapshot();
37979
+ let configured = null;
37980
+ try {
37981
+ configured = this.sources.configuration?.getSnapshot() ?? null;
37982
+ } catch {
37983
+ }
37984
+ if (native.checking || native.assessment?.status !== "setup_required" || configured?.checking || configured?.assessment?.status !== "ready") return;
37985
+ await this.native.start().catch((error4) => {
37986
+ if (!(isMdbaseError(error4) && error4.reason === "readiness_busy")) throw error4;
37987
+ });
37988
+ }
37899
37989
  close() {
37900
37990
  if (this.closing) return this.closing;
37901
37991
  this.closed = true;
@@ -38158,7 +38248,10 @@ ${end.comment}` : end.comment;
38158
38248
  check(signal, session);
38159
38249
  if (!stops.length) {
38160
38250
  lastStamp = stamp();
38161
- stops.push(input.client.onStatus(invalidate), input.client.onLink(invalidate));
38251
+ stops.push(input.client.onStatus((status) => {
38252
+ if (localCommitSignal(status)) lastStamp = null;
38253
+ invalidate();
38254
+ }), input.client.onLink(invalidate));
38162
38255
  }
38163
38256
  dirty = false;
38164
38257
  const { journaled, previous } = await recover(signal, session);
@@ -41091,12 +41184,12 @@ ${end.comment}` : end.comment;
41091
41184
  // src/application/asset-pins.json
41092
41185
  var asset_pins_default = {
41093
41186
  runtime: {
41094
- sha256: "4d377128dd7e76241cbbf63d00dd3f232286d8a506908fa240d20c6ac85c69a8",
41095
- bytes: 3811508,
41096
- maxBytes: 3811508,
41187
+ sha256: "e70b55216318f5d12bde51ef75120c8f8fd285816e596817e766d484085aa073",
41188
+ bytes: 3838960,
41189
+ maxBytes: 3838960,
41097
41190
  source: {
41098
41191
  repository: "mdbase-dev/mdbase-connect",
41099
- commit: "419d7ddfaade89b3795836674685f99738db9427"
41192
+ commit: "d9abf0ee991f4b7d3b558eb3def05b8285d5afc1"
41100
41193
  }
41101
41194
  },
41102
41195
  sqlite: {