saturndocs 0.1.2 → 0.2.0

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.
Files changed (50) hide show
  1. package/dist/{auth-FRCFGNYT.js → auth-DUYYFNEZ.js} +4 -4
  2. package/dist/{brokenLinks-TTOBP4P7.js → brokenLinks-E364XYH3.js} +1 -1
  3. package/dist/{chunk-SABK3R2P.js → chunk-2RZEC3VH.js} +132 -136
  4. package/dist/{chunk-KGJESHJC.js → chunk-2YTD2XNI.js} +1 -1
  5. package/dist/{chunk-QLFODLVN.js → chunk-4J33CCAC.js} +18 -15
  6. package/dist/{chunk-STCCGFKC.js → chunk-4ORVQCHY.js} +1 -1
  7. package/dist/chunk-56U46JVN.js +28 -0
  8. package/dist/chunk-6JGAA5TF.js +86 -0
  9. package/dist/{chunk-GYRVGWDM.js → chunk-ADZOBRZE.js} +88 -6
  10. package/dist/chunk-D3CLXV7D.js +131 -0
  11. package/dist/{chunk-5KX4ZK5E.js → chunk-DBMFJXKP.js} +11 -5
  12. package/dist/chunk-EB7RWFQA.js +3821 -0
  13. package/dist/{chunk-R3X2DPFF.js → chunk-FGKHDJOC.js} +133 -4
  14. package/dist/{chunk-3V753MRI.js → chunk-GGGL4O7Z.js} +2 -2
  15. package/dist/{chunk-OZWTXMO3.js → chunk-GLI3OUYL.js} +57 -4
  16. package/dist/{chunk-3P2OFTXR.js → chunk-K5YY6NSF.js} +2 -2
  17. package/dist/{chunk-TKISMN3P.js → chunk-KOJJUISB.js} +2 -2
  18. package/dist/chunk-O72DR5FK.js +152 -0
  19. package/dist/{chunk-U7PKMSB3.js → chunk-QF2ADHQZ.js} +4 -4
  20. package/dist/{chunk-S45UWCML.js → chunk-SVDVBZPA.js} +9 -9
  21. package/dist/{chunk-CMNX5DLQ.js → chunk-W3GKH5DY.js} +2 -2
  22. package/dist/{chunk-N7QPZMLP.js → chunk-WBI4EI3D.js} +1 -1
  23. package/dist/{chunk-OEAEX5YW.js → chunk-WHNL6UYJ.js} +8 -2
  24. package/dist/chunk-WUPP3THV.js +87 -0
  25. package/dist/chunk-YSFP37B7.js +76 -0
  26. package/dist/{chunk-XO4CUC7V.js → chunk-Z5CBPJ2L.js} +3 -3
  27. package/dist/cli.js +3 -3
  28. package/dist/coverage-EBWULNQQ.js +15 -0
  29. package/dist/deploy-QUVLOGII.js +13 -0
  30. package/dist/dist-XISZDQTR.js +120 -0
  31. package/dist/index.d.ts +35 -2
  32. package/dist/index.js +66 -38
  33. package/dist/{init-7T5TEPBH.js → init-PI4VTG7V.js} +2 -2
  34. package/dist/lint-SXBP37G3.js +13 -0
  35. package/dist/{manage-MKH27U3B.js → manage-OB6DQK3Q.js} +2 -2
  36. package/dist/nav-R4OORY2G.js +14 -0
  37. package/dist/{openapiCheck-KGBQJTIQ.js → openapiCheck-X2QQGETY.js} +6 -6
  38. package/dist/{pages-HIPXRLSY.js → pages-MKFZAVGI.js} +5 -5
  39. package/dist/{read-DMSJUEDA.js → read-VECMKHBW.js} +4 -4
  40. package/dist/{read-ZEVUZNNB.js → read-WWOMA67R.js} +4 -4
  41. package/dist/requests-A7WC3B4M.js +13 -0
  42. package/dist/{schema-XJUEZSIW.js → schema-NKOXZHQH.js} +3 -3
  43. package/dist/{sites-I4WI2MPG.js → sites-XMMGWPY2.js} +4 -4
  44. package/dist/{status-7R3NOI5H.js → status-SYIUUSSU.js} +4 -4
  45. package/dist/{suggestions-4WFQ3APX.js → suggestions-GX5CQK26.js} +4 -4
  46. package/dist/{validate-VXL4PL42.js → validate-D4I3DY2W.js} +5 -3
  47. package/package.json +6 -5
  48. package/dist/chunk-I6U4V7B4.js +0 -1552
  49. package/dist/deploy-QU7DCKWU.js +0 -11
  50. package/dist/requests-H5MIGBIS.js +0 -13
