@somewhere-cloud/cli 0.38.157 → 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,13 @@
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
+
7
+ ## 0.38.158
8
+
9
+ - `somewhere cron run <name> --wait` reports job completion sooner.
10
+
3
11
  ## 0.38.157
4
12
 
5
13
  - Generated starter guides show how to import large CSV files in background jobs using batched writes.
@@ -42319,6 +42319,9 @@ var init_http = __esm({
42319
42319
  function interactivePollDelay(attempt) {
42320
42320
  return [150, 300, 600][attempt] ?? 1e3;
42321
42321
  }
42322
+ function jobPollDelay(elapsedMs) {
42323
+ return elapsedMs < 8e3 ? 150 : 1e3;
42324
+ }
42322
42325
  function retryAfterMs(value, now2 = Date.now()) {
42323
42326
  const header = value?.trim();
42324
42327
  if (!header)
@@ -42332,6 +42335,7 @@ var init_poll_delay = __esm({
42332
42335
  "dist/lib/poll-delay.js"() {
42333
42336
  "use strict";
42334
42337
  __name(interactivePollDelay, "interactivePollDelay");
42338
+ __name(jobPollDelay, "jobPollDelay");
42335
42339
  __name(retryAfterMs, "retryAfterMs");
42336
42340
  }
42337
42341
  });
@@ -88051,7 +88055,7 @@ function renderDocsIndex(pages, groups) {
88051
88055
  lines.push("", "Quick links:");
88052
88056
  for (const [name, entry] of Object.entries(TOPICS))
88053
88057
  lines.push(` ${name.padEnd(10)} ${entry.blurb}`);
88054
- 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)`);
88055
88059
  return lines.join("\n") + "\n";
88056
88060
  }
88057
88061
  async function fetchDocsSearch(query, topic) {
@@ -88112,19 +88116,45 @@ async function writeResponseBodyToStdout(res) {
88112
88116
  }
88113
88117
  }
88114
88118
  function topicSummary(content, topic, full) {
88119
+ if (hasViewNotice(content))
88120
+ return withNewline(content);
88115
88121
  const command = `${cliInvocation()} docs ${commandArg(topic)}`;
88116
88122
  return `${content.trimEnd()}
88117
88123
 
88118
88124
  Full topic (${full} characters): ${command} --full
88119
88125
  `;
88120
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
+ }
88121
88150
  function registerDocs(program2) {
88122
- 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", `
88123
88152
  Examples:
88124
88153
  ${cliInvocation()} docs # topic index
88125
88154
  ${cliInvocation()} docs --search "magic link" # matching sections across every topic
88126
88155
  ${cliInvocation()} docs pull # download Markdown into .somewhere/docs/
88127
- ${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
88128
88158
  ${cliInvocation()} docs sw.auth setRoles # search within this topic
88129
88159
  ${cliInvocation()} docs sw.auth --section <id> # one section
88130
88160
  ${cliInvocation()} docs --full # the whole manual (very large)
@@ -88210,7 +88240,7 @@ ${dim(result.open)}
88210
88240
  }
88211
88241
  return;
88212
88242
  }
88213
- 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" };
88214
88244
  if (opts.list || topic === void 0 && view.kind === "default") {
88215
88245
  try {
88216
88246
  const { pages, groups, version: version2 } = await fetchPublicManifestWithGroups();
@@ -88270,19 +88300,30 @@ ${dim(`No account yet? Start with: ${cliInvocation()} docs start`)}`);
88270
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))) {
88271
88301
  throw new Error("Authenticated docs did not return the requested view; trying the public index.");
88272
88302
  }
88273
- if (status.view === "summary" && status.complete === false)
88303
+ if (status.view === "summary" && status.complete === false) {
88274
88304
  content = topicSummary(content, resolvedTopic, Number(full));
88305
+ }
88275
88306
  await warnIfLocalDocsOlder();
88276
88307
  if (opts.json)
88277
88308
  printJson({ topic: requestedTopic, ...status, content });
88278
88309
  else
88279
- process.stdout.write(withNewline(content));
88310
+ process.stdout.write(displayDocs(content));
88280
88311
  return;
88281
88312
  } catch (e) {
88282
88313
  authenticatedFailure = e instanceof Error ? e.message : String(e);
88283
88314
  }
88284
88315
  }
88285
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
+ }
88286
88327
  const { pages, aliases, version: version2 } = await fetchPublicManifestWithGroups();
88287
88328
  await warnIfLocalDocsOlder(version2);
88288
88329
  const page = findPublicDocsPage(pages, aliases, resolvedTopic);
@@ -88297,11 +88338,12 @@ ${dim(`No account yet? Start with: ${cliInvocation()} docs start`)}`);
88297
88338
  topic: page.id,
88298
88339
  url: DOCS_BASE2 + PUBLIC_MANIFEST_PATH,
88299
88340
  source: "public",
88300
- ...page.summary || page.summary_complete !== void 0 || view.kind !== "default" ? { view: rendered.view, complete: rendered.complete } : {},
88341
+ view: rendered.view,
88342
+ complete: rendered.complete,
88301
88343
  content: rendered.content
88302
88344
  });
88303
88345
  } else {
88304
- process.stdout.write(rendered.content);
88346
+ process.stdout.write(displayDocs(rendered.content));
88305
88347
  }
