superbee 0.4.4-pre.2 → 0.4.4-pre.4

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.
@@ -3397,6 +3397,11 @@ function stringifyDoc(frontmatter2, body) {
3397
3397
  return stringifyWithData(frontmatter2, body);
3398
3398
  }
3399
3399
 
3400
+ // ../core/src/code-unit-order.ts
3401
+ function compareCodeUnits(a, b) {
3402
+ return a < b ? -1 : a > b ? 1 : 0;
3403
+ }
3404
+
3400
3405
  // ../core/src/links.ts
3401
3406
  function normalizeSegments(segments) {
3402
3407
  const out = [];
@@ -3418,6 +3423,13 @@ function isExternalHref(href) {
3418
3423
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(h) || h.startsWith("mailto:") || h.startsWith("#");
3419
3424
  }
3420
3425
  function extractMarkdownLinks(source, options = {}) {
3426
+ const out = [];
3427
+ for (const span of extractMarkdownLinkSpans(source, options)) {
3428
+ if (!span.image) out.push({ text: span.text, href: span.href });
3429
+ }
3430
+ return out;
3431
+ }
3432
+ function extractMarkdownLinkSpans(source, options = {}) {
3421
3433
  const body = options.skipCode ? maskMarkdownCode(source) : source;
3422
3434
  const out = [];
3423
3435
  let textOpen = -1;
@@ -3428,12 +3440,16 @@ function extractMarkdownLinks(source, options = {}) {
3428
3440
  const char = body[cursor];
3429
3441
  if (hrefRest) {
3430
3442
  if (char === ")") {
3431
- if (hrefRest.open === 0 || body[hrefRest.open - 1] !== "!") {
3432
- out.push({
3433
- text: source.slice(hrefRest.open + 1, hrefRest.close),
3434
- href: source.slice(hrefRest.hrefStart, cursor)
3435
- });
3436
- }
3443
+ const image = hrefRest.open > 0 && body[hrefRest.open - 1] === "!";
3444
+ out.push({
3445
+ text: source.slice(hrefRest.open + 1, hrefRest.close),
3446
+ href: source.slice(hrefRest.hrefStart, cursor),
3447
+ start: image ? hrefRest.open - 1 : hrefRest.open,
3448
+ end: cursor + 1,
3449
+ hrefStart: hrefRest.hrefStart,
3450
+ hrefEnd: cursor,
3451
+ image
3452
+ });
3437
3453
  textOpen = -1;
3438
3454
  afterClose = void 0;
3439
3455
  hrefFirst = void 0;
@@ -3813,12 +3829,13 @@ async function readDocVersioned(backend, id) {
3813
3829
  function isEnoent(err) {
3814
3830
  return typeof err === "object" && err !== null && err.code === "ENOENT";
3815
3831
  }
3816
- async function readManyExisting(backend, ids, onMalformed) {
3832
+ async function readManyExisting(backend, ids, onMalformed, onAliased) {
3817
3833
  try {
3818
3834
  return await backend.readMany(ids);
3819
3835
  } catch (err) {
3820
- const malformed = err instanceof MalformedDocumentError;
3821
- if (!isEnoent(err) && !(malformed && onMalformed)) throw err;
3836
+ const malformed = err instanceof MalformedDocumentError && onMalformed !== void 0;
3837
+ const aliased = err instanceof FilesystemIdentityAliasError && onAliased !== void 0;
3838
+ if (!isEnoent(err) && !malformed && !aliased) throw err;
3822
3839
  const out = [];
3823
3840
  for (const id of ids) {
3824
3841
  try {
@@ -3829,6 +3846,10 @@ async function readManyExisting(backend, ids, onMalformed) {
3829
3846
  onMalformed({ id, reason: candidate.detail });
3830
3847
  continue;
3831
3848
  }
3849
+ if (candidate instanceof FilesystemIdentityAliasError && onAliased) {
3850
+ onAliased({ id, reason: candidate.message });
3851
+ continue;
3852
+ }
3832
3853
  throw candidate;
3833
3854
  }
3834
3855
  }
@@ -3841,7 +3862,7 @@ async function scanMatching(backend, filter, onSkip) {
3841
3862
  for (const result of await readManyExisting(backend, ids, onSkip)) {
3842
3863
  if (matchesFilter(result.doc, filter)) results.push(result);
3843
3864
  }
3844
- results.sort((a, b) => a.doc.id.localeCompare(b.doc.id));
3865
+ results.sort((a, b) => compareCodeUnits(a.doc.id, b.doc.id));
3845
3866
  return results;
3846
3867
  }
3847
3868
  async function query(backend, filter = {}, options = {}) {
@@ -3850,7 +3871,7 @@ async function query(backend, filter = {}, options = {}) {
3850
3871
  async function queryHeads(backend, filter = {}, options = {}) {
3851
3872
  if (backend.queryHeads) {
3852
3873
  const rows = (await backend.queryHeads(filter, options.onSkip ? { onSkip: options.onSkip } : void 0)).filter((row) => matchesFilter(row, filter));
3853
- rows.sort((a, b) => a.id.localeCompare(b.id));
3874
+ rows.sort((a, b) => compareCodeUnits(a.id, b.id));
3854
3875
  return rows;
3855
3876
  }
3856
3877
  return (await scanMatching(backend, filter, options.onSkip)).map(({ doc, version: version2 }) => ({
@@ -3890,7 +3911,7 @@ async function queryEdges(backend, filter = {}, options = {}) {
3890
3911
  edges.push(link);
3891
3912
  }
3892
3913
  }
3893
- edges.sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to) || a.text.localeCompare(b.text));
3914
+ edges.sort((a, b) => compareCodeUnits(a.from, b.from) || compareCodeUnits(a.to, b.to) || compareCodeUnits(a.text, b.text));
3894
3915
  return edges;
3895
3916
  }
3896
3917
 
@@ -4406,6 +4427,11 @@ async function acquireFilesystemIdentityLock(key, identity, options = {}) {
4406
4427
  return claimLockPath(path.join(lockRoot, `${key}.lock`), owner, waitMs, pollMs, policy);
4407
4428
  }
4408
4429
 
4430
+ // ../core/src/identity-fold.ts
4431
+ function foldSegment(segment) {
4432
+ return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
4433
+ }
4434
+
4409
4435
  // ../core/src/filesystem-identity.ts
4410
4436
  async function replaceExistingLeaf(port, tmp, target, rel) {
4411
4437
  try {
@@ -4451,9 +4477,6 @@ function relSegments(rel) {
4451
4477
  }
4452
4478
  return segments;
4453
4479
  }
4454
- function foldSegment(segment) {
4455
- return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
4456
- }
4457
4480
  async function existingAnchor(resolved) {
4458
4481
  const tail = [];
4459
4482
  let candidate = resolved;
@@ -5440,11 +5463,6 @@ async function queryEdges2(bundle, filter = {}, options = {}) {
5440
5463
  // ../core/src/bundle.ts
5441
5464
  setDefaultBackendFactory((root) => new FilesystemBackend(root));
5442
5465
 
5443
- // ../core/src/code-unit-order.ts
5444
- function compareCodeUnits(a, b) {
5445
- return a < b ? -1 : a > b ? 1 : 0;
5446
- }
5447
-
5448
5466
  // ../core/src/managed-document-metadata.ts
5449
5467
  var MANAGED_DOCUMENT_METADATA_FIELDS = /* @__PURE__ */ new Set([
5450
5468
  "generated",
@@ -6580,7 +6598,7 @@ function replyWithinLimit(reply) {
6580
6598
  }
6581
6599
  function skippedReply(skipped) {
6582
6600
  if (skipped.length === 0) return {};
6583
- return { skipped: [...skipped].sort((a, b) => a.id.localeCompare(b.id)).slice(0, MAX_QUERY_ROWS) };
6601
+ return { skipped: [...skipped].sort((a, b) => compareCodeUnits(a.id, b.id)).slice(0, MAX_QUERY_ROWS) };
6584
6602
  }
6585
6603
  function boundedRows(rows, params, kinds) {
6586
6604
  const requested = params.limit === 0 || params.limit === void 0 ? MAX_QUERY_ROWS : Math.min(params.limit, MAX_QUERY_ROWS);
@@ -6695,7 +6713,7 @@ var BridgeService = class {
6695
6713
  for (const id of subscription.baseline.keys()) {
6696
6714
  if (!next.has(id)) removed.push(id);
6697
6715
  }
6698
- changes.sort((a, b) => a.id.localeCompare(b.id));
6716
+ changes.sort((a, b) => compareCodeUnits(a.id, b.id));
6699
6717
  removed.sort();
6700
6718
  if (changes.length === 0 && removed.length === 0) return { status: "unchanged" };
6701
6719
  if (changes.length > MAX_CHANGE_ROWS || removed.length > MAX_CHANGE_ROWS) {
@@ -6724,7 +6742,7 @@ var BridgeService = class {
6724
6742
  throw new Error("the bundle is too large for the experimental View polling snapshot");
6725
6743
  }
6726
6744
  return new Map(
6727
- [...rows].sort((a, b) => a.id.localeCompare(b.id)).map((row) => [row.id, row.version])
6745
+ [...rows].sort((a, b) => compareCodeUnits(a.id, b.id)).map((row) => [row.id, row.version])
6728
6746
  );
6729
6747
  }
6730
6748
  /**
@@ -31351,6 +31351,11 @@ function stringifyDoc(frontmatter2, body) {
31351
31351
  return stringifyWithData(frontmatter2, body);
31352
31352
  }
31353
31353
 
31354
+ // ../core/src/code-unit-order.ts
31355
+ function compareCodeUnits(a, b) {
31356
+ return a < b ? -1 : a > b ? 1 : 0;
31357
+ }
31358
+
31354
31359
  // ../core/src/links.ts
31355
31360
  function normalizeSegments(segments) {
31356
31361
  const out = [];
@@ -31372,6 +31377,13 @@ function isExternalHref(href) {
31372
31377
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(h) || h.startsWith("mailto:") || h.startsWith("#");
31373
31378
  }
31374
31379
  function extractMarkdownLinks(source, options = {}) {
31380
+ const out = [];
31381
+ for (const span of extractMarkdownLinkSpans(source, options)) {
31382
+ if (!span.image) out.push({ text: span.text, href: span.href });
31383
+ }
31384
+ return out;
31385
+ }
31386
+ function extractMarkdownLinkSpans(source, options = {}) {
31375
31387
  const body = options.skipCode ? maskMarkdownCode(source) : source;
31376
31388
  const out = [];
31377
31389
  let textOpen = -1;
@@ -31382,12 +31394,16 @@ function extractMarkdownLinks(source, options = {}) {
31382
31394
  const char = body[cursor];
31383
31395
  if (hrefRest) {
31384
31396
  if (char === ")") {
31385
- if (hrefRest.open === 0 || body[hrefRest.open - 1] !== "!") {
31386
- out.push({
31387
- text: source.slice(hrefRest.open + 1, hrefRest.close),
31388
- href: source.slice(hrefRest.hrefStart, cursor)
31389
- });
31390
- }
31397
+ const image = hrefRest.open > 0 && body[hrefRest.open - 1] === "!";
31398
+ out.push({
31399
+ text: source.slice(hrefRest.open + 1, hrefRest.close),
31400
+ href: source.slice(hrefRest.hrefStart, cursor),
31401
+ start: image ? hrefRest.open - 1 : hrefRest.open,
31402
+ end: cursor + 1,
31403
+ hrefStart: hrefRest.hrefStart,
31404
+ hrefEnd: cursor,
31405
+ image
31406
+ });
31391
31407
  textOpen = -1;
31392
31408
  afterClose = void 0;
31393
31409
  hrefFirst = void 0;
@@ -31767,12 +31783,13 @@ async function readDocVersioned(backend, id) {
31767
31783
  function isEnoent(err) {
31768
31784
  return typeof err === "object" && err !== null && err.code === "ENOENT";
31769
31785
  }
31770
- async function readManyExisting(backend, ids, onMalformed) {
31786
+ async function readManyExisting(backend, ids, onMalformed, onAliased) {
31771
31787
  try {
31772
31788
  return await backend.readMany(ids);
31773
31789
  } catch (err) {
31774
- const malformed = err instanceof MalformedDocumentError;
31775
- if (!isEnoent(err) && !(malformed && onMalformed)) throw err;
31790
+ const malformed = err instanceof MalformedDocumentError && onMalformed !== void 0;
31791
+ const aliased = err instanceof FilesystemIdentityAliasError && onAliased !== void 0;
31792
+ if (!isEnoent(err) && !malformed && !aliased) throw err;
31776
31793
  const out = [];
31777
31794
  for (const id of ids) {
31778
31795
  try {
@@ -31783,6 +31800,10 @@ async function readManyExisting(backend, ids, onMalformed) {
31783
31800
  onMalformed({ id, reason: candidate.detail });
31784
31801
  continue;
31785
31802
  }
31803
+ if (candidate instanceof FilesystemIdentityAliasError && onAliased) {
31804
+ onAliased({ id, reason: candidate.message });
31805
+ continue;
31806
+ }
31786
31807
  throw candidate;
31787
31808
  }
31788
31809
  }
@@ -31795,7 +31816,7 @@ async function scanMatching(backend, filter, onSkip) {
31795
31816
  for (const result of await readManyExisting(backend, ids, onSkip)) {
31796
31817
  if (matchesFilter(result.doc, filter)) results.push(result);
31797
31818
  }
31798
- results.sort((a, b) => a.doc.id.localeCompare(b.doc.id));
31819
+ results.sort((a, b) => compareCodeUnits(a.doc.id, b.doc.id));
31799
31820
  return results;
31800
31821
  }
31801
31822
  async function query(backend, filter = {}, options = {}) {
@@ -31804,7 +31825,7 @@ async function query(backend, filter = {}, options = {}) {
31804
31825
  async function queryHeads(backend, filter = {}, options = {}) {
31805
31826
  if (backend.queryHeads) {
31806
31827
  const rows = (await backend.queryHeads(filter, options.onSkip ? { onSkip: options.onSkip } : void 0)).filter((row) => matchesFilter(row, filter));
31807
- rows.sort((a, b) => a.id.localeCompare(b.id));
31828
+ rows.sort((a, b) => compareCodeUnits(a.id, b.id));
31808
31829
  return rows;
31809
31830
  }
31810
31831
  return (await scanMatching(backend, filter, options.onSkip)).map(({ doc, version: version2 }) => ({
@@ -31844,7 +31865,7 @@ async function queryEdges(backend, filter = {}, options = {}) {
31844
31865
  edges.push(link);
31845
31866
  }
31846
31867
  }
31847
- edges.sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to) || a.text.localeCompare(b.text));
31868
+ edges.sort((a, b) => compareCodeUnits(a.from, b.from) || compareCodeUnits(a.to, b.to) || compareCodeUnits(a.text, b.text));
31848
31869
  return edges;
31849
31870
  }
31850
31871
 
@@ -32360,6 +32381,11 @@ async function acquireFilesystemIdentityLock(key, identity, options = {}) {
32360
32381
  return claimLockPath(path.join(lockRoot, `${key}.lock`), owner, waitMs, pollMs, policy);
32361
32382
  }
32362
32383
 
32384
+ // ../core/src/identity-fold.ts
32385
+ function foldSegment(segment) {
32386
+ return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
32387
+ }
32388
+
32363
32389
  // ../core/src/filesystem-identity.ts
32364
32390
  async function replaceExistingLeaf(port, tmp, target, rel) {
32365
32391
  try {
@@ -32405,9 +32431,6 @@ function relSegments(rel) {
32405
32431
  }
32406
32432
  return segments;
32407
32433
  }
32408
- function foldSegment(segment) {
32409
- return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
32410
- }
32411
32434
  async function existingAnchor(resolved) {
32412
32435
  const tail = [];
32413
32436
  let candidate = resolved;
@@ -33424,11 +33447,6 @@ async function queryEdges2(bundle, filter = {}, options = {}) {
33424
33447
  // ../core/src/bundle.ts
33425
33448
  setDefaultBackendFactory((root) => new FilesystemBackend(root));
33426
33449
 
33427
- // ../core/src/code-unit-order.ts
33428
- function compareCodeUnits(a, b) {
33429
- return a < b ? -1 : a > b ? 1 : 0;
33430
- }
33431
-
33432
33450
  // ../core/src/managed-document-metadata.ts
33433
33451
  var MANAGED_DOCUMENT_METADATA_FIELDS = /* @__PURE__ */ new Set([
33434
33452
  "generated",
@@ -43795,7 +43813,7 @@ function replyWithinLimit(reply) {
43795
43813
  }
43796
43814
  function skippedReply(skipped) {
43797
43815
  if (skipped.length === 0) return {};
43798
- return { skipped: [...skipped].sort((a, b) => a.id.localeCompare(b.id)).slice(0, MAX_QUERY_ROWS) };
43816
+ return { skipped: [...skipped].sort((a, b) => compareCodeUnits(a.id, b.id)).slice(0, MAX_QUERY_ROWS) };
43799
43817
  }
43800
43818
  function boundedRows(rows, params, kinds) {
43801
43819
  const requested = params.limit === 0 || params.limit === void 0 ? MAX_QUERY_ROWS : Math.min(params.limit, MAX_QUERY_ROWS);
@@ -43910,7 +43928,7 @@ var BridgeService = class {
43910
43928
  for (const id of subscription.baseline.keys()) {
43911
43929
  if (!next.has(id)) removed.push(id);
43912
43930
  }
43913
- changes.sort((a, b) => a.id.localeCompare(b.id));
43931
+ changes.sort((a, b) => compareCodeUnits(a.id, b.id));
43914
43932
  removed.sort();
43915
43933
  if (changes.length === 0 && removed.length === 0) return { status: "unchanged" };
43916
43934
  if (changes.length > MAX_CHANGE_ROWS || removed.length > MAX_CHANGE_ROWS) {
@@ -43939,7 +43957,7 @@ var BridgeService = class {
43939
43957
  throw new Error("the bundle is too large for the experimental View polling snapshot");
43940
43958
  }
43941
43959
  return new Map(
43942
- [...rows].sort((a, b) => a.id.localeCompare(b.id)).map((row) => [row.id, row.version])
43960
+ [...rows].sort((a, b) => compareCodeUnits(a.id, b.id)).map((row) => [row.id, row.version])
43943
43961
  );
43944
43962
  }
43945
43963
  /**
@@ -44542,22 +44560,22 @@ function buildSnapshot(first) {
44542
44560
  });
44543
44561
  relationships.push(...parseLinksFromDoc(doc).map((link) => ({ ...link })));
44544
44562
  }
44545
- documents.sort((a, b) => a.id.localeCompare(b.id));
44546
- relationships.sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to) || a.text.localeCompare(b.text) || a.href.localeCompare(b.href));
44563
+ documents.sort((a, b) => compareCodeUnits(a.id, b.id));
44564
+ relationships.sort((a, b) => compareCodeUnits(a.from, b.from) || compareCodeUnits(a.to, b.to) || compareCodeUnits(a.text, b.text) || compareCodeUnits(a.href, b.href));
44547
44565
  const reserved = first.reserved.map((row) => ({
44548
44566
  dir: row.dir,
44549
44567
  name: row.name,
44550
44568
  version: row.version,
44551
44569
  object: addObject(objects, row.bytes, "text/markdown; charset=utf-8", "exact")
44552
44570
  }));
44553
- reserved.sort((a, b) => `${a.dir}/${a.name}`.localeCompare(`${b.dir}/${b.name}`));
44571
+ reserved.sort((a, b) => compareCodeUnits(`${a.dir}/${a.name}`, `${b.dir}/${b.name}`));
44554
44572
  const blobs = first.blobs.map((row) => ({
44555
44573
  key: row.key,
44556
44574
  version: row.version,
44557
44575
  contentType: row.contentType,
44558
44576
  object: addObject(objects, row.bytes, row.contentType, "exact")
44559
44577
  }));
44560
- blobs.sort((a, b) => a.key.localeCompare(b.key));
44578
+ blobs.sort((a, b) => compareCodeUnits(a.key, b.key));
44561
44579
  const blobsByKey = new Map(blobs.map((row) => [row.key, row]));
44562
44580
  const views = [];
44563
44581
  for (const { doc, version: version2 } of parsedDocs.values()) {
@@ -44599,7 +44617,7 @@ function buildSnapshot(first) {
44599
44617
  entryObject: blob.object
44600
44618
  });
44601
44619
  }
44602
- views.sort((a, b) => a.id.localeCompare(b.id));
44620
+ views.sort((a, b) => compareCodeUnits(a.id, b.id));
44603
44621
  const withoutDigest = {
44604
44622
  schema: PUBLICATION_SNAPSHOT_V1,
44605
44623
  schemaVersion: 1,