superbee 0.4.4-pre.1 → 0.4.4-pre.3

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.
@@ -3,6 +3,11 @@ import { createHash } from "node:crypto";
3
3
  import { mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
 
6
+ // ../core/src/path-fold.ts
7
+ function foldPath(path2) {
8
+ return path2.normalize("NFC").toLowerCase().toUpperCase().toLowerCase().normalize("NFC");
9
+ }
10
+
6
11
  // ../core/src/errors.ts
7
12
  var InvalidInputError = class extends Error {
8
13
  constructor(message) {
@@ -175,7 +180,6 @@ function readStoredZip(archive) {
175
180
  return entries;
176
181
  }
177
182
  var WINDOWS_DEVICE_NAMES = /* @__PURE__ */ new Set(["CON", "PRN", "AUX", "NUL", ...Array.from({ length: 9 }, (_, i) => `COM${i + 1}`), ...Array.from({ length: 9 }, (_, i) => `LPT${i + 1}`)]);
178
- var fold = (segment) => segment.normalize("NFC").toLowerCase();
179
183
  function classifyEntryPath(entryPath) {
180
184
  const unsafe = (why) => new ExportArchiveError("unsafe_path", `the archive holds a path a bundle cannot keep (${why}): ${JSON.stringify(entryPath.slice(0, 200))}`);
181
185
  if (entryPath === "" || entryPath.length > 4096) throw unsafe("empty or too long");
@@ -209,13 +213,13 @@ function findEntryCollision(paths) {
209
213
  const dirs = /* @__PURE__ */ new Map();
210
214
  for (const entryPath of paths) {
211
215
  const segments = entryPath.split("/");
212
- const key = segments.map(fold).join("/");
216
+ const key = segments.map(foldPath).join("/");
213
217
  const file = files.get(key) ?? dirs.get(key)?.by;
214
218
  if (file !== void 0) return [file, entryPath];
215
219
  files.set(key, entryPath);
216
220
  for (let depth = 1; depth < segments.length; depth += 1) {
217
221
  const spelling = segments.slice(0, depth).join("/");
218
- const dirKey = segments.slice(0, depth).map(fold).join("/");
222
+ const dirKey = segments.slice(0, depth).map(foldPath).join("/");
219
223
  const asFile = files.get(dirKey);
220
224
  if (asFile !== void 0) return [asFile, entryPath];
221
225
  const seen = dirs.get(dirKey);
@@ -3418,6 +3418,13 @@ function isExternalHref(href) {
3418
3418
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(h) || h.startsWith("mailto:") || h.startsWith("#");
3419
3419
  }
3420
3420
  function extractMarkdownLinks(source, options = {}) {
3421
+ const out = [];
3422
+ for (const span of extractMarkdownLinkSpans(source, options)) {
3423
+ if (!span.image) out.push({ text: span.text, href: span.href });
3424
+ }
3425
+ return out;
3426
+ }
3427
+ function extractMarkdownLinkSpans(source, options = {}) {
3421
3428
  const body = options.skipCode ? maskMarkdownCode(source) : source;
3422
3429
  const out = [];
3423
3430
  let textOpen = -1;
@@ -3428,12 +3435,16 @@ function extractMarkdownLinks(source, options = {}) {
3428
3435
  const char = body[cursor];
3429
3436
  if (hrefRest) {
3430
3437
  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
- }
3438
+ const image = hrefRest.open > 0 && body[hrefRest.open - 1] === "!";
3439
+ out.push({
3440
+ text: source.slice(hrefRest.open + 1, hrefRest.close),
3441
+ href: source.slice(hrefRest.hrefStart, cursor),
3442
+ start: image ? hrefRest.open - 1 : hrefRest.open,
3443
+ end: cursor + 1,
3444
+ hrefStart: hrefRest.hrefStart,
3445
+ hrefEnd: cursor,
3446
+ image
3447
+ });
3437
3448
  textOpen = -1;
3438
3449
  afterClose = void 0;
3439
3450
  hrefFirst = void 0;
@@ -3813,12 +3824,13 @@ async function readDocVersioned(backend, id) {
3813
3824
  function isEnoent(err) {
3814
3825
  return typeof err === "object" && err !== null && err.code === "ENOENT";
3815
3826
  }
3816
- async function readManyExisting(backend, ids, onMalformed) {
3827
+ async function readManyExisting(backend, ids, onMalformed, onAliased) {
3817
3828
  try {
3818
3829
  return await backend.readMany(ids);
3819
3830
  } catch (err) {
3820
- const malformed = err instanceof MalformedDocumentError;
3821
- if (!isEnoent(err) && !(malformed && onMalformed)) throw err;
3831
+ const malformed = err instanceof MalformedDocumentError && onMalformed !== void 0;
3832
+ const aliased = err instanceof FilesystemIdentityAliasError && onAliased !== void 0;
3833
+ if (!isEnoent(err) && !malformed && !aliased) throw err;
3822
3834
  const out = [];
3823
3835
  for (const id of ids) {
3824
3836
  try {
@@ -3829,6 +3841,10 @@ async function readManyExisting(backend, ids, onMalformed) {
3829
3841
  onMalformed({ id, reason: candidate.detail });
3830
3842
  continue;
3831
3843
  }
3844
+ if (candidate instanceof FilesystemIdentityAliasError && onAliased) {
3845
+ onAliased({ id, reason: candidate.message });
3846
+ continue;
3847
+ }
3832
3848
  throw candidate;
3833
3849
  }
3834
3850
  }
@@ -4406,6 +4422,11 @@ async function acquireFilesystemIdentityLock(key, identity, options = {}) {
4406
4422
  return claimLockPath(path.join(lockRoot, `${key}.lock`), owner, waitMs, pollMs, policy);
4407
4423
  }
4408
4424
 
4425
+ // ../core/src/identity-fold.ts
4426
+ function foldSegment(segment) {
4427
+ return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
4428
+ }
4429
+
4409
4430
  // ../core/src/filesystem-identity.ts
4410
4431
  async function replaceExistingLeaf(port, tmp, target, rel) {
4411
4432
  try {
@@ -4451,9 +4472,6 @@ function relSegments(rel) {
4451
4472
  }
4452
4473
  return segments;
4453
4474
  }
4454
- function foldSegment(segment) {
4455
- return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
4456
- }
4457
4475
  async function existingAnchor(resolved) {
4458
4476
  const tail = [];
4459
4477
  let candidate = resolved;
@@ -5440,6 +5458,11 @@ async function queryEdges2(bundle, filter = {}, options = {}) {
5440
5458
  // ../core/src/bundle.ts
5441
5459
  setDefaultBackendFactory((root) => new FilesystemBackend(root));
5442
5460
 
5461
+ // ../core/src/code-unit-order.ts
5462
+ function compareCodeUnits(a, b) {
5463
+ return a < b ? -1 : a > b ? 1 : 0;
5464
+ }
5465
+
5443
5466
  // ../core/src/managed-document-metadata.ts
5444
5467
  var MANAGED_DOCUMENT_METADATA_FIELDS = /* @__PURE__ */ new Set([
5445
5468
  "generated",
@@ -6328,7 +6351,7 @@ function compareByMeaningfulChange(a, b) {
6328
6351
  } else if (b.timestampMs !== null) {
6329
6352
  return 1;
6330
6353
  }
6331
- return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
6354
+ return compareCodeUnits(a.id, b.id);
6332
6355
  }
6333
6356
  function sortByMeaningfulChange(rows, okfVersion) {
6334
6357
  return rows.map((row) => ({ row, key: meaningfulChangeOrderKey(row.id, row.frontmatter, okfVersion) })).sort((a, b) => compareByMeaningfulChange(a.key, b.key)).map(({ row }) => row);
@@ -31372,6 +31372,13 @@ function isExternalHref(href) {
31372
31372
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(h) || h.startsWith("mailto:") || h.startsWith("#");
31373
31373
  }
31374
31374
  function extractMarkdownLinks(source, options = {}) {
31375
+ const out = [];
31376
+ for (const span of extractMarkdownLinkSpans(source, options)) {
31377
+ if (!span.image) out.push({ text: span.text, href: span.href });
31378
+ }
31379
+ return out;
31380
+ }
31381
+ function extractMarkdownLinkSpans(source, options = {}) {
31375
31382
  const body = options.skipCode ? maskMarkdownCode(source) : source;
31376
31383
  const out = [];
31377
31384
  let textOpen = -1;
@@ -31382,12 +31389,16 @@ function extractMarkdownLinks(source, options = {}) {
31382
31389
  const char = body[cursor];
31383
31390
  if (hrefRest) {
31384
31391
  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
- }
31392
+ const image = hrefRest.open > 0 && body[hrefRest.open - 1] === "!";
31393
+ out.push({
31394
+ text: source.slice(hrefRest.open + 1, hrefRest.close),
31395
+ href: source.slice(hrefRest.hrefStart, cursor),
31396
+ start: image ? hrefRest.open - 1 : hrefRest.open,
31397
+ end: cursor + 1,
31398
+ hrefStart: hrefRest.hrefStart,
31399
+ hrefEnd: cursor,
31400
+ image
31401
+ });
31391
31402
  textOpen = -1;
31392
31403
  afterClose = void 0;
31393
31404
  hrefFirst = void 0;
@@ -31767,12 +31778,13 @@ async function readDocVersioned(backend, id) {
31767
31778
  function isEnoent(err) {
31768
31779
  return typeof err === "object" && err !== null && err.code === "ENOENT";
31769
31780
  }
31770
- async function readManyExisting(backend, ids, onMalformed) {
31781
+ async function readManyExisting(backend, ids, onMalformed, onAliased) {
31771
31782
  try {
31772
31783
  return await backend.readMany(ids);
31773
31784
  } catch (err) {
31774
- const malformed = err instanceof MalformedDocumentError;
31775
- if (!isEnoent(err) && !(malformed && onMalformed)) throw err;
31785
+ const malformed = err instanceof MalformedDocumentError && onMalformed !== void 0;
31786
+ const aliased = err instanceof FilesystemIdentityAliasError && onAliased !== void 0;
31787
+ if (!isEnoent(err) && !malformed && !aliased) throw err;
31776
31788
  const out = [];
31777
31789
  for (const id of ids) {
31778
31790
  try {
@@ -31783,6 +31795,10 @@ async function readManyExisting(backend, ids, onMalformed) {
31783
31795
  onMalformed({ id, reason: candidate.detail });
31784
31796
  continue;
31785
31797
  }
31798
+ if (candidate instanceof FilesystemIdentityAliasError && onAliased) {
31799
+ onAliased({ id, reason: candidate.message });
31800
+ continue;
31801
+ }
31786
31802
  throw candidate;
31787
31803
  }
31788
31804
  }
@@ -32360,6 +32376,11 @@ async function acquireFilesystemIdentityLock(key, identity, options = {}) {
32360
32376
  return claimLockPath(path.join(lockRoot, `${key}.lock`), owner, waitMs, pollMs, policy);
32361
32377
  }
32362
32378
 
32379
+ // ../core/src/identity-fold.ts
32380
+ function foldSegment(segment) {
32381
+ return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
32382
+ }
32383
+
32363
32384
  // ../core/src/filesystem-identity.ts
32364
32385
  async function replaceExistingLeaf(port, tmp, target, rel) {
32365
32386
  try {
@@ -32405,9 +32426,6 @@ function relSegments(rel) {
32405
32426
  }
32406
32427
  return segments;
32407
32428
  }
32408
- function foldSegment(segment) {
32409
- return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
32410
- }
32411
32429
  async function existingAnchor(resolved) {
32412
32430
  const tail = [];
32413
32431
  let candidate = resolved;
@@ -33424,6 +33442,11 @@ async function queryEdges2(bundle, filter = {}, options = {}) {
33424
33442
  // ../core/src/bundle.ts
33425
33443
  setDefaultBackendFactory((root) => new FilesystemBackend(root));
33426
33444
 
33445
+ // ../core/src/code-unit-order.ts
33446
+ function compareCodeUnits(a, b) {
33447
+ return a < b ? -1 : a > b ? 1 : 0;
33448
+ }
33449
+
33427
33450
  // ../core/src/managed-document-metadata.ts
33428
33451
  var MANAGED_DOCUMENT_METADATA_FIELDS = /* @__PURE__ */ new Set([
33429
33452
  "generated",
@@ -43543,7 +43566,7 @@ function compareByMeaningfulChange(a, b) {
43543
43566
  } else if (b.timestampMs !== null) {
43544
43567
  return 1;
43545
43568
  }
43546
- return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
43569
+ return compareCodeUnits(a.id, b.id);
43547
43570
  }
43548
43571
  function sortByMeaningfulChange(rows, okfVersion) {
43549
43572
  return rows.map((row) => ({ row, key: meaningfulChangeOrderKey(row.id, row.frontmatter, okfVersion) })).sort((a, b) => compareByMeaningfulChange(a.key, b.key)).map(({ row }) => row);