@somewhere-cloud/cli 0.38.158 → 0.38.159

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.159
4
+
5
+ - Docs summaries show how much of the topic you received and give commands for the remaining sections, the whole topic, and search. The same summary goes to a terminal, pipe or file. Use `somewhere docs <topic> --full` when you need the complete topic.
6
+
3
7
  ## 0.38.158
4
8
 
5
9
  - `somewhere cron run <name> --wait` reports job completion sooner.
@@ -88055,7 +88055,7 @@ function renderDocsIndex(pages, groups) {
88055
88055
  lines.push("", "Quick links:");
88056
88056
  for (const [name, entry] of Object.entries(TOPICS))
88057
88057
  lines.push(` ${name.padEnd(10)} ${entry.blurb}`);
88058
- lines.push("", `Open a topic: ${cliInvocation()} docs <topic> (full when piped or redirected)`, `Open a section: ${cliInvocation()} docs <topic> --section <id>`, `Whole topic: ${cliInvocation()} docs <topic> --full`, `Search all docs: ${cliInvocation()} docs --search "<words>"`, `Download Markdown: ${cliInvocation()} docs pull`, `Full manual: ${cliInvocation()} docs --full (very large)`);
88058
+ lines.push("", `Open a topic: ${cliInvocation()} docs <topic> `, `Open a section: ${cliInvocation()} docs <topic> --section <id>`, `Whole topic: ${cliInvocation()} docs <topic> --full`, `Search all docs: ${cliInvocation()} docs --search "<words>"`, `Download Markdown: ${cliInvocation()} docs pull`, `Full manual: ${cliInvocation()} docs --full (very large)`);
88059
88059
  return lines.join("\n") + "\n";
88060
88060
  }
88061
88061
  async function fetchDocsSearch(query, topic) {
@@ -88116,19 +88116,45 @@ async function writeResponseBodyToStdout(res) {
88116
88116
  }
88117
88117
  }
88118
88118
  function topicSummary(content, topic, full) {
88119
+ if (hasViewNotice(content))
88120
+ return withNewline(content);
88119
88121
  const command = `${cliInvocation()} docs ${commandArg(topic)}`;
88120
88122
  return `${content.trimEnd()}
88121
88123
 
88122
88124
  Full topic (${full} characters): ${command} --full
88123
88125
  `;
88124
88126
  }