@@ -2,6 +2,124 @@
2
2
  import { z } from "zod";
3
3
  import { parse as parseToml } from "smol-toml";
4
4
  import { readFile } from "fs/promises";
5
+ var BuildRuleError = class extends Error {
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.name = "BuildRuleError";
10
+ this.code = code;
11
+ }
12
+ };
13
+ var NAV_VARIANT_DIRECTORY = "__gs-variants";
14
+ var NAV_VARIANT_SOURCE_DIRECTORY = "gs-nav-variants";
15
+ var NAV_VARIANT_GROUP_CAP = 4;
16
+ function knownGroups(corpus) {
17
+ return [...new Set(corpus.pages.flatMap((page) => [...page.groups]))].sort();
18
+ }
19
+ function assertGroupCapacity(groups) {
20
+ if (groups.length <= NAV_VARIANT_GROUP_CAP) return;
21
+ throw new Error(
22
+ `Reader-scoped navigation supports at most ${NAV_VARIANT_GROUP_CAP} reader groups (${2 ** NAV_VARIANT_GROUP_CAP - 1} rendered variants). This corpus references ${groups.length}: ${groups.join(", ")}. Until the group count drops to the cap the build cannot hide restricted pages from the sidebar, tabs, pagination, and the known-pages list, so every reader would see links to pages they cannot open.`
23
+ );
24
+ }
25
+ function reservedPageClash(docIds, hasVariants) {
26
+ if (!hasVariants) return null;
27
+ for (const reserved of [NAV_VARIANT_SOURCE_DIRECTORY, NAV_VARIANT_DIRECTORY]) {
28
+ const docId = docIds.find((id) => id === reserved || id.startsWith(`${reserved}/`));
29
+ if (docId !== void 0) return { docId, reserved };
30
+ }
31
+ return null;
32
+ }
33
+ function normalizedRedirectPath(value) {
34
+ if (!value.startsWith("/") || value.startsWith("//") || value.includes("\\")) return value;
35
+ const path = value.split(/[?#]/, 1)[0]?.replace(/\/+$/, "") ?? "";
36
+ return path || "/";
37
+ }
38
+ function resolveRootRedirectDestination(redirects, knownPagePaths) {
39
+ const bySource = new Map(
40
+ redirects.map((redirect) => [normalizedRedirectPath(redirect.source), redirect.destination])
41
+ );
42
+ for (const source of bySource.keys()) {
43
+ const visited2 = /* @__PURE__ */ new Set();
44
+ let current = source;
45
+ while (bySource.has(current)) {
46
+ if (visited2.has(current)) {
47
+ throw new BuildRuleError("redirect_cycle", `docs.json redirects contain a cycle involving ${current}.`);
48
+ }
49
+ visited2.add(current);
50
+ current = normalizedRedirectPath(bySource.get(current) ?? "");
51
+ }
52
+ }
53
+ if (!bySource.has("/")) return void 0;
54
+ let destination = normalizedRedirectPath(bySource.get("/") ?? "");
55
+ const visited = /* @__PURE__ */ new Set(["/"]);
56
+ while (bySource.has(destination)) {
57
+ if (destination === "/ask") {
58
+ throw new BuildRuleError("root_redirect_to_ask", 'The root redirect destination must not be "/ask".');
59
+ }
60
+ if (visited.has(destination)) {
61
+ throw new BuildRuleError("redirect_cycle", `docs.json redirects contain a cycle involving ${destination}.`);
62
+ }
63
+ visited.add(destination);
64
+ destination = normalizedRedirectPath(bySource.get(destination) ?? "");
65
+ }
66
+ if (destination === "/ask") {
67
+ throw new BuildRuleError("root_redirect_to_ask", 'The root redirect destination must not be "/ask".');
68
+ }
69
+ if (!knownPagePaths.has(destination)) {
70
+ throw new BuildRuleError(
71
+ "root_redirect_unknown_page",
72
+ `The resolved root redirect destination ${JSON.stringify(destination)} is not a known page path.`
73
+ );
74
+ }
75
+ return destination;
76
+ }
77
+ function openApiPublicationName(specPath) {
78
+ const filename = specPath.slice(specPath.lastIndexOf("/") + 1);
79
+ return filename.replace(/\.(?:json|ya?ml)$/i, "");
80
+ }
81
+ function openApiPublicationCollision(specPaths) {
82
+ const byName = /* @__PURE__ */ new Map();
83
+ for (const specPath of specPaths) {
84
+ const name = openApiPublicationName(specPath);
85
+ const taken = byName.get(name);
86
+ if (taken === void 0) byName.set(name, specPath);
87
+ else if (taken !== specPath) return { first: taken, second: specPath, name };
88
+ }
89
+ return null;
90
+ }
91
+ function ungatedOpenApiSpecPaths(groups, groupsForPage) {
92
+ const gated = /* @__PURE__ */ new Set();
93
+ const ordered = [];
94
+ for (const group of groups) {
95
+ if (!ordered.includes(group.openapi)) ordered.push(group.openapi);
96
+ if (group.pages.some((page) => groupsForPage(page).length > 0)) gated.add(group.openapi);
97
+ }
98
+ return ordered.filter((specPath) => !gated.has(specPath));
99
+ }
100
+ var FORBIDDEN_THEME_CSS_SUBSTRINGS = [
101
+ "#gs-ask-ai",
102
+ "gs-ai-panel",
103
+ "data-astro-transition-persist"
104
+ ];
105
+ function themeCssProblems(source) {
106
+ const problems = [];
107
+ for (const forbidden of FORBIDDEN_THEME_CSS_SUBSTRINGS) {
108
+ if (source.includes(forbidden)) {
109
+ problems.push(`theme.css contains forbidden substring ${JSON.stringify(forbidden)}.`);
110
+ }
111
+ }
112
+ source.split(/\r?\n/).forEach((line, index) => {
113
+ const normalized = line.toLowerCase();
114
+ if (normalized.includes("!important") && normalized.includes("width") && normalized.includes("gs-ask")) {
115
+ problems.push(`theme.css line ${index + 1} combines gs-ask, width, and !important.`);
116
+ }
117
+ });
118
+ if (/[^{}]*\.gs-header\b[^{}]*\{[^{}]*\bposition\s*:\s*fixed\b[^{}]*\}/is.test(source)) {
119
+ problems.push("theme.css sets position: fixed on .gs-header.");
120
+ }
121
+ return problems;
122
+ }
5
123
  var DEFAULT_BACKGROUND_PRESET = "linear-wash";
6
124
  var CODE_THEMES = [
7
125
  "andromeeda",
@@ -532,6 +650,8 @@ function parseModelsConfigValue(toml, label, platformApiBase) {
532
650
  }
533
651
  return applyModelsDefaults(result.data, platformApiBase);
534
652
  }
653
+ var HOSTED_MODEL_API_BASE = "https://openrouter.ai/api/v1";
654
+ var HOSTED_MODEL_KEY_ENV = "OPENROUTER_API_KEY";
535
655
  function applyModelsDefaults(config, platformApiBase) {
536
656
  const endpoint = config.endpoint ?? {};
537
657
  const behavior = config.behavior ?? {};
@@ -542,8 +662,8 @@ function applyModelsDefaults(config, platformApiBase) {
542
662
  suggestion: config.models.suggestion ?? config.models.synthesis
543
663
  },
544
664
  endpoint: {
545
- api_base: endpoint.api_base ?? platformBase(platformApiBase),
546
- api_key_env: endpoint.api_key_env ?? "OPENROUTER_API_KEY"
665
+ api_base: endpoint.api_base ?? platformModelApiBase(platformApiBase),
666
+ api_key_env: endpoint.api_key_env ?? HOSTED_MODEL_KEY_ENV
547
667
  },
548
668
  behavior: {
549
669
  cache: behavior.cache ?? true,
@@ -551,15 +671,24 @@ function applyModelsDefaults(config, platformApiBase) {
551
671
  }
552
672
  };
553
673
  }
554
- function platformBase(platformApiBase) {
674
+ function platformModelApiBase(platformApiBase) {
555
675
  const trimmed = platformApiBase?.trim() ?? "";
556
- return trimmed === "" ? "https://openrouter.ai/api/v1" : trimmed;
676
+ return trimmed === "" ? HOSTED_MODEL_API_BASE : trimmed;
557
677
  }
558
678
  function errorMessage(cause) {
559
679
  return cause instanceof Error ? cause.message : String(cause);
560
680
  }
561
681
 
562
682
  export {
683
+ BuildRuleError,
684
+ knownGroups,
685
+ assertGroupCapacity,
686
+ reservedPageClash,
687
+ normalizedRedirectPath,
688
+ resolveRootRedirectDestination,
689
+ openApiPublicationCollision,
690
+ ungatedOpenApiSpecPaths,
691
+ themeCssProblems,
563
692
  parseDocsConfig,
564
693
  navigationGroups,
565
694
  loadDocsConfig,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  asCliError,
3
3
  clientFor
4
- } from "./chunk-TKISMN3P.js";
4
+ } from "./chunk-KOJJUISB.js";
5
5
  import {
6
6
  applyCommandHelp
7
7
  } from "./chunk-M2BZEDAS.js";
@@ -20,7 +20,7 @@ import {
20
20
  statusRecovery,
21
21
  statusSections,
22
22
  successResult
23
- } from "./chunk-GYRVGWDM.js";
23
+ } from "./chunk-ADZOBRZE.js";
24
24
 
25
25
  // src/commands/status.ts
26
26
  var STATUS_METADATA = Object.freeze([
@@ -1,11 +1,25 @@
1
+ import {
2
+ collectOutsideRootFiles,
3
+ collectSourceFiles,
4
+ pageSourcePaths,
5
+ violationErrors
6
+ } from "./chunk-O72DR5FK.js";
7
+ import {
8
+ RESERVED_URL_PREFIXES,
9
+ findUnresolvedLinks,
10
+ outlineDocId,
11
+ resolveHref,
12
+ validateBundleSemanticsAsync,
13
+ validateBundleStructure
14
+ } from "./chunk-EB7RWFQA.js";
1
15
  import {
2
16
  parseOpenApiFile
3
- } from "./chunk-S45UWCML.js";
17
+ } from "./chunk-SVDVBZPA.js";
4
18
  import {
5
19
  loadDocsConfig,
6
20
  loadModelsConfig,
7
21
  navigationGroups
8
- } from "./chunk-R3X2DPFF.js";
22
+ } from "./chunk-FGKHDJOC.js";
9
23
 
10
24
  // src/lib/pages.ts
11
25
  import { existsSync } from "fs";
@@ -519,6 +533,42 @@ function parseFrontmatter(raw) {
519
533
  function messageOf(error) {
520
534
  return error instanceof Error ? error.message : String(error);
521
535
  }
536
+ var isSiteRoot = (href) => (href.split("#")[0] ?? "").split("?")[0] === "/";
537
+ var RESERVED_SEGMENTS = new Set(RESERVED_URL_PREFIXES.map((prefix) => prefix.replace(/^\//, "").replace(/\/\*$/, "")));
538
+ var isReservedRoute = (target) => target !== null && RESERVED_SEGMENTS.has(target.split("/")[0] ?? "");
539
+ async function validateBundle(docsDir, routeDocIds) {
540
+ let files;
541
+ let outsideRoots;
542
+ try {
543
+ files = await collectSourceFiles(docsDir);
544
+ outsideRoots = await collectOutsideRootFiles(docsDir);
545
+ } catch (error) {
546
+ return [messageOf(error)];
547
+ }
548
+ const errors = violationErrors(validateBundleStructure([
549
+ ...files.map((file) => ({ path: file.path, size: file.bytes.byteLength })),
550
+ ...outsideRoots
551
+ ]));
552
+ const byPath = new Map(files.map((file) => [file.path, file.bytes]));
553
+ const pagePaths = pageSourcePaths(files);
554
+ if (errors.length === 0) {
555
+ errors.push(...violationErrors(await validateBundleSemanticsAsync({
556
+ docsJson: byPath.get("docs.json") ?? new Uint8Array(),
557
+ modelsToml: byPath.get("models.toml"),
558
+ pagePaths,
559
+ readFile: async (path) => byPath.get(path) ?? null
560
+ })));
561
+ }
562
+ const decoder = new TextDecoder();
563
+ const pages = pagePaths.map((path) => ({ path, docId: outlineDocId(path), source: decoder.decode(byPath.get(path)) }));
564
+ const docIds = /* @__PURE__ */ new Set([...pages.map((page) => page.docId), ...routeDocIds]);
565
+ for (const miss of findUnresolvedLinks(pages, docIds)) {
566
+ if (isSiteRoot(miss.href) && docIds.has("index")) continue;
567
+ if (isReservedRoute(resolveHref(miss.href, outlineDocId(miss.path)))) continue;
568
+ errors.push(`${miss.path}: link to ${miss.href} does not resolve to a page`);
569
+ }
570
+ return errors;
571
+ }
522
572
  async function validateDocs(docsDir) {
523
573
  const errors = [];
524
574
  const docsJsonPath = join2(docsDir, "docs.json");
@@ -560,6 +610,7 @@ async function validateDocs(docsDir) {
560
610
  errors.push(`Page "${entry}": ${messageOf(error)}`);
561
611
  }
562
612
  }
613
+ const operationDocIds = [];
563
614
  for (const group of navigationGroups(config)) {
564
615
  if (!group.openapi) continue;
565
616
  const openapiPath = join2(docsDir, group.openapi);
@@ -568,12 +619,14 @@ async function validateDocs(docsDir) {
568
619
  continue;
569
620
  }
570
621
  try {
571
- await parseOpenApiFile(openapiPath);
622
+ const spec = await parseOpenApiFile(openapiPath);
623
+ operationDocIds.push(...spec.operations.map((operation) => `api-reference/${operation.slug}`));
572
624
  } catch (error) {
573
625
  errors.push(`OpenAPI ${group.openapi}: ${messageOf(error)}`);
574
626
  }
575
627
  }
576
- return errors;
628
+ if (errors.length > 0) return errors;
629
+ return validateBundle(docsDir, operationDocIds);
577
630
  }
578
631
 
579
632
  export {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  asCliError,
3
3
  clientFor
4
- } from "./chunk-TKISMN3P.js";
4
+ } from "./chunk-KOJJUISB.js";
5
5
  import {
6
6
  applyCommandHelp
7
7
  } from "./chunk-M2BZEDAS.js";
@@ -13,7 +13,7 @@ import {
13
13
  listSites,
14
14
  resolveGlobalOptions,
15
15
  successResult
16
- } from "./chunk-GYRVGWDM.js";
16
+ } from "./chunk-ADZOBRZE.js";
17
17
 
18
18
  // src/commands/auth.ts
19
19
  var AUTH_METADATA = Object.freeze([
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  interruptSignal
3
- } from "./chunk-KGJESHJC.js";
3
+ } from "./chunk-2YTD2XNI.js";
4
4
  import {
5
5
  CliError,
6
6
  createClient,
7
7
  isManagementError
8
- } from "./chunk-GYRVGWDM.js";
8
+ } from "./chunk-ADZOBRZE.js";
9
9
 
10
10
  // src/adapter/client.ts
11
11
  var TOKEN_VARIABLE = "SATURNDOCS_MANAGEMENT_TOKEN";
@@ -0,0 +1,152 @@
1
+ import {
2
+ TAR_TRAILER_SIZE,
3
+ paxRecord,
4
+ tarHeader,
5
+ tarPadding,
6
+ validateBundleSemantics,
7
+ validateBundleStructure
8
+ } from "./chunk-EB7RWFQA.js";
9
+
10
+ // src/lib/bundle.ts
11
+ import { createHash } from "crypto";
12
+ import { createReadStream, createWriteStream } from "fs";
13
+ import { lstat, mkdir, mkdtemp, readFile, readdir, rm, stat } from "fs/promises";
14
+ import { tmpdir } from "os";
15
+ import { join, posix, resolve } from "path";
16
+ import { Readable } from "stream";
17
+ import { pipeline } from "stream/promises";
18
+ import { createGzip } from "zlib";
19
+ var encoder = new TextEncoder();
20
+ var isLocalNoise = (entry) => entry.name.startsWith(".") || entry.isDirectory() && entry.name === "node_modules";
21
+ async function collectDirectory(root, relative, files) {
22
+ const absolute = join(root, ...relative.split("/"));
23
+ const entries = await readdir(absolute, { withFileTypes: true });
24
+ for (const entry of entries.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)) {
25
+ if (isLocalNoise(entry)) continue;
26
+ const path = posix.join(relative, entry.name);
27
+ const absolutePath = join(root, ...path.split("/"));
28
+ if (entry.isSymbolicLink()) throw new Error(`source bundle cannot contain a symbolic link: ${path}`);
29
+ if (entry.isDirectory()) await collectDirectory(root, path, files);
30
+ else if (entry.isFile()) files.push({ path, absolutePath, bytes: new Uint8Array(await readFile(absolutePath)) });
31
+ else throw new Error(`source bundle contains an unsupported filesystem entry: ${path}`);
32
+ }
33
+ }
34
+ var SOURCE_FILES = ["docs.json", "models.toml"];
35
+ var SOURCE_ROOTS = ["pages", "public", "openapi"];
36
+ async function collectSourceFiles(docsDir) {
37
+ const files = [];
38
+ for (const [legacy, replacement] of [["assets", "public"], ["api-reference", "openapi"]]) {
39
+ if (await lstat(join(docsDir, legacy)).catch(() => null) !== null) {
40
+ throw new Error(`legacy ${legacy}/ source is not publishable; move it to ${replacement}/`);
41
+ }
42
+ }
43
+ for (const name of SOURCE_FILES) {
44
+ const absolutePath = join(docsDir, name);
45
+ const info = await lstat(absolutePath).catch(() => null);
46
+ if (info === null) continue;
47
+ if (info.isSymbolicLink() || !info.isFile()) throw new Error(`${name} must be a regular file`);
48
+ files.push({ path: name, absolutePath, bytes: new Uint8Array(await readFile(absolutePath)) });
49
+ }
50
+ for (const name of SOURCE_ROOTS) {
51
+ const absolutePath = join(docsDir, name);
52
+ const info = await lstat(absolutePath).catch(() => null);
53
+ if (info === null) continue;
54
+ if (info.isSymbolicLink() || !info.isDirectory()) throw new Error(`${name} must be a regular directory`);
55
+ await collectDirectory(docsDir, name, files);
56
+ }
57
+ return files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
58
+ }
59
+ async function collectOutsideRootFiles(docsDir) {
60
+ const inRoots = /* @__PURE__ */ new Set([...SOURCE_FILES, ...SOURCE_ROOTS]);
61
+ const files = [];
62
+ const walk = async (relative) => {
63
+ for (const entry of await readdir(join(docsDir, ...relative.split("/")), { withFileTypes: true })) {
64
+ const path = posix.join(relative, entry.name);
65
+ if (isLocalNoise(entry) || relative === "" && inRoots.has(entry.name)) continue;
66
+ if (entry.isDirectory()) {
67
+ await walk(path);
68
+ } else if (entry.isFile()) {
69
+ files.push({ path, size: (await lstat(join(docsDir, ...path.split("/")))).size });
70
+ }
71
+ }
72
+ };
73
+ await walk("");
74
+ return files;
75
+ }
76
+ function pageSourcePaths(files) {
77
+ return files.map((file) => file.path).filter((path) => path.startsWith("pages/") && /\.(?:md|mdx)$/i.test(path));
78
+ }
79
+ function violationErrors(violations) {
80
+ return violations.filter((violation) => violation.severity === "error").map((violation) => `${violation.path ?? "bundle"}: ${violation.message}`);
81
+ }
82
+ function validateSourceFiles(files) {
83
+ const structural = validateBundleStructure(files.map((file) => ({ path: file.path, size: file.bytes.byteLength })));
84
+ const errors = violationErrors(structural);
85
+ if (errors.length > 0) throw new Error(errors.join("\n"));
86
+ const byPath = new Map(files.map((file) => [file.path, file.bytes]));
87
+ const semantic = validateBundleSemantics({
88
+ docsJson: byPath.get("docs.json") ?? new Uint8Array(),
89
+ modelsToml: byPath.get("models.toml"),
90
+ pagePaths: pageSourcePaths(files),
91
+ readFile: (path) => byPath.get(path) ?? null
92
+ });
93
+ const semanticErrors = violationErrors(semantic);
94
+ if (semanticErrors.length > 0) throw new Error(semanticErrors.join("\n"));
95
+ return [...structural, ...semantic].filter((violation) => violation.severity === "warning");
96
+ }
97
+ async function* tarEntries(files) {
98
+ for (let index = 0; index < files.length; index += 1) {
99
+ const file = files[index];
100
+ let headerName = file.path;
101
+ if (encoder.encode(file.path).byteLength > 100) {
102
+ const pax = paxRecord("path", file.path);
103
+ yield tarHeader(`PaxHeaders/${index}`, pax.byteLength, { type: "x", mode: 384 });
104
+ yield pax;
105
+ const paxPadding = tarPadding(pax.byteLength);
106
+ if (paxPadding > 0) yield new Uint8Array(paxPadding);
107
+ headerName = `file-${index}`;
108
+ }
109
+ yield tarHeader(headerName, file.bytes.byteLength);
110
+ yield file.bytes;
111
+ const filePadding = tarPadding(file.bytes.byteLength);
112
+ if (filePadding > 0) yield new Uint8Array(filePadding);
113
+ }
114
+ yield new Uint8Array(TAR_TRAILER_SIZE);
115
+ }
116
+ async function fileSha256(path) {
117
+ const hash = createHash("sha256");
118
+ for await (const chunk of createReadStream(path)) hash.update(chunk);
119
+ return hash.digest("hex");
120
+ }
121
+ async function createBundleArchive(inputDir) {
122
+ const docsDir = resolve(inputDir);
123
+ const info = await lstat(docsDir).catch(() => null);
124
+ if (info === null || !info.isDirectory() || info.isSymbolicLink()) throw new Error(`docs directory not found: ${docsDir}`);
125
+ const files = await collectSourceFiles(docsDir);
126
+ const warnings = validateSourceFiles(files);
127
+ const temporaryRoot = await mkdtemp(join(tmpdir(), "saturndocs-deploy-"));
128
+ await mkdir(temporaryRoot, { recursive: true });
129
+ const archivePath = join(temporaryRoot, "source.tar.gz");
130
+ try {
131
+ await pipeline(Readable.from(tarEntries(files)), createGzip({ level: 9 }), createWriteStream(archivePath, { mode: 384 }));
132
+ const archiveInfo = await stat(archivePath);
133
+ return {
134
+ path: archivePath,
135
+ byteLength: archiveInfo.size,
136
+ sha256: await fileSha256(archivePath),
137
+ warnings,
138
+ cleanup: () => rm(temporaryRoot, { recursive: true, force: true })
139
+ };
140
+ } catch (error) {
141
+ await rm(temporaryRoot, { recursive: true, force: true });
142
+ throw error;
143
+ }
144
+ }
145
+
146
+ export {
147
+ collectSourceFiles,
148
+ collectOutsideRootFiles,
149
+ pageSourcePaths,
150
+ violationErrors,
151
+ createBundleArchive
152
+ };
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  readTextInput
3
- } from "./chunk-N7QPZMLP.js";
3
+ } from "./chunk-WBI4EI3D.js";
4
4
  import {
5
5
  asCliError,
6
6
  clientFor
7
- } from "./chunk-TKISMN3P.js";
7
+ } from "./chunk-KOJJUISB.js";
8
8
  import {
9
9
  interruptSignal
10
- } from "./chunk-KGJESHJC.js";
10
+ } from "./chunk-2YTD2XNI.js";
11
11
  import {
12
12
  applyCommandHelp
13
13
  } from "./chunk-M2BZEDAS.js";
