@openfn/cli 0.0.39 → 0.0.41

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.
@@ -0,0 +1,33 @@
1
+ // src/util/expand-adaptors.ts
2
+ var expand = (name) => {
3
+ if (typeof name === "string") {
4
+ const [left] = name.split("=");
5
+ if (left.match("/") || left.endsWith(".js")) {
6
+ return name;
7
+ }
8
+ return `@openfn/language-${name}`;
9
+ }
10
+ return name;
11
+ };
12
+ var expand_adaptors_default = (opts) => {
13
+ const { adaptors, workflow } = opts;
14
+ if (adaptors) {
15
+ opts.adaptors = adaptors?.map(expand);
16
+ }
17
+ if (workflow) {
18
+ Object.values(workflow.jobs).forEach((job) => {
19
+ if (job.adaptor) {
20
+ job.adaptor = expand(job.adaptor);
21
+ }
22
+ });
23
+ }
24
+ return opts;
25
+ };
26
+
27
+ // src/constants.ts
28
+ var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
29
+
30
+ export {
31
+ expand_adaptors_default,
32
+ DEFAULT_REPO_DIR
33
+ };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  DEFAULT_REPO_DIR,
4
4
  expand_adaptors_default
5
- } from "./chunk-LV5XDERP.js";
5
+ } from "./chunk-UBDWXKSG.js";
6
6
 
7
7
  // src/process/spawn.ts
8
8
  import path from "node:path";
