@diafunc/cli 0.23.0 → 0.24.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.
@@ -4,13 +4,13 @@ import {
4
4
  PromptCancelled,
5
5
  createProgram,
6
6
  handleError
7
- } from "../chunk-DXZN6YJJ.js";
7
+ } from "../chunk-2YKNPNBM.js";
8
8
  import {
9
9
  getUpdateNotice
10
- } from "../chunk-CBQ5OGX3.js";
10
+ } from "../chunk-FX557IX3.js";
11
11
  import {
12
12
  package_default
13
- } from "../chunk-KND3I4AN.js";
13
+ } from "../chunk-A6PH2CFB.js";
14
14
 
15
15
  // bin/diafunc.ts
16
16
  import chalk2 from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-KND3I4AN.js";
3
+ } from "./chunk-A6PH2CFB.js";
4
4
 
5
5
  // src/index.ts
6
6
  import chalk37 from "chalk";
@@ -1684,6 +1684,18 @@ function createAnalysisService(client) {
1684
1684
  rawBody: formData
1685
1685
  });
1686
1686
  },
1687
+ /**
1688
+ * Makes a data source one of the files the analysis's data is built from: the platform fetches once and
1689
+ * stores the file as a source. The data is not built here; see `planSources` and `buildSources`.
1690
+ */
1691
+ async attachDataSource(analysisId, body) {
1692
+ return client.request({
1693
+ method: "POST",
1694
+ service: SERVICE2,
1695
+ path: `/${encodeURIComponent(analysisId)}/sources/data-source`,
1696
+ body
1697
+ });
1698
+ },
1687
1699
  async listSources(analysisId) {
1688
1700
  return client.request({
1689
1701
  method: "GET",
@@ -6315,7 +6327,7 @@ var HELP = [
6315
6327
  ];
6316
6328
  async function runChatRepl(options) {
6317
6329
  const { input: promptInput } = await import("@inquirer/prompts");
6318
- const { getUpdateNotice } = await import("./update-check-PBX3DE56.js");
6330
+ const { getUpdateNotice } = await import("./update-check-YTIEPB54.js");
6319
6331
  let sessionId = options.session;
6320
6332
  let lastReportedSession;
6321
6333
  console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
@@ -9023,28 +9035,55 @@ async function deletePreset(presetId) {
9023
9035
  await api.analysis.deletePreset(presetId);
9024
9036
  success(`Deleted preset ${presetId}.`);
9025
9037
  }
9026
- async function listTriggers(analysisId, cmd) {
9027
- const outputFormat = getOutputFormat15(cmd);
9028
- const api = createApiClient();
9029
- const triggers = await api.analysis.listTriggers(analysisId);
9030
- format(triggers.map((t) => ({
9038
+ function triggerRow(t) {
9039
+ return {
9031
9040
  triggerId: t.triggerId,
9032
9041
  kind: t.kind,
9033
9042
  schedule: t.scheduleSpec,
9034
9043
  active: t.active,
9035
- nextFireAt: t.nextFireAt
9036
- })), {
9044
+ refreshFirst: t.refreshFirst === true,
9045
+ nextFireAt: t.nextFireAt,
9046
+ lastOutcome: t.lastOutcome ?? ""
9047
+ };
9048
+ }
9049
+ function triggerChanges(options) {
9050
+ const flag = (name, value) => {
9051
+ if (value === void 0) return void 0;
9052
+ const lc = value.toLowerCase();
9053
+ if (lc !== "true" && lc !== "false") {
9054
+ throw new CliError(`Invalid --${name} value "${value}". Use true or false.`);
9055
+ }
9056
+ return lc === "true";
9057
+ };
9058
+ const active = flag("active", options.active);
9059
+ const refreshFirst = flag("refresh-first", options.refreshFirst);
9060
+ if (active === void 0 && !options.schedule && refreshFirst === void 0) {
9061
+ throw new CliError("Pass at least one of --active, --schedule or --refresh-first.");
9062
+ }
9063
+ return {
9064
+ active: active ?? null,
9065
+ scheduleSpec: options.schedule ?? null,
9066
+ ...refreshFirst === void 0 ? {} : { refreshFirst }
9067
+ };
9068
+ }
9069
+ async function listTriggers(analysisId, cmd) {
9070
+ const outputFormat = getOutputFormat15(cmd);
9071
+ const api = createApiClient();
9072
+ const triggers = await api.analysis.listTriggers(analysisId);
9073
+ format(triggers.map(triggerRow), {
9037
9074
  format: outputFormat,
9038
9075
  columns: [
9039
9076
  { key: "triggerId", kind: "id" },
9040
9077
  "kind",
9041
9078
  "schedule",
9042
9079
  { key: "active", kind: "boolean" },
9043
- { key: "nextFireAt", header: "next fire", kind: "date" }
9080
+ { key: "refreshFirst", header: "refresh first", kind: "boolean" },
9081
+ { key: "nextFireAt", header: "next fire", kind: "date" },
9082
+ { key: "lastOutcome", header: "last outcome" }
9044
9083
  ]
9045
9084
  });
9046
9085
  }
9047
- async function createTrigger(analysisId, kind, schedule, cmd) {
9086
+ async function createTrigger(analysisId, kind, schedule, cmd, refreshFirst = false) {
9048
9087
  const outputFormat = getOutputFormat15(cmd);
9049
9088
  const upper = kind.toUpperCase();
9050
9089
  if (upper !== "ONCE" && upper !== "CRON") {
@@ -9054,7 +9093,8 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
9054
9093
  const api = createApiClient();
9055
9094
  const trigger = await api.analysis.createTrigger(analysisId, {
9056
9095
  kind: upper,
9057
- scheduleSpec: schedule
9096
+ scheduleSpec: schedule,
9097
+ ...refreshFirst ? { refreshFirst: true } : {}
9058
9098
  });
9059
9099
  format(trigger, { format: outputFormat });
9060
9100
  }
@@ -9065,24 +9105,9 @@ async function deleteTrigger(triggerId) {
9065
9105
  }
9066
9106
  async function updateTriggerCmd(triggerId, options, cmd) {
9067
9107
  const outputFormat = getOutputFormat15(cmd);
9068
- let activeFlag;
9069
- if (options.active !== void 0) {
9070
- const lc = options.active.toLowerCase();
9071
- if (lc !== "true" && lc !== "false") {
9072
- failure(`Invalid --active value "${options.active}". Use true or false.`);
9073
- process.exit(EXIT_FAILURE);
9074
- }
9075
- activeFlag = lc === "true";
9076
- }
9077
- if (activeFlag === void 0 && !options.schedule) {
9078
- failure("Pass at least one of --active or --schedule.");
9079
- process.exit(EXIT_FAILURE);
9080
- }
9108
+ const changes = triggerChanges(options);
9081
9109
  const api = createApiClient();
9082
- const trigger = await api.analysis.updateTrigger(triggerId, {
9083
- active: activeFlag ?? null,
9084
- scheduleSpec: options.schedule ?? null
9085
- });
9110
+ const trigger = await api.analysis.updateTrigger(triggerId, changes);
9086
9111
  format(trigger, { format: outputFormat });
9087
9112
  }
9088
9113
  var COLUMN_LIST_HELP = "one argument each or comma-separated; a name that contains a comma is an argument of its own, or goes in double quotes inside a list";
@@ -9370,9 +9395,9 @@ function registerAnalyzeCommand(program) {
9370
9395
  handleError(error);
9371
9396
  }
9372
9397
  });
9373
- triggers.command("create").description("Create a trigger (ONCE: ISO-8601 timestamp; CRON: cron expression)").argument("<analysisId>", "Analysis ID").requiredOption("--kind <kind>", "ONCE or CRON").requiredOption("--schedule <spec>", "ISO-8601 timestamp (ONCE) or cron expression (CRON)").action(async (analysisId, options, cmd) => {
9398
+ triggers.command("create").description("Create a trigger (ONCE: ISO-8601 timestamp; CRON: cron expression)").argument("<analysisId>", "Analysis ID").requiredOption("--kind <kind>", "ONCE or CRON").requiredOption("--schedule <spec>", "ISO-8601 timestamp (ONCE) or cron expression (CRON)").option("--refresh-first", "Fetch the data sources that feed the analysis and build its data again before every run this trigger starts. A fetch that fails, or data that no longer fits, starts no run; `triggers list` says why").action(async (analysisId, options, cmd) => {
9374
9399
  try {
9375
- await createTrigger(analysisId, options.kind, options.schedule, cmd);
9400
+ await createTrigger(analysisId, options.kind, options.schedule, cmd, options.refreshFirst === true);
9376
9401
  } catch (error) {
9377
9402
  handleError(error);
9378
9403
  }
@@ -9385,7 +9410,7 @@ function registerAnalyzeCommand(program) {
9385
9410
  handleError(error);
9386
9411
  }
9387
9412
  });
9388
- triggers.command("update").description("Update a trigger: pause or resume it (--active), reschedule it (--schedule), or both").argument("<triggerId>", "Trigger ID").option("--active <bool>", "true to resume, false to pause").option("--schedule <spec>", "New schedule spec (ISO-8601 instant for ONCE, Quartz cron for CRON)").action(async (triggerId, options, cmd) => {
9413
+ triggers.command("update").description("Update a trigger: pause or resume it (--active), reschedule it (--schedule), switch refreshing the data first on or off (--refresh-first), or several at once").argument("<triggerId>", "Trigger ID").option("--active <bool>", "true to resume, false to pause").option("--schedule <spec>", "New schedule spec (ISO-8601 instant for ONCE, Quartz cron for CRON)").option("--refresh-first <bool>", "true to fetch the analysis's data sources before each run, false to run on the data as it is").action(async (triggerId, options, cmd) => {
9389
9414
  try {
9390
9415
  await updateTriggerCmd(triggerId, options, cmd);
9391
9416
  } catch (error) {
@@ -9588,7 +9613,7 @@ function dataSourceTableRow(ds) {
9588
9613
  id: ds.id,
9589
9614
  name: ds.name,
9590
9615
  type: ds.type,
9591
- target: `${ds.targetEntityId}@${ds.targetEntityBranch}`,
9616
+ target: ds.analysisId ? `analysis ${ds.analysisId}` : `${ds.targetEntityId}@${ds.targetEntityBranch}`,
9592
9617
  schedule: ds.scheduleCron ?? "manual",
9593
9618
  lastStatus: ds.lastRunStatus ?? "\u2014",
9594
9619
  lastRefreshAt: ds.lastRefreshAt ?? "\u2014"
@@ -9718,9 +9743,62 @@ async function showDashboard(projectId, cmd) {
9718
9743
  ]
9719
9744
  });
9720
9745
  }
9746
+ var TABLE_TARGET_FLAGS = [
9747
+ ["projectId", "--project-id"],
9748
+ ["projectBranch", "--project-branch"],
9749
+ ["targetEntityId", "--target-entity-id"],
9750
+ ["targetEntityBranch", "--target-entity-branch"]
9751
+ ];
9752
+ function createTarget(options) {
9753
+ const given = TABLE_TARGET_FLAGS.filter(([key]) => options[key] !== void 0).map(([, flag]) => flag);
9754
+ if (options.analysis !== void 0) {
9755
+ if (given.length > 0) {
9756
+ throw new CliError(
9757
+ `--analysis cannot be combined with ${given.join(", ")}.`,
9758
+ { exitCode: EXIT_USAGE, hint: "A data source feeds an analysis or overwrites a table, not both." }
9759
+ );
9760
+ }
9761
+ return "analysis";
9762
+ }
9763
+ const missing = TABLE_TARGET_FLAGS.filter(([key]) => options[key] === void 0).map(([, flag]) => flag);
9764
+ if (missing.length > 0) {
9765
+ throw new CliError(
9766
+ `Say what the data source refreshes: --analysis <analysisId>, or a table with ${missing.join(", ")}.`,
9767
+ { exitCode: EXIT_USAGE }
9768
+ );
9769
+ }
9770
+ return "table";
9771
+ }
9772
+ async function createForAnalysis(api, options, human) {
9773
+ const analysisId = options.analysis;
9774
+ const source = await api.analysis.attachDataSource(analysisId, {
9775
+ name: options.name,
9776
+ type: options.type,
9777
+ config: parseConfigPairs(options.config),
9778
+ scheduleCron: options.scheduleCron ?? null
9779
+ });
9780
+ const plan = await api.analysis.planSources(analysisId, null);
9781
+ const build = await api.analysis.buildSources(analysisId, plan.recipe);
9782
+ if (human) {
9783
+ success(`Added ${source.fileName} to analysis ${analysisId} from data source ${source.dataSourceId ?? ""}`.trimEnd());
9784
+ for (const line of planLines(build.plan)) {
9785
+ console.log(line.caution ? chalk27.yellow(` ${line.text}`) : chalk27.dim(` ${line.text}`));
9786
+ }
9787
+ console.log(chalk27.dim(options.scheduleCron ? ` Refreshes ${humanizeCron(options.scheduleCron)}; each refresh replaces the file and builds the data again.` : " No schedule of its own: refresh it with `data-sources refresh`, or let a trigger fetch it before a run (`analyze triggers create --refresh-first`)."));
9788
+ }
9789
+ return { source, build };
9790
+ }
9721
9791
  async function createDataSource(options, cmd) {
9722
9792
  const outputFormat = getOutputFormat17(cmd);
9793
+ const target = createTarget(options);
9723
9794
  const api = createApiClient();
9795
+ if (target === "analysis") {
9796
+ const created = await createForAnalysis(api, options, outputFormat === "human");
9797
+ if (outputFormat !== "human") {
9798
+ format(created, { format: outputFormat });
9799
+ }
9800
+ return;
9801
+ }
9724
9802
  const request = {
9725
9803
  projectId: options.projectId,
9726
9804
  projectBranch: options.projectBranch,
@@ -9855,7 +9933,7 @@ Examples:
9855
9933
  handleError(error);
9856
9934
  }
9857
9935
  });
9858
- dataSources.command("create").description("Create a data source (runs the initial fetch synchronously)").requiredOption("--project-id <id>", "Project ID").requiredOption("--project-branch <branch>", 'Project branch (usually "main")').requiredOption("--target-entity-id <id>", "Target table entity ID").requiredOption("--target-entity-branch <branch>", "Target table entity branch").requiredOption("--name <name>", "Display name").requiredOption("--type <type>", "Connector type (google_sheets, s3_url, jdbc)").option("--config <key=value>", "Connector config field; repeat for multiple", (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", 'Quartz cron expression (e.g. "0 0 2 * * ?" for daily 02:00 UTC); omit for manual-only').action(async (options, cmd) => {
9936
+ dataSources.command("create").description("Create a data source (runs the initial fetch synchronously). With --analysis the fetched file becomes one of the files that analysis is built from, and every refresh builds its data again; otherwise the data source overwrites a table").option("--analysis <analysisId>", "The analysis to feed: the file is stacked, matched by a key or reshaped like an uploaded one. Replaces the four table flags").option("--project-id <id>", "Project ID (for a table)").option("--project-branch <branch>", 'Project branch, usually "main" (for a table)').option("--target-entity-id <id>", "Target table entity ID (for a table)").option("--target-entity-branch <branch>", "Target table entity branch (for a table)").requiredOption("--name <name>", "Display name").requiredOption("--type <type>", "Connector type (google_sheets, s3_url, jdbc)").option("--config <key=value>", "Connector config field; repeat for multiple", (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", 'Quartz cron expression (e.g. "0 0 2 * * ?" for daily 02:00 UTC); omit for manual-only').action(async (options, cmd) => {
9859
9937
  try {
9860
9938
  await createDataSource(options, cmd);
9861
9939
  } catch (error) {
@@ -10808,7 +10886,7 @@ function registerShellCommand(program) {
10808
10886
  });
10809
10887
  const api = createApiClient();
10810
10888
  const { input: promptInput } = await import("@inquirer/prompts");
10811
- const { getUpdateNotice } = await import("./update-check-PBX3DE56.js");
10889
+ const { getUpdateNotice } = await import("./update-check-YTIEPB54.js");
10812
10890
  const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
10813
10891
  console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
10814
10892
  console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
@@ -11858,4 +11936,4 @@ export {
11858
11936
  PromptCancelled,
11859
11937
  createProgram
11860
11938
  };
11861
- //# sourceMappingURL=chunk-DXZN6YJJ.js.map
11939
+ //# sourceMappingURL=chunk-2YKNPNBM.js.map