@@ -31,7 +31,7 @@ import {
31
31
  retryRequest,
32
32
  successResult,
33
33
  waitForRequest
34
- } from "./chunk-GYRVGWDM.js";
34
+ } from "./chunk-ADZOBRZE.js";
35
35
 
36
36
  // src/commands/requests/create.ts
37
37
  var REQUESTS_CREATE_METADATA = Object.freeze([
@@ -26,14 +26,14 @@ function decodePointerToken(token) {
26
26
  }
27
27
  function lookupPointer(root, ref) {
28
28
  const pointer = ref.slice(1);
29
- const tokens = pointer.split("/").filter((segment) => segment.length > 0);
29
+ const tokens = pointer === "" ? [] : pointer.slice(1).split("/");
30
30
  let current = root;
31
31
  for (const rawToken of tokens) {
32
32
  const token = decodePointerToken(rawToken);
33
33
  if (isRecord(current)) {
34
- current = current[token];
34
+ current = Object.hasOwn(current, token) ? current[token] : void 0;
35
35
  } else if (Array.isArray(current)) {
36
- current = current[Number(token)];
36
+ current = /^(?:0|[1-9][0-9]*)$/.test(token) ? current[Number(token)] : void 0;
37
37
  } else {
38
38
  current = void 0;
39
39
  }
@@ -159,13 +159,13 @@ function resolveRefs(node, root, seen, depth) {
159
159
  const nextSeen = new Set(seen);
160
160
  nextSeen.add(ref);
161
161
  const resolvedTarget = resolveRefs(target, root, nextSeen, depth + 1);
162
- const siblings = {};
162
+ const siblings = /* @__PURE__ */ Object.create(null);
163
163
  for (const [key, value] of Object.entries(node)) {
164
164
  if (key !== "$ref") siblings[key] = resolveRefs(value, root, seen, depth + 1);
165
165
  }
166
166
  return withSiblings(resolvedTarget, siblings, ref);
167
167
  }
168
- const out = {};
168
+ const out = /* @__PURE__ */ Object.create(null);
169
169
  for (const [key, value] of Object.entries(node)) {
170
170
  out[key] = resolveRefs(value, root, seen, depth + 1);
171
171
  }
@@ -194,13 +194,13 @@ async function resolveRefsAsync(node, root, seen, depth, context) {
194
194
  const nextSeen = new Set(seen);
195
195
  nextSeen.add(marker);
196
196
  const resolvedTarget = local ? await resolveRefsAsync(lookupPointer(root, ref), root, nextSeen, depth + 1, context) : await context.resolver.resolveExternal(ref, context.currentFile, nextSeen, depth + 1);
197
- const siblings = {};
197
+ const siblings = /* @__PURE__ */ Object.create(null);
198
198
  for (const [key, value] of Object.entries(node)) {
199
199
  if (key !== "$ref") siblings[key] = await resolveRefsAsync(value, root, seen, depth + 1, context);
200
200
  }
201
201
  return withSiblings(resolvedTarget, siblings, ref);
202
202
  }
203
- const out = {};
203
+ const out = /* @__PURE__ */ Object.create(null);
204
204
  for (const [key, value] of Object.entries(node)) {
205
205
  out[key] = await resolveRefsAsync(value, root, seen, depth + 1, context);
206
206
  }
@@ -352,8 +352,8 @@ function normalizeSecurityScheme(name, raw) {
352
352
  return info;
353
353
  }
354
354
  function securitySchemeMap(resolved) {
355
- if (!isRecord(resolved)) return {};
356
- const map = {};
355
+ const map = /* @__PURE__ */ Object.create(null);
356
+ if (!isRecord(resolved)) return map;
357
357
  for (const [name, raw] of Object.entries(resolved)) {
358
358
  const info = normalizeSecurityScheme(name, raw);
359
359
  if (info) map[name] = info;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  asCliError,
3
3
  clientFor
4
- } from "./chunk-TKISMN3P.js";
4
+ } from "./chunk-KOJJUISB.js";
5
5
  import {
6
6
  applyCommandHelp
7
7
  } from "./chunk-M2BZEDAS.js";
@@ -15,7 +15,7 @@ import {
15
15
  resolveGlobalOptions,
16
16
  resolveTarget,
17
17
  successResult
18
- } from "./chunk-GYRVGWDM.js";
18
+ } from "./chunk-ADZOBRZE.js";
19
19
 
20
20
  // src/commands/sites.ts
21
21
  var SITES_METADATA = Object.freeze([
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  invalidInput
3
- } from "./chunk-GYRVGWDM.js";
3
+ } from "./chunk-ADZOBRZE.js";
4
4
 
5
5
  // src/adapter/input.ts
6
6
  import { readFile } from "fs/promises";
@@ -1,5 +1,5 @@
1
1
  // src/lib/links.ts
2
- import { existsSync } from "fs";
2
+ import { statSync } from "fs";
3
3
  import { readFile } from "fs/promises";
4
4
  import { dirname, extname, join, relative } from "path";
5
5
  import fg from "fast-glob";
@@ -36,7 +36,13 @@ async function scanBrokenLinks(distDir) {
36
36
  if (!isInternalLink(href)) continue;
37
37
  const candidates = candidatePaths(distDir, htmlFile, href);
38
38
  if (candidates.length === 0) continue;
39
- if (candidates.some((candidate) => existsSync(candidate))) continue;
39
+ if (candidates.some((candidate) => {
40
+ try {
41
+ return statSync(candidate, { throwIfNoEntry: false })?.isFile() === true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ })) continue;
40
46
  const key = `${source}\0${href}`;
41
47
  if (seen.has(key)) continue;
42
48
  seen.add(key);