@@ -34,77 +34,6 @@ function spawn_default(basePath, opts2) {
34
34
  import yargs from "yargs";
35
35
  import { hideBin } from "yargs/helpers";
36
36
 
37
- // src/repo/command.ts
38
- var repo = {
39
- command: "repo [subcommand]",
40
- desc: "Run commands on the module repo (install|clean)",
41
- builder: (yargs2) => yargs2.command(clean).command(install).command(pwd).command(list).example("repo install -a http", "Install @openfn/language-http").example("repo clean", "Remove everything from the repo working dir").example("repo pwd", "Print the current repo working dir")
42
- };
43
- var install = {
44
- command: "install [packages...]",
45
- desc: "install one or more packages to the runtime repo",
46
- handler: (argv) => {
47
- argv.command = "repo-install";
48
- },
49
- builder: (yargs2) => {
50
- return yargs2.option("adaptor", {
51
- alias: ["a"],
52
- description: "Install an adaptor by passing a shortened version of the name",
53
- boolean: true
54
- }).example("install axios", "Install the axios npm package to the repo").example(
55
- "install -a http",
56
- "Install @openfn/language-http adaptor to the repo"
57
- ).example(
58
- "install @openfn/language-http",
59
- "Install the language-http adaptor to the repo"
60
- );
61
- }
62
- };
63
- var clean = {
64
- command: "clean",
65
- desc: "Removes all modules from the runtime module repo",
66
- handler: (argv) => {
67
- argv.command = "repo-clean";
68
- },
69
- builder: (yargs2) => yargs2.option("force", {
70
- alias: ["f"],
71
- description: "Skip the prompt and force deletion",
72
- boolean: true
73
- })
74
- };
75
- var pwd = {
76
- command: "pwd",
77
- desc: "Print repo's current working directory",
78
- handler: (argv) => {
79
- argv.command = "repo-pwd";
80
- }
81
- };
82
- var list = {
83
- command: "list",
84
- desc: "Show a report on what is installed in the repo",
85
- handler: (argv) => {
86
- argv.command = "repo-list";
87
- }
88
- };
89
-
90
- // src/util/command-builders.ts
91
- var build = (opts2, yargs2) => opts2.reduce((_y, o) => yargs2.option(o.name, o.yargs), yargs2);
92
- var ensure = (command, opts2) => (yargs2) => {
93
- yargs2.command = command;
94
- opts2.filter((opt) => opt.ensure).forEach((opt) => {
95
- opt.ensure(yargs2);
96
- });
97
- };
98
- var override = (command, yargs2) => {
99
- return {
100
- ...command,
101
- yargs: {
102
- ...command.yargs || {},
103
- ...yargs2
104
- }
105
- };
106
- };
107
-
108
37
  // src/options.ts
109
38
  import path2 from "node:path";
110
39
  var setDefaultValue = (opts2, key, value) => {
@@ -259,10 +188,10 @@ var outputPath = {
259
188
  };
260
189
  var repoDir = {
261
190
  name: "repo-dir",
262
- yargs: {
191
+ yargs: () => ({
263
192
  description: "Provide a path to the repo root dir",
264
193
  default: process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR
265
- }
194
+ })
266
195
  };
267
196
  var start = {
268
197
  name: "start",
@@ -286,11 +215,11 @@ var strictOutput = {
286
215
  }
287
216
  };
288
217
  var strict = {
289
- name: "no-strict",
218
+ name: "strict",
290
219
  yargs: {
291
220
  default: false,
292
221
  boolean: true,
293
- description: "Strict state handling, meaning only state.data is returned from a job."
222
+ description: "Enables strict state handling, meaning only state.data is returned from a job."
294
223
  },
295
224
  ensure: (opts2) => {
296
225
  if (!opts2.hasOwnProperty("strictOutput")) {
@@ -343,6 +272,85 @@ var useAdaptorsMonorepo = {
343
272
  }
344
273
  };
345
274
 
275
+ // src/util/command-builders.ts
276
+ var expandYargs = (y2) => {
277
+ if (typeof y2 === "function") {
278
+ return y2();
279
+ }
280
+ return y2;
281
+ };
282
+ var build = (opts2, yargs2) => opts2.reduce((_y, o) => yargs2.option(o.name, expandYargs(o.yargs)), yargs2);
283
+ var ensure = (command, opts2) => (yargs2) => {
284
+ yargs2.command = command;
285
+ opts2.filter((opt) => opt.ensure).forEach((opt) => {
286
+ opt.ensure(yargs2);
287
+ });
288
+ };
289
+ var override = (command, yargs2) => {
290
+ return {
291
+ ...command,
292
+ yargs: {
293
+ ...command.yargs || {},
294
+ ...yargs2
295
+ }
296
+ };
297
+ };
298
+
299
+ // src/repo/command.ts
300
+ var repo = {
301
+ command: "repo [subcommand]",
302
+ desc: "Run commands on the module repo (install|clean)",
303
+ builder: (yargs2) => yargs2.command(clean).command(install).command(list).example("repo install -a http", "Install @openfn/language-http").example("repo clean", "Remove everything from the repo working dir")
304
+ };
305
+ var installOptions = [
306
+ repoDir,
307
+ override(expandAdaptors, {
308
+ default: true,
309
+ hidden: true
310
+ }),
311
+ override(adaptors, {
312
+ description: "Specify which language-adaptor to install (allows short-form names to be used, eg, http)"
313
+ })
314
+ ];
315
+ var install = {
316
+ command: "install [packages...]",
317
+ desc: "install one or more packages to the runtime repo. Use -a to pass shorthand adaptor names.",
318
+ handler: ensure("repo-install", installOptions),
319
+ builder: (yargs2) => build(installOptions, yargs2).example("install axios", "Install the axios npm package to the repo").example(
320
+ "install -a http",
321
+ "Install @openfn/language-http adaptor to the repo"
322
+ ).example(
323
+ "install @openfn/language-http",
324
+ "Install the language-http adaptor to the repo"
325
+ )
326
+ };
327
+ var clean = {
328
+ command: "clean",
329
+ desc: "Removes all modules from the runtime module repo",
330
+ handler: ensure("repo-clean", [repoDir]),
331
+ builder: (yargs2) => build(
332
+ [
333
+ repoDir,
334
+ {
335
+ name: "force",
336
+ yargs: {
337
+ alias: ["f"],
338
+ description: "Skip the prompt and force deletion",
339
+ boolean: true
340
+ }
341
+ }
342
+ ],
343
+ yargs2
344
+ )
345
+ };
346
+ var list = {
347
+ command: "list",
348
+ desc: "Show a report on what is installed in the repo",
349
+ aliases: ["$0"],
350
+ handler: ensure("repo-list", [repoDir]),
351
+ builder: (yargs2) => build([repoDir], yargs2)
352
+ };
353
+
346
354
  // src/execute/command.ts
347
355
  var options = [
348
356
  expandAdaptors,
@@ -383,8 +391,8 @@ Remember to include the adaptor name with -a. Auto install adaptors with the -i
383
391
  "openfn foo/job.js",
384
392
  "Execute foo/job.js with no adaptor and write the final state to foo/job.json"
385
393
  ).example(
386
- "openfn workflow.json -ia common",
387
- "Execute workflow.json using @openfn/language-commom (with autoinstall enabled)"
394
+ "openfn workflow.json -i",
395
+ "Execute workflow.json with autoinstall enabled"
388
396
  ).example(
389
397
  "openfn job.js -a common --log info",
390
398
  "Execute job.js with common adaptor and info-level logging"
@@ -1,20 +1,40 @@
1
1
  import {
2
- CLI,
3
- COMPILER,
4
- JOB,
5
- RUNTIME,
6
- createNullLogger,
7
- defaultLogger,
8
- ensureLogOpts,
9
- ensureOpts,
10
- expand_adaptors_default,
11
- logger_default,
12
- printDuration
13
- } from "../chunk-LV5XDERP.js";
2
+ DEFAULT_REPO_DIR,
3
+ expand_adaptors_default
4
+ } from "../chunk-UBDWXKSG.js";
14
5
 
15
6
  // src/execute/execute.ts
16
7
  import run, { getNameAndVersion } from "@openfn/runtime";
17
8
 
9
+ // src/util/logger.ts
10
+ import actualCreateLogger, { printDuration } from "@openfn/logger";
11
+ import { isValidLogLevel, defaultLogger } from "@openfn/logger";
12
+ var CLI = "cli";
13
+ var COMPILER = "compiler";
14
+ var RUNTIME = "runtime";
15
+ var JOB = "job";
16
+ var namespaces = {
17
+ [CLI]: "CLI",
18
+ [RUNTIME]: "R/T",
19
+ [COMPILER]: "CMP",
20
+ [JOB]: "JOB"
21
+ };
22
+ var createLogger = (name = "", options) => {
23
+ const logOptions = options.log || {};
24
+ let json = false;
25
+ let level = logOptions[name] || logOptions.default || "default";
26
+ if (options.logJson) {
27
+ json = true;
28
+ }
29
+ return actualCreateLogger(namespaces[name] || name, {
30
+ level,
31
+ json,
32
+ ...logOptions
33
+ });
34
+ };
35
+ var logger_default = createLogger;
36
+ var createNullLogger = () => createLogger(void 0, { log: { default: "none" } });
37
+
18
38
  // src/util/abort.ts
19
39
  var AbortError = class extends Error {
20
40
  constructor(reason) {
@@ -58,13 +78,13 @@ var execute_default = async (input, state, opts, logger) => {
58
78
  };
59
79
  function parseAdaptors(opts) {
60
80
  const extractInfo = (specifier) => {
61
- const [module, path6] = specifier.split("=");
81
+ const [module, path7] = specifier.split("=");
62
82
  const { name, version } = getNameAndVersion(module);
63
83
  const info = {
64
84
  name
65
85
  };
66
- if (path6) {
67
- info.path = path6;
86
+ if (path7) {
87
+ info.path = path7;
68
88
  }
69
89
  if (version) {
70
90
  info.version = version;
@@ -145,16 +165,13 @@ import { exec } from "node:child_process";
145
165
  import treeify from "treeify";
146
166
  import { install as rtInstall, loadRepoPkg } from "@openfn/runtime";
147
167
  var install = async (opts, log = defaultLogger) => {
148
- let { packages, adaptor, repoDir } = opts;
149
- if (packages) {
168
+ let { packages, adaptors, repoDir } = opts;
169
+ const targets = [].concat(packages ?? [], adaptors ?? []);
170
+ if (targets) {
150
171
  log.timer("install");
151
172
  log.success("Installing packages...");
152
173
  log.debug("repoDir is set to:", repoDir);
153
- if (adaptor) {
154
- const expanded = expand_adaptors_default({ adaptors: packages });
155
- packages = expanded.adaptors;
156
- }
157
- await rtInstall(packages ?? [], repoDir, log);
174
+ await rtInstall(targets, repoDir, log);
158
175
  const duration = log.timer("install");
159
176
  log.success(`Installation complete in ${duration}`);
160
177
  }
@@ -269,10 +286,10 @@ var stripVersionSpecifier = (specifier) => {
269
286
  return specifier;
270
287
  };
271
288
  var resolveSpecifierPath = async (pattern, repoDir, log) => {
272
- const [specifier, path6] = pattern.split("=");
273
- if (path6) {
274
- log.debug(`Resolved ${specifier} to path: ${path6}`);
275
- return path6;
289
+ const [specifier, path7] = pattern.split("=");
290
+ if (path7) {
291
+ log.debug(`Resolved ${specifier} to path: ${path7}`);
292
+ return path7;
276
293
  }
277
294
  const repoPath = await getModulePath(specifier, repoDir, log);
278
295
  if (repoPath) {
@@ -289,16 +306,16 @@ var loadTransformOptions = async (opts, log) => {
289
306
  const [pattern] = opts.adaptors;
290
307
  const [specifier] = pattern.split("=");
291
308
  log.debug(`Attempting to preload types for ${specifier}`);
292
- const path6 = await resolveSpecifierPath(pattern, opts.repoDir, log);
293
- if (path6) {
309
+ const path7 = await resolveSpecifierPath(pattern, opts.repoDir, log);
310
+ if (path7) {
294
311
  try {
295
312
  exports = await preloadAdaptorExports(
296
- path6,
313
+ path7,
297
314
  opts.useAdaptorsMonorepo,
298
315
  log
299
316
  );
300
317
  } catch (e) {
301
- log.error(`Failed to load adaptor typedefs from path ${path6}`);
318
+ log.error(`Failed to load adaptor typedefs from path ${path7}`);
302
319
  log.error(e);
303
320
  }
304
321
  }
@@ -494,6 +511,59 @@ Paths inside the workflow are relative to the workflow.json`
494
511
  }
495
512
  };
496
513
 
514
+ // src/util/map-adaptors-to-monorepo.ts
515
+ import { readFile } from "node:fs/promises";
516
+ import path2 from "node:path";
517
+ import assert from "node:assert";
518
+ import { getNameAndVersion as getNameAndVersion2 } from "@openfn/runtime";
519
+ var validateMonoRepo = async (repoPath, log) => {
520
+ try {
521
+ const raw = await readFile(`${repoPath}/package.json`, "utf8");
522
+ const pkg = JSON.parse(raw);
523
+ assert(pkg.name === "adaptors");
524
+ } catch (e) {
525
+ log.error(`ERROR: Adaptors Monorepo not found at ${repoPath}`);
526
+ process.exit(9);
527
+ }
528
+ };
529
+ var updatePath = (adaptor, repoPath, log) => {
530
+ if (adaptor.match("=")) {
531
+ return adaptor;
532
+ }
533
+ const { name, version } = getNameAndVersion2(adaptor);
534
+ if (version) {
535
+ log.warn(
536
+ `Warning: Ignoring version specifier on ${adaptor} as loading from the adaptors monorepo`
537
+ );
538
+ }
539
+ const shortName = name.replace("@openfn/language-", "");
540
+ const abspath = path2.resolve(repoPath, "packages", shortName);
541
+ return `${name}=${abspath}`;
542
+ };
543
+ var mapAdaptorsToMonorepo = async (options, log) => {
544
+ const { adaptors, monorepoPath, workflow } = options;
545
+ if (monorepoPath) {
546
+ await validateMonoRepo(monorepoPath, log);
547
+ log.success(`Loading adaptors from monorepo at ${monorepoPath}`);
548
+ if (adaptors) {
549
+ options.adaptors = adaptors.map((a) => {
550
+ const p = updatePath(a, monorepoPath, log);
551
+ log.info(`Mapped adaptor ${a} to monorepo: ${p.split("=")[1]}`);
552
+ return p;
553
+ });
554
+ }
555
+ if (workflow) {
556
+ Object.values(workflow.jobs).forEach((job) => {
557
+ if (job.adaptor) {
558
+ job.adaptor = updatePath(job.adaptor, monorepoPath, log);
559
+ }
560
+ });
561
+ }
562
+ }
563
+ return options;
564
+ };
565
+ var map_adaptors_to_monorepo_default = mapAdaptorsToMonorepo;
566
+
497
567
  // src/execute/handler.ts
498
568
  var executeHandler = async (options, logger) => {
499
569
  const start = new Date().getTime();
@@ -501,6 +571,10 @@ var executeHandler = async (options, logger) => {
501
571
  let input = await load_input_default(options, logger);
502
572
  if (options.workflow) {
503
573
  expand_adaptors_default(options);
574
+ await map_adaptors_to_monorepo_default(
575
+ options,
576
+ logger
577
+ );
504
578
  }
505
579
  const { repoDir, monorepoPath, autoinstall } = options;
506
580
  if (autoinstall) {
@@ -547,6 +621,13 @@ var handler_default = executeHandler;
547
621
  import { writeFile as writeFile2 } from "node:fs/promises";
548
622
  var compileHandler = async (options, logger) => {
549
623
  await load_input_default(options, logger);
624
+ if (options.workflow) {
625
+ expand_adaptors_default(options);
626
+ await map_adaptors_to_monorepo_default(
627
+ options,
628
+ logger
629
+ );
630
+ }
550
631
  let result = await compile_default(options, logger);
551
632
  if (options.workflow) {
552
633
  result = JSON.stringify(result);
@@ -612,28 +693,28 @@ var handler_default3 = testHandler;
612
693
  // src/docgen/handler.ts
613
694
  import { writeFile as writeFile3 } from "node:fs/promises";
614
695
  import { readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
615
- import path2 from "node:path";
696
+ import path3 from "node:path";
616
697
  import { describePackage } from "@openfn/describe-package";
617
- import { getNameAndVersion as getNameAndVersion2 } from "@openfn/runtime";
698
+ import { getNameAndVersion as getNameAndVersion3 } from "@openfn/runtime";
618
699
  var RETRY_DURATION = 500;
619
700
  var RETRY_COUNT = 20;
620
701
  var TIMEOUT_MS = 1e3 * 60;
621
702
  var actualDocGen = (specifier) => describePackage(specifier, {});
622
- var ensurePath = (filePath) => mkdirSync(path2.dirname(filePath), { recursive: true });
623
- var generatePlaceholder = (path6) => {
624
- writeFileSync(path6, `{ "loading": true, "timestamp": ${Date.now()}}`);
703
+ var ensurePath = (filePath) => mkdirSync(path3.dirname(filePath), { recursive: true });
704
+ var generatePlaceholder = (path7) => {
705
+ writeFileSync(path7, `{ "loading": true, "timestamp": ${Date.now()}}`);
625
706
  };
626
707
  var finish = (logger, resultPath) => {
627
708
  logger.success("Done! Docs can be found at:\n");
628
- logger.print(` ${path2.resolve(resultPath)}`);
709
+ logger.print(` ${path3.resolve(resultPath)}`);
629
710
  };
630
- var generateDocs = async (specifier, path6, docgen, logger) => {
711
+ var generateDocs = async (specifier, path7, docgen, logger) => {
631
712
  const result = await docgen(specifier);
632
- await writeFile3(path6, JSON.stringify(result, null, 2));
633
- finish(logger, path6);
634
- return path6;
713
+ await writeFile3(path7, JSON.stringify(result, null, 2));
714
+ finish(logger, path7);
715
+ return path7;
635
716
  };
636
- var waitForDocs = async (docs, path6, logger, retryDuration = RETRY_DURATION) => {
717
+ var waitForDocs = async (docs, path7, logger, retryDuration = RETRY_DURATION) => {
637
718
  try {
638
719
  if (docs.hasOwnProperty("loading")) {
639
720
  logger.info("Docs are being loaded by another process. Waiting.");
@@ -645,19 +726,19 @@ var waitForDocs = async (docs, path6, logger, retryDuration = RETRY_DURATION) =>
645
726
  clearInterval(i);
646
727
  reject(new Error("Timed out waiting for docs to load"));
647
728
  }
648
- const updated = JSON.parse(readFileSync(path6, "utf8"));
729
+ const updated = JSON.parse(readFileSync(path7, "utf8"));
649
730
  if (!updated.hasOwnProperty("loading")) {
650
731
  logger.info("Docs found!");
651
732
  clearInterval(i);
652
- resolve(path6);
733
+ resolve(path7);
653
734
  }
654
735
  count++;
655
736
  }, retryDuration);
656
737
  });
657
738
  } else {
658
- logger.info(`Docs already written to cache at ${path6}`);
659
- finish(logger, path6);
660
- return path6;
739
+ logger.info(`Docs already written to cache at ${path7}`);
740
+ finish(logger, path7);
741
+ return path7;
661
742
  }
662
743
  } catch (e) {
663
744
  logger.error("Existing doc JSON corrupt. Aborting");
@@ -666,7 +747,7 @@ var waitForDocs = async (docs, path6, logger, retryDuration = RETRY_DURATION) =>
666
747
  };
667
748
  var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RETRY_DURATION) => {
668
749
  const { specifier, repoDir } = options;
669
- const { version } = getNameAndVersion2(specifier);
750
+ const { version } = getNameAndVersion3(specifier);
670
751
  if (!version) {
671
752
  logger.error("Error: No version number detected");
672
753
  logger.error("eg, @openfn/language-common@1.7.5");
@@ -674,28 +755,28 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
674
755
  process.exit(9);
675
756
  }
676
757
  logger.success(`Generating docs for ${specifier}`);
677
- const path6 = `${repoDir}/docs/${specifier}.json`;
678
- ensurePath(path6);
758
+ const path7 = `${repoDir}/docs/${specifier}.json`;
759
+ ensurePath(path7);
679
760
  const handleError = () => {
680
761
  logger.info("Removing placeholder");
681
- rmSync(path6);
762
+ rmSync(path7);
682
763
  };
683
764
  try {
684
- const existing = readFileSync(path6, "utf8");
765
+ const existing = readFileSync(path7, "utf8");
685
766
  const json = JSON.parse(existing);
686
767
  if (json && json.timeout && Date.now() - json.timeout >= TIMEOUT_MS) {
687
768
  logger.info(`Expired placeholder found. Removing.`);
688
- rmSync(path6);
769
+ rmSync(path7);
689
770
  throw new Error("TIMEOUT");
690
771
  }
691
- return waitForDocs(json, path6, logger, retryDuration);
772
+ return waitForDocs(json, path7, logger, retryDuration);
692
773
  } catch (e) {
693
774
  if (e.message !== "TIMEOUT") {
694
- logger.info(`Docs JSON not found at ${path6}`);
775
+ logger.info(`Docs JSON not found at ${path7}`);
695
776
  }
696
777
  logger.debug("Generating placeholder");
697
- generatePlaceholder(path6);
698
- return generateDocs(specifier, path6, docgen, logger).catch((e2) => {
778
+ generatePlaceholder(path7);
779
+ return generateDocs(specifier, path7, docgen, logger).catch((e2) => {
699
780
  logger.error("Error generating documentation");
700
781
  logger.error(e2);
701
782
  handleError();
@@ -705,8 +786,8 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
705
786
  var handler_default4 = docgenHandler;
706
787
 
707
788
  // src/docs/handler.ts
708
- import { readFile } from "node:fs/promises";
709
- import { getNameAndVersion as getNameAndVersion3, getLatestVersion } from "@openfn/runtime";
789
+ import { readFile as readFile2 } from "node:fs/promises";
790
+ import { getNameAndVersion as getNameAndVersion4, getLatestVersion } from "@openfn/runtime";
710
791
  var describeFn = (adaptorName, fn) => `## ${fn.name}(${fn.parameters.map(({ name }) => name).join(",")})
711
792
 
712
793
  ${fn.description}
@@ -736,7 +817,7 @@ var docsHandler = async (options, logger) => {
736
817
  const { adaptor, operation, repoDir } = options;
737
818
  const { adaptors } = expand_adaptors_default({ adaptors: [adaptor] });
738
819
  const [adaptorName] = adaptors;
739
- let { name, version } = getNameAndVersion3(adaptorName);
820
+ let { name, version } = getNameAndVersion4(adaptorName);
740
821
  if (!version) {
741
822
  logger.info("No version number provided, looking for latest...");
742
823
  version = await getLatestVersion(name);
@@ -744,7 +825,7 @@ var docsHandler = async (options, logger) => {
744
825
  logger.success(`Showing docs for ${adaptorName} v${version}`);
745
826
  }
746
827
  logger.info("Generating/loading documentation...");
747
- const path6 = await handler_default4(
828
+ const path7 = await handler_default4(
748
829
  {
749
830
  specifier: `${name}@${version}`,
750
831
  repoDir
@@ -752,8 +833,8 @@ var docsHandler = async (options, logger) => {
752
833
  createNullLogger()
753
834
  );
754
835
  let didError = false;
755
- if (path6) {
756
- const source = await readFile(path6, "utf8");
836
+ if (path7) {
837
+ const source = await readFile2(path7, "utf8");
757
838
  const data = JSON.parse(source);
758
839
  let desc;
759
840
  if (operation) {
@@ -785,7 +866,7 @@ var handler_default5 = docsHandler;
785
866
  // src/metadata/cache.ts
786
867
  import { createHash } from "node:crypto";
787
868
  import { readFileSync as readFileSync2 } from "node:fs";
788
- import path3 from "node:path";
869
+ import path4 from "node:path";
789
870
  import { writeFile as writeFile4, mkdir } from "node:fs/promises";
790
871
  var getPath = (repoDir, key) => `${repoDir}/meta/${key}.json`;
791
872
  var sortKeys = (obj) => {
@@ -816,7 +897,7 @@ var get = (repoPath, key) => {
816
897
  };
817
898
  var set = async (repoPath, key, data) => {
818
899
  const fullPath = getPath(repoPath, key);
819
- await mkdir(path3.dirname(fullPath), { recursive: true });
900
+ await mkdir(path4.dirname(fullPath), { recursive: true });
820
901
  await writeFile4(fullPath, JSON.stringify(data));
821
902
  };
822
903
  var cache_default = { get, set, generateKey, getPath, sortKeys };
@@ -899,50 +980,104 @@ var metadataHandler = async (options, logger) => {
899
980
  };
900
981
  var handler_default6 = metadataHandler;
901
982
 
902
- // src/util/use-adaptors-repo.ts
903
- import { readFile as readFile2 } from "node:fs/promises";
904
- import path4 from "node:path";
905
- import assert from "node:assert";
906
- import { getNameAndVersion as getNameAndVersion5 } from "@openfn/runtime";
907
- var validateMonoRepo = async (repoPath, log) => {
908
- try {
909
- const raw = await readFile2(`${repoPath}/package.json`, "utf8");
910
- const pkg = JSON.parse(raw);
911
- assert(pkg.name === "adaptors");
912
- } catch (e) {
913
- log.error(`ERROR: Adaptors Monorepo not found at ${repoPath}`);
914
- process.exit(9);
983
+ // src/util/ensure-opts.ts
984
+ import path5 from "node:path";
985
+ var defaultLoggerOptions = {
986
+ default: "default",
987
+ job: "debug"
988
+ };
989
+ var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
990
+ var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
991
+ var componentShorthands = {
992
+ cmp: "compiler",
993
+ rt: "runtime",
994
+ "r/t": "runtime"
995
+ };
996
+ var isValidComponent = (v) => /^(cli|runtime|compiler|job|default)$/i.test(v);
997
+ var ensureLogOpts = (opts) => {
998
+ const components = {};
999
+ if (!opts.log && /^(version|test)$/.test(opts.command)) {
1000
+ opts.log = { default: "info" };
1001
+ return opts;
1002
+ } else if (opts.log) {
1003
+ opts.log.forEach((l) => {
1004
+ let component = "";
1005
+ let level = "";
1006
+ if (l.match(/=/)) {
1007
+ const parts = l.split("=");
1008
+ component = parts[0].toLowerCase();
1009
+ if (componentShorthands[component]) {
1010
+ component = componentShorthands[component];
1011
+ }
1012
+ level = parts[1].toLowerCase();
1013
+ } else {
1014
+ component = "default";
1015
+ level = l.toLowerCase();
1016
+ }
1017
+ if (!isValidComponent(component)) {
1018
+ throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
1019
+ }
1020
+ level = level.toLowerCase();
1021
+ if (!isValidLogLevel(level)) {
1022
+ throw new Error(ERROR_MESSAGE_LOG_LEVEL);
1023
+ }
1024
+ components[component] = level;
1025
+ });
915
1026
  }
1027
+ opts.log = {
1028
+ ...defaultLoggerOptions,
1029
+ ...components
1030
+ };
1031
+ return opts;
916
1032
  };
917
- var updatePath = (adaptor, repoPath, log) => {
918
- if (adaptor.match("=")) {
919
- return adaptor;
1033
+ function ensureOpts(basePath = ".", opts) {
1034
+ const newOpts = {
1035
+ adaptor: opts.adaptor,
1036
+ adaptors: opts.adaptors || [],
1037
+ autoinstall: opts.autoinstall,
1038
+ command: opts.command,
1039
+ expandAdaptors: opts.expandAdaptors !== false,
1040
+ force: opts.force || false,
1041
+ immutable: opts.immutable || false,
1042
+ log: opts.log,
1043
+ logJson: typeof opts.logJson == "boolean" ? opts.logJson : Boolean(process.env.OPENFN_LOG_JSON),
1044
+ compile: Boolean(opts.compile),
1045
+ operation: opts.operation,
1046
+ outputStdout: Boolean(opts.outputStdout),
1047
+ packages: opts.packages,
1048
+ repoDir: opts.repoDir || process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
1049
+ skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
1050
+ specifier: opts.specifier,
1051
+ stateStdin: opts.stateStdin,
1052
+ timeout: opts.timeout
1053
+ };
1054
+ const set2 = (key, value) => {
1055
+ newOpts[key] = opts.hasOwnProperty(key) ? opts[key] : value;
1056
+ };
1057
+ if (opts.useAdaptorsMonorepo) {
1058
+ newOpts.monorepoPath = process.env.OPENFN_ADAPTORS_REPO || "ERR";
920
1059
  }
921
- const { name, version } = getNameAndVersion5(adaptor);
922
- if (version) {
923
- log.warn(
924
- `Warning: Ignoring version specifier on ${adaptor} as loading from the adaptors monorepo`
1060
+ let baseDir = basePath;
1061
+ if (basePath.endsWith(".js")) {
1062
+ baseDir = path5.dirname(basePath);
1063
+ set2("jobPath", basePath);
1064
+ } else {
1065
+ set2("jobPath", `${baseDir}/job.js`);
1066
+ }
1067
+ set2("statePath", `${baseDir}/state.json`);
1068
+ if (!opts.outputStdout) {
1069
+ set2(
1070
+ "outputPath",
1071
+ newOpts.command === "compile" ? `${baseDir}/output.js` : `${baseDir}/output.json`
925
1072
  );
926
1073
  }
927
- const shortName = name.replace("@openfn/language-", "");
928
- const abspath = path4.resolve(repoPath, "packages", shortName);
929
- return `${name}=${abspath}`;
930
- };
931
- var useAdaptorsRepo = async (adaptors, repoPath, log) => {
932
- await validateMonoRepo(repoPath, log);
933
- log.success(`Loading adaptors from monorepo at ${repoPath}`);
934
- const updatedAdaptors = adaptors.map((a) => {
935
- const p = updatePath(a, repoPath, log);
936
- log.info(`Mapped adaptor ${a} to monorepo: ${p.split("=")[1]}`);
937
- return p;
938
- });
939
- return updatedAdaptors;
940
- };
941
- var use_adaptors_repo_default = useAdaptorsRepo;
1074
+ ensureLogOpts(newOpts);
1075
+ return newOpts;
1076
+ }
942
1077
 
943
1078
  // src/util/print-versions.ts
944
1079
  import { readFileSync as readFileSync3 } from "node:fs";
945
- import path5 from "node:path";
1080
+ import path6 from "node:path";
946
1081
  import { getNameAndVersion as getNameAndVersion6 } from "@openfn/runtime";
947
1082
  import { mainSymbols } from "figures";
948
1083
  var NODE = "node.js";
@@ -952,7 +1087,7 @@ var COMPILER2 = "compiler";
952
1087
  var { triangleRightSmall: t } = mainSymbols;
953
1088
  var loadVersionFromPath = (adaptorPath) => {
954
1089
  try {
955
- const pkg = JSON.parse(readFileSync3(path5.resolve(adaptorPath, "package.json"), "utf8"));
1090
+ const pkg = JSON.parse(readFileSync3(path6.resolve(adaptorPath, "package.json"), "utf8"));
956
1091
  return pkg.version;
957
1092
  } catch (e) {
958
1093
  return "unknown";
@@ -1029,7 +1164,7 @@ var handlers = {
1029
1164
  ["repo-list"]: list,
1030
1165
  version: async (opts, logger) => print_versions_default(logger, opts)
1031
1166
  };
1032
- var maybeEnsureOpts = (basePath, options) => /^(execute|compile|test)$/.test(options.command) ? ensureLogOpts(options) : ensureOpts(basePath, options);
1167
+ var maybeEnsureOpts = (basePath, options) => /(^(execute|compile|test)$)|(repo-)/.test(options.command) ? ensureLogOpts(options) : ensureOpts(basePath, options);
1033
1168
  var parse = async (basePath, options, log) => {
1034
1169
  const opts = maybeEnsureOpts(basePath, options);
1035
1170
  const logger = log || logger_default(CLI, opts);
@@ -1044,11 +1179,7 @@ var parse = async (basePath, options, log) => {
1044
1179
  logger.error("Set OPENFN_ADAPTORS_REPO to a path pointing to the repo");
1045
1180
  process.exit(9);
1046
1181
  }
1047
- opts.adaptors = await use_adaptors_repo_default(
1048
- opts.adaptors,
1049
- opts.monorepoPath,
1050
- logger
1051
- );
1182
+ await map_adaptors_to_monorepo_default(opts, logger);
1052
1183
  } else if (opts.adaptors && opts.expandAdaptors) {
1053
1184
  expand_adaptors_default(opts);
1054
1185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "description": "CLI devtools for the openfn toolchain.",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -39,7 +39,7 @@
39
39
  "@openfn/compiler": "0.0.32",
40
40
  "@openfn/describe-package": "0.0.16",
41
41
  "@openfn/logger": "0.0.13",
42
- "@openfn/runtime": "0.0.24",
42
+ "@openfn/runtime": "0.0.25",
43
43
  "figures": "^5.0.0",
44
44
  "rimraf": "^3.0.2",
45
45
  "treeify": "^1.1.0",
@@ -1,165 +0,0 @@
1
- // src/util/expand-adaptors.ts
2
- var expand = (name) => {
3
- if (typeof name === "string") {
4
- const [left] = name.split("=");
5
- if (left.match("/") || left.endsWith(".js")) {
6
- return name;
7
- }
8
- return `@openfn/language-${name}`;
9
- }
10
- return name;
11
- };
12
- var expand_adaptors_default = (opts) => {
13
- const { adaptors, workflow } = opts;
14
- if (adaptors) {
15
- opts.adaptors = adaptors?.map(expand);
16
- }
17
- if (workflow) {
18
- Object.values(workflow.jobs).forEach((job) => {
19
- if (job.adaptor) {
20
- job.adaptor = expand(job.adaptor);
21
- }
22
- });
23
- }
24
- return opts;
25
- };
26
-
27
- // src/util/logger.ts
28
- import actualCreateLogger, { printDuration } from "@openfn/logger";
29
- import { isValidLogLevel, defaultLogger } from "@openfn/logger";
30
- var CLI = "cli";
31
- var COMPILER = "compiler";
32
- var RUNTIME = "runtime";
33
- var JOB = "job";
34
- var namespaces = {
35
- [CLI]: "CLI",
36
- [RUNTIME]: "R/T",
37
- [COMPILER]: "CMP",
38
- [JOB]: "JOB"
39
- };
40
- var createLogger = (name = "", options) => {
41
- const logOptions = options.log || {};
42
- let json = false;
43
- let level = logOptions[name] || logOptions.default || "default";
44
- if (options.logJson) {
45
- json = true;
46
- }
47
- return actualCreateLogger(namespaces[name] || name, {
48
- level,
49
- json,
50
- ...logOptions
51
- });
52
- };
53
- var logger_default = createLogger;
54
- var createNullLogger = () => createLogger(void 0, { log: { default: "none" } });
55
-
56
- // src/util/ensure-opts.ts
57
- import path from "node:path";
58
- var defaultLoggerOptions = {
59
- default: "default",
60
- job: "debug"
61
- };
62
- var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
63
- var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
64
- var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
65
- var componentShorthands = {
66
- cmp: "compiler",
67
- rt: "runtime",
68
- "r/t": "runtime"
69
- };
70
- var isValidComponent = (v) => /^(cli|runtime|compiler|job|default)$/i.test(v);
71
- var ensureLogOpts = (opts) => {
72
- const components = {};
73
- if (!opts.log && /^(version|test)$/.test(opts.command)) {
74
- opts.log = { default: "info" };
75
- return opts;
76
- } else if (opts.log) {
77
- opts.log.forEach((l) => {
78
- let component = "";
79
- let level = "";
80
- if (l.match(/=/)) {
81
- const parts = l.split("=");
82
- component = parts[0].toLowerCase();
83
- if (componentShorthands[component]) {
84
- component = componentShorthands[component];
85
- }
86
- level = parts[1].toLowerCase();
87
- } else {
88
- component = "default";
89
- level = l.toLowerCase();
90
- }
91
- if (!isValidComponent(component)) {
92
- throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
93
- }
94
- level = level.toLowerCase();
95
- if (!isValidLogLevel(level)) {
96
- throw new Error(ERROR_MESSAGE_LOG_LEVEL);
97
- }
98
- components[component] = level;
99
- });
100
- }
101
- opts.log = {
102
- ...defaultLoggerOptions,
103
- ...components
104
- };
105
- return opts;
106
- };
107
- function ensureOpts(basePath = ".", opts) {
108
- const newOpts = {
109
- adaptor: opts.adaptor,
110
- adaptors: opts.adaptors || [],
111
- autoinstall: opts.autoinstall,
112
- command: opts.command,
113
- expandAdaptors: opts.expandAdaptors !== false,
114
- force: opts.force || false,
115
- immutable: opts.immutable || false,
116
- log: opts.log,
117
- logJson: typeof opts.logJson == "boolean" ? opts.logJson : Boolean(process.env.OPENFN_LOG_JSON),
118
- compile: Boolean(opts.compile),
119
- operation: opts.operation,
120
- outputStdout: Boolean(opts.outputStdout),
121
- packages: opts.packages,
122
- repoDir: opts.repoDir || process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
123
- skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
124
- specifier: opts.specifier,
125
- stateStdin: opts.stateStdin,
126
- timeout: opts.timeout
127
- };
128
- const set = (key, value) => {
129
- newOpts[key] = opts.hasOwnProperty(key) ? opts[key] : value;
130
- };
131
- if (opts.useAdaptorsMonorepo) {
132
- newOpts.monorepoPath = process.env.OPENFN_ADAPTORS_REPO || "ERR";
133
- }
134
- let baseDir = basePath;
135
- if (basePath.endsWith(".js")) {
136
- baseDir = path.dirname(basePath);
137
- set("jobPath", basePath);
138
- } else {
139
- set("jobPath", `${baseDir}/job.js`);
140
- }
141
- set("statePath", `${baseDir}/state.json`);
142
- if (!opts.outputStdout) {
143
- set(
144
- "outputPath",
145
- newOpts.command === "compile" ? `${baseDir}/output.js` : `${baseDir}/output.json`
146
- );
147
- }
148
- ensureLogOpts(newOpts);
149
- return newOpts;
150
- }
151
-
152
- export {
153
- expand_adaptors_default,
154
- printDuration,
155
- CLI,
156
- COMPILER,
157
- RUNTIME,
158
- JOB,
159
- logger_default,
160
- createNullLogger,
161
- defaultLogger,
162
- DEFAULT_REPO_DIR,
163
- ensureLogOpts,
164
- ensureOpts
165
- };