@diafunc/cli 0.9.1 → 0.9.2

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.
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createProgram
4
- } from "../chunk-2WJQPO4V.js";
4
+ } from "../chunk-SOXLUOWV.js";
5
5
  import {
6
6
  getUpdateNotice
7
- } from "../chunk-67PBARIH.js";
7
+ } from "../chunk-CBSJB5GC.js";
8
8
  import {
9
9
  package_default
10
- } from "../chunk-VKUAIYZZ.js";
10
+ } from "../chunk-WPZBLPVY.js";
11
11
 
12
12
  // bin/diafunc.ts
13
13
  import chalk2 from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-VKUAIYZZ.js";
3
+ } from "./chunk-WPZBLPVY.js";
4
4
 
5
5
  // src/util/update-check.ts
6
6
  import * as fs from "fs";
@@ -72,4 +72,4 @@ async function getUpdateNotice() {
72
72
  export {
73
73
  getUpdateNotice
74
74
  };
75
- //# sourceMappingURL=chunk-67PBARIH.js.map
75
+ //# sourceMappingURL=chunk-CBSJB5GC.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-VKUAIYZZ.js";
3
+ } from "./chunk-WPZBLPVY.js";
4
4
 
5
5
  // src/index.ts
6
6
  import { Command } from "commander";
@@ -2681,6 +2681,22 @@ async function pollUntilFinished(storage, projectId, projectBranch, bundleId, in
2681
2681
  throw new Error(`Export ${bundleId} did not finish within the timeout \u2014 poll it with 'diafunc notebook bundles'`);
2682
2682
  }
2683
2683
 
2684
+ // src/util/function-language.ts
2685
+ var DEFAULT_FUNCTION_LANGUAGE = "Java";
2686
+ async function resolveLanguage(api, projectId, explicit) {
2687
+ if (explicit) {
2688
+ return explicit;
2689
+ }
2690
+ try {
2691
+ const project = await api.admin.getProject(projectId);
2692
+ if (project?.language) {
2693
+ return project.language;
2694
+ }
2695
+ } catch {
2696
+ }
2697
+ return DEFAULT_FUNCTION_LANGUAGE;
2698
+ }
2699
+
2684
2700
  // src/commands/project/index.ts
2685
2701
  function getOutputFormat(cmd) {
2686
2702
  const config = loadConfig();
@@ -2716,7 +2732,7 @@ function registerProjectCommands(program) {
2716
2732
  handleError(error);
2717
2733
  }
2718
2734
  });