88127
+ async function fetchPublishedDocsView(topic, view) {
88128
+ if (!/^[a-z0-9_.-]+$/i.test(topic))
88129
+ return null;
88130
+ const params = new URLSearchParams({ view: view.kind === "default" ? "summary" : view.kind });
88131
+ if (view.kind === "section")
88132
+ params.set("section", view.id);
88133
+ const response = await fetchWithProxy(`${DOCS_BASE2}/docs/${encodeURIComponent(topic.toLowerCase())}.txt?${params}`);
88134
+ if (!response.ok || !response.headers.get("content-type")?.includes("application/json"))
88135
+ return null;
88136
+ const value = await response.json();
88137
+ if (!value || typeof value !== "object")
88138
+ return null;
88139
+ const result = value;
88140
+ if (typeof result.topic !== "string" || typeof result.text !== "string" || typeof result.view !== "string" || typeof result.complete !== "boolean" || /(?:^|\n)No section "/.test(result.text))
88141
+ return null;
88142
+ return { topic: result.topic, content: result.text, view: result.view, complete: result.complete, version: docsVersion(result.version) };
88143
+ }
88144
+ function hasViewNotice(content) {
88145
+ return /^Showing (?:the whole topic \(|[^\n]+ of this topic \()/m.test(content);
88146
+ }
88147
+ function displayDocs(content) {
88148
+ return withNewline(hasViewNotice(content) ? content.replace(/^\[docs\][^\n]*\n/, "") : content);
88149
+ }
88125
88150
  function registerDocs(program2) {
88126
- program2.command("docs [topic] [terms...]").description(`Read platform docs. No login needed \u2014 every topic is public. With no topic, prints the topic index. Search with \`${cliInvocation()} docs --search "<words>"\`. Quick topics: ` + Object.keys(TOPICS).join(", ") + `. Example manual topic: \`${cliInvocation()} docs sw.db\`.`).option("--list", `List available topics (the same index bare \`${cliInvocation()} docs\` prints)`).option("--full", "Print the complete topic in a terminal; with no topic, the full manual").option("--search <words>", "Search matching sections across all live docs topics").option("--section <id>", "Print one section of a topic (ids are listed in the summary)").option("--json", "Print the selected document in a JSON envelope").addHelpText("after", `
88151
+ program2.command("docs [topic] [terms...]").description(`Read platform docs. No login needed \u2014 every topic is public. With no topic, prints the topic index. Search with \`${cliInvocation()} docs --search "<words>"\`. Quick topics: ` + Object.keys(TOPICS).join(", ") + `. Example manual topic: \`${cliInvocation()} docs sw.db\`.`).option("--list", `List available topics (the same index bare \`${cliInvocation()} docs\` prints)`).option("--full", "Print the complete topic; with no topic, print the full manual").option("--search <words>", "Search matching sections across all live docs topics").option("--section <id>", "Print one section of a topic (ids are listed in the summary)").option("--json", "Print the selected document in a JSON envelope").addHelpText("after", `
88127
88152
  Examples:
88128
88153
  ${cliInvocation()} docs # topic index
88129
88154
  ${cliInvocation()} docs --search "magic link" # matching sections across every topic
88130
88155
  ${cliInvocation()} docs pull # download Markdown into .somewhere/docs/
88131
- ${cliInvocation()} docs sw.auth # full when piped or redirected
88156
+ ${cliInvocation()} docs sw.auth # topic summary when the whole topic is long
88157
+ ${cliInvocation()} docs sw.auth --full # complete topic for a terminal, pipe or file
88132
88158
  ${cliInvocation()} docs sw.auth setRoles # search within this topic
88133
88159
  ${cliInvocation()} docs sw.auth --section <id> # one section
88134
88160
  ${cliInvocation()} docs --full # the whole manual (very large)
@@ -88214,7 +88240,7 @@ ${dim(result.open)}
88214
88240
  }
88215
88241
  return;
88216
88242
  }
88217
- const view = opts.section !== void 0 ? { kind: "section", id: opts.section } : opts.full || topic !== void 0 && !process.stdout.isTTY ? { kind: "full" } : { kind: "default" };
88243
+ const view = opts.section !== void 0 ? { kind: "section", id: opts.section } : opts.full ? { kind: "full" } : { kind: "default" };
88218
88244
  if (opts.list || topic === void 0 && view.kind === "default") {
88219
88245
  try {
88220
88246
  const { pages, groups, version: version2 } = await fetchPublicManifestWithGroups();
@@ -88274,19 +88300,30 @@ ${dim(`No account yet? Start with: ${cliInvocation()} docs start`)}`);
88274
88300
  if (/^Topic "[^\n]*" not found\./.test(content) || view.kind === "full" && status.complete === false || status.view === "summary" && status.complete === false && !full || view.kind === "section" && (status.view !== "section" || /(?:^|\n)No section "/.test(content))) {
88275
88301
  throw new Error("Authenticated docs did not return the requested view; trying the public index.");
88276
88302
  }
88277
- if (status.view === "summary" && status.complete === false)
88303
+ if (status.view === "summary" && status.complete === false) {
88278
88304
  content = topicSummary(content, resolvedTopic, Number(full));
88305
+ }
88279
88306
  await warnIfLocalDocsOlder();
88280
88307
  if (opts.json)
88281
88308
  printJson({ topic: requestedTopic, ...status, content });
88282
88309
  else
88283
- process.stdout.write(withNewline(content));
88310
+ process.stdout.write(displayDocs(content));
88284
88311
  return;
88285
88312
  } catch (e) {
88286
88313
  authenticatedFailure = e instanceof Error ? e.message : String(e);
88287
88314
  }
88288
88315
  }
88289
88316
  try {
88317
+ const published = await fetchPublishedDocsView(resolvedTopic, view).catch(() => null);
88318
+ if (published) {
88319
+ await warnIfLocalDocsOlder(published.version);
88320
+ const { topic: topic2, content, view: view2, complete } = published;
88321
+ if (opts.json)
88322
+ printJson({ topic: topic2, url: DOCS_BASE2 + PUBLIC_MANIFEST_PATH, source: "public", view: view2, complete, content });
88323
+ else
88324
+ process.stdout.write(displayDocs(content));
88325
+ return;
88326
+ }
88290
88327
  const { pages, aliases, version: version2 } = await fetchPublicManifestWithGroups();
88291
88328
  await warnIfLocalDocsOlder(version2);
88292
88329
  const page = findPublicDocsPage(pages, aliases, resolvedTopic);
@@ -88301,11 +88338,12 @@ ${dim(`No account yet? Start with: ${cliInvocation()} docs start`)}`);
88301
88338
  topic: page.id,
88302
88339
  url: DOCS_BASE2 + PUBLIC_MANIFEST_PATH,
88303
88340
  source: "public",
88304
- ...page.summary || page.summary_complete !== void 0 || view.kind !== "default" ? { view: rendered.view, complete: rendered.complete } : {},
88341
+ view: rendered.view,
88342
+ complete: rendered.complete,
88305
88343
  content: rendered.content
88306
88344
  });
88307
88345
  } else {
88308
- process.stdout.write(rendered.content);
88346
+ process.stdout.write(displayDocs(rendered.content));
88309
88347
  }
88310
88348
  return;
88311
88349
  }
@@ -88419,6 +88457,9 @@ var init_docs = __esm({
88419
88457
  __name(renderPublicPage, "renderPublicPage");
88420
88458
  __name(writeResponseBodyToStdout, "writeResponseBodyToStdout");
88421
88459
  __name(topicSummary, "topicSummary");
88460
+ __name(fetchPublishedDocsView, "fetchPublishedDocsView");
88461
+ __name(hasViewNotice, "hasViewNotice");
88462
+ __name(displayDocs, "displayDocs");
88422
88463
  __name(registerDocs, "registerDocs");
88423
88464
  }
88424
88465
  });