88306
88348
  return;
88307
88349
  }
@@ -88415,6 +88457,9 @@ var init_docs = __esm({
88415
88457
  __name(renderPublicPage, "renderPublicPage");
88416
88458
  __name(writeResponseBodyToStdout, "writeResponseBodyToStdout");
88417
88459
  __name(topicSummary, "topicSummary");
88460
+ __name(fetchPublishedDocsView, "fetchPublishedDocsView");
88461
+ __name(hasViewNotice, "hasViewNotice");
88462
+ __name(displayDocs, "displayDocs");
88418
88463
  __name(registerDocs, "registerDocs");
88419
88464
  }
88420
88465
  });
@@ -89861,12 +89906,12 @@ async function folderPreviewTool(opts) {
89861
89906
  async function previewCurrentVersion(credential) {
89862
89907
  return previewToolClient(credential).call("GET", "/preview-tools/whoami");
89863
89908
  }
89864
- async function waitForPreviewJob(credential, jobId, timeoutSeconds, firstDelayMs = 0) {
89865
- const client = previewToolClient(credential);
89866
- const deadline = Date.now() + timeoutSeconds * 1e3;
89909
+ async function waitForPreviewJob(client, jobId, timeoutSeconds, firstDelayMs = 0) {
89910
+ const startedAt = Date.now();
89911
+ const deadline = startedAt + timeoutSeconds * 1e3;
89867
89912
  let job;
89868
89913
  let delay2 = firstDelayMs;
89869
- for (let attempt = 0; ; attempt++) {
89914
+ for (; ; ) {
89870
89915
  const remaining = deadline - Date.now();
89871
89916
  if (delay2 >= remaining) {
89872
89917
  if (remaining > 0)
@@ -89891,7 +89936,7 @@ async function waitForPreviewJob(credential, jobId, timeoutSeconds, firstDelayMs
89891
89936
  throw error3;
89892
89937
  retryAfter = Math.max(retryAfter, error3.meta.retryAfterMs);
89893
89938
  }
89894
- delay2 = Math.max(interactivePollDelay(attempt), retryAfter);
89939
+ delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter);
89895
89940
  }
89896
89941
  }
89897
89942
  var TERMINAL;
@@ -90212,7 +90257,11 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
90212
90257
  if (!Number.isFinite(timeout) || timeout < 1 || timeout > 3600)
90213
90258
  throw new Error("--timeout must be a number of seconds from 1 to 3600. Nothing ran.");
90214
90259
  target = await previewToolTarget(opts);
90215
- const queued = await previewToolClient(target.credential).call("POST", "/preview-tools/run-job", { handler: handlerPath, ...payload !== void 0 ? { payload } : {} });
90260
+ const client = previewToolClient(target.credential);
90261
+ let firstDelayMs = 0;
90262
+ const queued = await client.call("POST", "/preview-tools/run-job", { handler: handlerPath, ...payload !== void 0 ? { payload } : {} }, void 0, { onRetryAfter: /* @__PURE__ */ __name((ms2) => {
90263
+ firstDelayMs = ms2;
90264
+ }, "onRetryAfter") });
90216
90265
  if (opts.wait === false) {
90217
90266
  if (opts.json) {
90218
90267
  printJson(queued);
@@ -90224,7 +90273,7 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
90224
90273
  }
90225
90274
  if (!opts.json)
90226
90275
  console.log(dim(`Job ${queued.job_id} queued in preview ${queued.preview_session_id} (version ${queued.preview_id}); waiting up to ${timeout}s\u2026`));
90227
- const { job, timedOut } = await waitForPreviewJob(target.credential, queued.job_id, timeout);
90276
+ const { job, timedOut } = await waitForPreviewJob(client, queued.job_id, timeout, firstDelayMs);
90228
90277
  const succeeded = !timedOut && job.status === "complete";
90229
90278
  if (!succeeded)
90230
90279
  process.exitCode = 1;
@@ -133563,13 +133612,13 @@ function parseWaitTimeout(value) {
133563
133612
  function isTerminalJobStatus(status) {
133564
133613
  return status === JOB_SUCCESS_STATUS || JOB_FAILURE_STATUSES.has(status);
133565
133614
  }
133566
- async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
133567
- const client = new ApiClient(getToken());
133615
+ async function waitForJob(client, admitted, timeoutSeconds, firstDelayMs) {
133568
133616
  const path3 = "/jobs/" + encodeURIComponent(admitted.job_id);
133569
- const deadline = Date.now() + timeoutSeconds * 1e3;
133617
+ const startedAt = Date.now();
133618
+ const deadline = startedAt + timeoutSeconds * 1e3;
133570
133619
  let job = admitted;
133571
133620
  let delay2 = firstDelayMs;
133572
- for (let attempt = 0; ; attempt++) {
133621
+ for (; ; ) {
133573
133622
  const remaining = deadline - Date.now();
133574
133623
  if (delay2 >= remaining) {
133575
133624
  if (remaining > 0)
@@ -133594,7 +133643,7 @@ async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
133594
133643
  throw error3;
133595
133644
  retryAfter = Math.max(retryAfter ?? 0, hint ?? 0);
133596
133645
  }
133597
- delay2 = Math.max(interactivePollDelay(attempt), retryAfter ?? 0);
133646
+ delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter ?? 0);
133598
133647
  }
133599
133648
  }
133600
133649
  function observedCronConfig(cron) {
@@ -133761,11 +133810,7 @@ function printTypedCronError(code, message3, json, extra) {
133761
133810
  function cronProjectScope(explicit) {
133762
133811
  return explicit ?? loadProjectConfig()?.project_id;
133763
133812
  }
133764
- async function findNamedCronRow(target, explicit, signal) {
133765
- const project = cronProjectScope(explicit);
133766
- const rows = cronRows(await callPlatformTool("cron_list", compactRecord([
133767
- ["project_id", project]
133768
- ]), { allTools: true, signal }));
133813
+ function matchNamedCron(target, project, rows) {
133769
133814
  const matches = rows.filter((row) => row.name === target);
133770
133815
  if (matches.length === 0) {
133771
133816
  throw new Error(`CRON_NOT_FOUND: No scheduled task named "${target}" was found${project ? ` in project "${project}"` : ""}.`);
@@ -133778,6 +133823,20 @@ async function findNamedCronRow(target, explicit, signal) {
133778
133823
  throw new Error("cron_list returned a scheduled task without a cron_id.");
133779
133824
  return { ...matches[0], cron_id: id };
133780
133825
  }
133826
+ async function findNamedCronRow(target, explicit, signal) {
133827
+ const project = cronProjectScope(explicit);
133828
+ const rows = cronRows(await callPlatformTool("cron_list", compactRecord([
133829
+ ["project_id", project]
133830
+ ]), { allTools: true, signal }));
133831
+ return matchNamedCron(target, project, rows);
133832
+ }
133833
+ async function resolveRunCronId(client, target, explicit) {
133834
+ if (target.startsWith("cron_"))
133835
+ return target;
133836
+ const project = cronProjectScope(explicit);
133837
+ const rows = cronRows(await client.call("GET", "/cron", void 0, { project_id: project }));
133838
+ return matchNamedCron(target, project, rows).cron_id;
133839
+ }
133781
133840
  async function resolveCronId(target, explicit) {
133782
133841
  if (target.startsWith("cron_"))
133783
133842
  return target;
@@ -133844,20 +133903,18 @@ function printCronMutation(verb, value) {
133844
133903
  const id = isRecord(data2) && typeof data2.id === "string" ? data2.id : isRecord(data2) && typeof data2.cron_id === "string" ? data2.cron_id : null;
133845
133904
  success(`${verb}${id ? ` ${id}` : ""}.`);
133846
133905
  }
133847
- async function runCronInPreview(cronId, opts, timeoutSeconds) {
133906
+ async function runCronInPreview(client, cronId, opts, timeoutSeconds) {
133848
133907
  const tool = await folderPreviewTool({});
133849
133908
  const version2 = await previewCurrentVersion(tool.credential);
133850
133909
  let firstDelayMs = 0;
133851
- const value = await callPlatformTool("cron_run", { cron_id: cronId, preview_session_id: version2.preview_session_id, preview_id: version2.preview_id }, {
133852
- allTools: true,
133910
+ const result = cronRunResult(await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run-preview`, version2, void 0, {
133853
133911
  onRetryAfter: /* @__PURE__ */ __name((ms2) => {
133854
- firstDelayMs = Math.max(firstDelayMs, ms2);
133912
+ firstDelayMs = ms2;
133855
133913
  }, "onRetryAfter")
133856
- });
133857
- const result = cronRunResult(value);
133914
+ }));
133858
133915
  if (!opts.wait) {
133859
133916
  if (opts.json) {
133860
- printJson(value);
133917
+ printJson({ ok: true, data: result });
133861
133918
  return;
133862
133919
  }
133863
133920
  success(`Scheduled task queued in preview ${version2.preview_session_id} (not finished yet). Job ${result.job_id}.`);
@@ -133866,7 +133923,7 @@ async function runCronInPreview(cronId, opts, timeoutSeconds) {
133866
133923
  }
133867
133924
  if (!opts.json)
133868
133925
  console.log(dim(`Job ${result.job_id} queued in preview ${version2.preview_session_id} for cron ${result.cron_id}; waiting up to ${timeoutSeconds}s\u2026`));
133869
- const { job, timedOut } = await waitForPreviewJob(tool.credential, result.job_id, timeoutSeconds, firstDelayMs);
133926
+ const { job, timedOut } = await waitForPreviewJob(previewToolClient(tool.credential), result.job_id, timeoutSeconds, firstDelayMs);
133870
133927
  const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
133871
133928
  if (!succeeded)
133872
133929
  process.exitCode = 1;
@@ -133941,38 +133998,37 @@ zone each trigger is stored in, and \`cron update --schedule\` keeps that zone u
133941
133998
  if (opts.timeout !== void 0 && !opts.wait) {
133942
133999
  throw new Error("USAGE_ERROR: --timeout only applies with --wait.");
133943
134000
  }
133944
- const cronId = await resolveCronId(target, opts.project);
134001
+ const client = new ApiClient(getToken());
134002
+ const cronId = await resolveRunCronId(client, target, opts.project);
133945
134003
  if (opts.preview) {
133946
134004
  if (opts.twice) {
133947
134005
  await printPreviewScheduleTest(cronId, await folderPreviewTool({}), true, Boolean(opts.json));
133948
134006
  return;
133949
134007
  }
133950
- await runCronInPreview(cronId, opts, timeoutSeconds);
134008
+ await runCronInPreview(client, cronId, opts, timeoutSeconds);
133951
134009
  return;
133952
134010
  }
133953
134011
  let firstDelayMs = 0;
133954
- const value = await callPlatformTool("cron_run", { cron_id: cronId }, {
133955
- allTools: true,
134012
+ const value = await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run`, void 0, void 0, {
133956
134013
  onRetryAfter: /* @__PURE__ */ __name((ms2) => {
133957
- firstDelayMs = Math.max(firstDelayMs, ms2);
134014
+ firstDelayMs = ms2;
133958
134015
  }, "onRetryAfter")
133959
134016
  });
133960
134017
  queued = true;
134018
+ const result = cronRunResult(value);
133961
134019
  if (!opts.wait) {
133962
134020
  if (opts.json) {
133963
- printJson(value);
134021
+ printJson({ ok: true, data: result });
133964
134022
  return;
133965
134023
  }
133966
- const result2 = cronRunResult(value);
133967
- success(`Scheduled task queued (not finished yet). Job ${result2.job_id}.`);
133968
- console.log(dim(`Cron ${result2.cron_id} Job ${result2.job_id} ${result2.status} trigger: ${result2.trigger}`));
134024
+ success(`Scheduled task queued (not finished yet). Job ${result.job_id}.`);
134025
+ console.log(dim(`Cron ${result.cron_id} Job ${result.job_id} ${result.status} trigger: ${result.trigger}`));
133969
134026
  console.log(dim("Pass --wait to wait for the run to finish and see its result."));
133970
134027
  return;
133971
134028
  }
133972
- const result = cronRunResult(value);
133973
134029
  if (!opts.json)
133974
134030
  console.log(dim(`Job ${result.job_id} queued for cron ${result.cron_id}; waiting up to ${timeoutSeconds}s\u2026`));
133975
- const { job, timedOut } = await waitForJob(result, timeoutSeconds, firstDelayMs);
134031
+ const { job, timedOut } = await waitForJob(client, result, timeoutSeconds, firstDelayMs);
133976
134032
  const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
133977
134033
  if (!succeeded)
133978
134034
  process.exitCode = 1;
@@ -134115,6 +134171,7 @@ var init_cron = __esm({
134115
134171
  init_next_actions();
134116
134172
  init_platform_tools();
134117
134173
  init_poll_delay();
134174
+ init_preview_credential();
134118
134175
  init_preview_jobs();
134119
134176
  init_platform_command();
134120
134177
  init_output();
@@ -134142,7 +134199,9 @@ var init_cron = __esm({
134142
134199
  __name(cronRunUnavailable, "cronRunUnavailable");
134143
134200
  __name(printTypedCronError, "printTypedCronError");
134144
134201
  __name(cronProjectScope, "cronProjectScope");
134202
+ __name(matchNamedCron, "matchNamedCron");
134145
134203
  __name(findNamedCronRow, "findNamedCronRow");
134204
+ __name(resolveRunCronId, "resolveRunCronId");
134146
134205
  __name(resolveCronId, "resolveCronId");
134147
134206
  __name(findCronRow, "findCronRow");
134148
134207
  __name(nextRunLabel, "nextRunLabel");