2719
- project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "Project language", "Java").action(async (options, cmd) => {
2735
+ project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "The project's default language for functions (Java, Kotlin, Python, JavaScript, Scala)", DEFAULT_FUNCTION_LANGUAGE).action(async (options, cmd) => {
2720
2736
  try {
2721
2737
  const outputFormat = getOutputFormat(cmd);
2722
2738
  const api = createApiClient();
@@ -4338,8 +4354,12 @@ function encodeFunctionSource(sourceCode) {
4338
4354
  }
4339
4355
  function buildFunctionEntity(args) {
4340
4356
  const now = Date.now();
4341
- const attributes = { language: args.language };
4342
- const attributeTypes = { language: "text" };
4357
+ const attributes = {};
4358
+ const attributeTypes = {};
4359
+ if (args.language !== null && args.language !== void 0) {
4360
+ attributes.language = args.language;
4361
+ attributeTypes.language = "text";
4362
+ }
4343
4363
  if (args.name !== null && args.name !== void 0) {
4344
4364
  attributes.name = args.name;
4345
4365
  attributeTypes.name = "text";
@@ -4600,7 +4620,7 @@ function registerFunctionCommands(program) {
4600
4620
  handleError(error);
4601
4621
  }
4602
4622
  });
4603
- fn.command("create").description("Create a new function entity").argument("<ref>", "Function entity reference").option("--language <lang>", "Function language (Java, JavaScript, Kotlin, Python, Scala)", "Java").option("--source <file>", "Initial source code file").option("--name <name>", "Display name (defaults to entityId)").action(async (ref, options, cmd) => {
4623
+ fn.command("create").description("Create a new function entity").argument("<ref>", "Function entity reference").option("--language <lang>", "Function language (Java, Kotlin, Python, JavaScript, Scala); defaults to the project's language").option("--source <file>", "Initial source code file").option("--name <name>", "Display name (defaults to entityId)").action(async (ref, options, cmd) => {
4604
4624
  try {
4605
4625
  const overrides = getOverrides8(cmd);
4606
4626
  const resolved = parseEntityReference(ref, overrides);
@@ -4612,11 +4632,12 @@ function registerFunctionCommands(program) {
4612
4632
  entityId: resolved.entityId,
4613
4633
  entityBranch: resolved.entityBranch,
4614
4634
  name: options.name ?? resolved.entityId,
4615
- language: options.language,
4635
+ language: options.language ?? null,
4616
4636
  sourceCode
4617
4637
  });
4618
4638
  await api.storage.saveEntities([entity]);
4619
- console.log(chalk19.green(`Function "${resolved.entityId}" created (${options.language}).`));
4639
+ const effective = options.language ? options.language : `${await resolveLanguage(api, resolved.projectId)}, the project's language`;
4640
+ console.log(chalk19.green(`Function "${resolved.entityId}" created (${effective}).`));
4620
4641
  } catch (error) {
4621
4642
  handleError(error);
4622
4643
  }
@@ -4993,7 +5014,7 @@ Error: ${event.content}`));
4993
5014
  }
4994
5015
  async function runChatRepl(options) {
4995
5016
  const { input: promptInput } = await import("@inquirer/prompts");
4996
- const { getUpdateNotice } = await import("./update-check-L55QNPYQ.js");
5017
+ const { getUpdateNotice } = await import("./update-check-JKIWTPFB.js");
4997
5018
  let sessionId = options.session;
4998
5019
  console.log(chalk22.bold("Diafunc chat") + chalk22.dim(" \xB7 /help for commands, /quit to exit"));
4999
5020
  if (sessionId) {
@@ -7480,12 +7501,12 @@ async function evaluate(api, fnRef, language, sourceCode) {
7480
7501
  }
7481
7502
  }
7482
7503
  function registerShellCommand(program) {
7483
- program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language", "JavaScript").action(async (options, cmd) => {
7504
+ program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language; defaults to the project's language").action(async (options, cmd) => {
7484
7505
  try {
7485
7506
  if (!options.function) {
7486
7507
  console.error(chalk35.red("Missing --function <ref>."));
7487
7508
  console.error(chalk35.dim("Pass an existing or new function entity reference to use as the shell target."));
7488
- console.error(chalk35.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
7509
+ console.error(chalk35.dim("Example: diafunc shell --function my-project/main/scratch/main --language Kotlin"));
7489
7510
  process.exit(1);
7490
7511
  }
7491
7512
  const config = loadConfig();
@@ -7496,14 +7517,15 @@ function registerShellCommand(program) {
7496
7517
  });
7497
7518
  const api = createApiClient();
7498
7519
  const { input: promptInput } = await import("@inquirer/prompts");
7499
- const { getUpdateNotice } = await import("./update-check-L55QNPYQ.js");
7500
- console.log(chalk35.bold("Diafunc shell") + chalk35.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
7520
+ const { getUpdateNotice } = await import("./update-check-JKIWTPFB.js");
7521
+ const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
7522
+ console.log(chalk35.bold("Diafunc shell") + chalk35.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
7501
7523
  console.log(chalk35.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
7502
7524
  console.log(chalk35.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
7503
7525
  const notice = await getUpdateNotice();
7504
7526
  if (notice) console.log(chalk35.dim(notice));
7505
7527
  console.log();
7506
- let language = options.language;
7528
+ let language = resolvedLanguage;
7507
7529
  for (; ; ) {
7508
7530
  let line;
7509
7531
  try {
@@ -7757,4 +7779,4 @@ function createProgram() {
7757
7779
  export {
7758
7780
  createProgram
7759
7781
  };
7760
- //# sourceMappingURL=chunk-2WJQPO4V.js.map
7782
+ //# sourceMappingURL=chunk-SOXLUOWV.js.map