diff --git a/packages/cli/src/docs/handler.ts b/packages/cli/src/docs/handler.ts index 95350cf60..1f2f01529 100644 --- a/packages/cli/src/docs/handler.ts +++ b/packages/cli/src/docs/handler.ts @@ -13,36 +13,40 @@ import type { import { getNameAndVersion, getLatestVersion } from '@openfn/runtime'; import expandAdaptors from '../util/expand-adaptors'; -const describeFn = (adaptorName: string, fn: FunctionDescription) => [ - c.green(`## ${ - fn.name -}(${fn.parameters.map(({ name }) => name).join(',')})`), -`${fn.description}`, -c.green('### Usage Examples'), -fn.examples.length - ? fn.examples - .map(({ code, caption }) => { - if (caption) { - return `${caption}:\n${code}`; - } - return code; - }) - .join('\n\n') - : 'None', -c.green('### API Reference'), -`https://docs.openfn.org/adaptors/packages/${adaptorName.replace( - '@openfn/language-', - '' -)}-docs#${fn.name} -`].join('\n\n'); +const describeFn = (adaptorName: string, fn: FunctionDescription) => + [ + c.green( + `## ${fn.name}(${fn.parameters.map(({ name }) => name).join(',')})` + ), + `${fn.description}`, + c.green('### Usage Examples'), + fn.examples.length + ? fn.examples + .map(({ code, caption }) => { + if (caption) { + return `${caption}:\n${code}`; + } + return code; + }) + .join('\n\n') + : 'None', + c.green('### API Reference'), + `https://docs.openfn.org/adaptors/packages/${adaptorName.replace( + '@openfn/language-', + '' + )}-docs#${fn.name} +`, + ].join('\n\n'); -const describeLib = ( - adaptorName: string, - data: PackageDescription -) => c.green(`## ${adaptorName} ${data.version}`) + ` +const describeLib = (adaptorName: string, data: PackageDescription) => + c.green(`## ${adaptorName} ${data.version}`) + + ` ${data.functions - .map((fn) => ` ${c.yellow(fn.name)} (${fn.parameters.map((p) => p.name).join(', ')})`) + .map( + (fn) => + ` ${c.yellow(fn.name)} (${fn.parameters.map((p) => p.name).join(', ')})` + ) .sort() .join('\n')} `; @@ -87,7 +91,7 @@ const docsHandler = async ( const fn = data.functions.find(({ name }) => name === operation); if (fn) { logger.debug('Operation schema:', fn); - logger.break() + logger.break(); // Generate a documentation string desc = describeFn(name, fn); @@ -98,7 +102,6 @@ const docsHandler = async ( logger.debug('No operation name provided'); logger.always('Available functions:\n'); desc = describeLib(name, data); - } // Log the description without any ceremony/meta stuff from the logger logger.print(desc); @@ -107,7 +110,7 @@ const docsHandler = async ( logger.always(`For more details on a specfic functions, use: openfn docs ${name} -`) +`); } if (didError) { diff --git a/packages/cli/src/metadata/handler.ts b/packages/cli/src/metadata/handler.ts index e68681228..bf6be72f0 100644 --- a/packages/cli/src/metadata/handler.ts +++ b/packages/cli/src/metadata/handler.ts @@ -49,7 +49,8 @@ export const getAdaptorPath = async ( return adaptorPath; }; -export const shouldAutoinstall = (adaptor: string): boolean => adaptor?.length > 0 && !adaptor.startsWith('/') && !adaptor.includes('='); +export const shouldAutoinstall = (adaptor: string): boolean => + adaptor?.length > 0 && !adaptor.startsWith('/') && !adaptor.includes('='); const metadataHandler = async (options: MetadataOpts, logger: Logger) => { const { repoDir, adaptors } = options; diff --git a/packages/cli/src/pull/command.ts b/packages/cli/src/pull/command.ts index 658507712..6697783ff 100644 --- a/packages/cli/src/pull/command.ts +++ b/packages/cli/src/pull/command.ts @@ -6,7 +6,14 @@ import * as o from '../options'; export type PullOptions = Required< Pick< Opts, - 'command' | 'log' | 'logJson' | 'statePath' | 'projectPath' | 'configPath' | 'projectId' | 'confirm' + | 'command' + | 'log' + | 'logJson' + | 'statePath' + | 'projectPath' + | 'configPath' + | 'projectId' + | 'confirm' > >; @@ -16,16 +23,17 @@ const pullCommand: yargs.CommandModule = { command: 'pull [projectId]', describe: "Pull a project's state and spec from a Lightning Instance to the local directory", - builder: (yargs: yargs.Argv) => - build(options, yargs) - .positional('projectId', { - describe: - 'The id of the project that should be pulled shouled be a UUID', - demandOption: true, - }).example( - 'pull 57862287-23e6-4650-8d79-e1dd88b24b1c', - 'Pull an updated copy of a the above spec and state from a Lightning Instance' - ), + builder: (yargs: yargs.Argv) => + build(options, yargs) + .positional('projectId', { + describe: + 'The id of the project that should be pulled shouled be a UUID', + demandOption: true, + }) + .example( + 'pull 57862287-23e6-4650-8d79-e1dd88b24b1c', + 'Pull an updated copy of a the above spec and state from a Lightning Instance' + ), handler: ensure('pull', options), }; diff --git a/packages/cli/src/pull/handler.ts b/packages/cli/src/pull/handler.ts index 3e5d58b8b..d01079f36 100644 --- a/packages/cli/src/pull/handler.ts +++ b/packages/cli/src/pull/handler.ts @@ -15,7 +15,9 @@ async function pullHandler(options: PullOptions, logger: Logger) { try { assertPath(options.projectId); const config = mergeOverrides(await getConfig(options.configPath), options); - logger.always('Downloading existing project state (as JSON) from the server.'); + logger.always( + 'Downloading existing project state (as JSON) from the server.' + ); // Get the project.json from Lightning const { data: project } = await getProject(config, options.projectId); @@ -38,9 +40,7 @@ async function pullHandler(options: PullOptions, logger: Logger) { JSON.stringify(state, null, 2) ); - logger.always( - 'Downloading the project spec (as YAML) from the server.' - ); + logger.always('Downloading the project spec (as YAML) from the server.'); // Get the project.yaml from Lightning const url = new URL( `api/provision/yaml?id=${options.projectId}`, diff --git a/packages/cli/src/test/handler.ts b/packages/cli/src/test/handler.ts index 1d148df4a..7b241ddc5 100644 --- a/packages/cli/src/test/handler.ts +++ b/packages/cli/src/test/handler.ts @@ -61,7 +61,12 @@ const testHandler = async (options: TestOptions, logger: Logger) => { const state = await loadState(plan, opts, createNullLogger()); const compiledPlan = (await compile(plan, opts, logger)) as ExecutionPlan; - const result = await execute(compiledPlan, state, opts as ExecuteOptions, logger); + const result = await execute( + compiledPlan, + state, + opts as ExecuteOptions, + logger + ); logger.success(`Result: ${result.data.answer}`); return result; }; diff --git a/packages/cli/src/util/cache.ts b/packages/cli/src/util/cache.ts index b9db05cc6..cd69d931c 100644 --- a/packages/cli/src/util/cache.ts +++ b/packages/cli/src/util/cache.ts @@ -57,7 +57,7 @@ export const saveToCache = async ( logger.info(`Writing ${stepId} output to ${cachePath}`); fs.writeFileSync(cachePath, JSON.stringify(output)); } -} +}; export const clearCache = async ( plan: ExecutionPlan, @@ -67,15 +67,15 @@ export const clearCache = async ( const cacheDir = await getCachePath(plan, options); try { - await rmdir(cacheDir, { recursive: true }) + await rmdir(cacheDir, { recursive: true }); logger.info(`Cleared cache at ${cacheDir}`); - } catch(e: any) { + } catch (e: any) { if (e.code === 'ENOENT') { // No cached files exist - this is fine, do nothing } else { - logger.error(`Error while clearing cache at ${cacheDir}`) - logger.error(e) + logger.error(`Error while clearing cache at ${cacheDir}`); + logger.error(e); } } -} +}; diff --git a/packages/cli/src/util/load-plan.ts b/packages/cli/src/util/load-plan.ts index eff5cd8cc..9c41550ed 100644 --- a/packages/cli/src/util/load-plan.ts +++ b/packages/cli/src/util/load-plan.ts @@ -50,7 +50,7 @@ const loadJson = async (workflowPath: string, logger: Logger): Promise => { try { text = await fs.readFile(workflowPath, 'utf8'); - logger.debug('Loaded workflow from', workflowPath) + logger.debug('Loaded workflow from', workflowPath); } catch (e) { return abort( logger, @@ -170,7 +170,7 @@ const fetchFile = async ( ? filePath : path.resolve(rootDir, filePath); const result = await fs.readFile(fullPath, 'utf8'); - log.debug('Loaded file', fullPath) + log.debug('Loaded file', fullPath); return result; } catch (e) { abort( diff --git a/packages/compiler/src/transforms/lazy-state.ts b/packages/compiler/src/transforms/lazy-state.ts index ec1154b3e..7cc8ae13a 100644 --- a/packages/compiler/src/transforms/lazy-state.ts +++ b/packages/compiler/src/transforms/lazy-state.ts @@ -3,10 +3,10 @@ * * Converts all $.a.b chains unless: * - $ was assigned previously in that scope - * + * * */ -import { builders as b, namedTypes as n} from 'ast-types'; +import { builders as b, namedTypes as n } from 'ast-types'; import type { NodePath } from 'ast-types/lib/node-path'; import type { Transformer } from '../transform'; @@ -17,14 +17,14 @@ const ensureParentArrow = (path: NodePath) => { // find the parenting call expression // Ie, the operation we're passing this arrow into - while(root && !n.CallExpression.check(root.node)) { + while (root && !n.CallExpression.check(root.node)) { last = root; root = root.parent; // if this is any kind of statement, we should throw // TODO we may relax this, see https://github.com/OpenFn/kit/issues/660 if (n.Statement.check(root.node) || n.Declaration.check(root.node)) { - throw new Error(`invalid state operator: must be inside an expression`) + throw new Error(`invalid state operator: must be inside an expression`); } } @@ -38,26 +38,30 @@ const ensureParentArrow = (path: NodePath) => { } } else { // Actually I don't think we'll ever get here - throw new Error(`invalid state operator: must be be passed as an argument to an operator`) + throw new Error( + `invalid state operator: must be be passed as an argument to an operator` + ); } -} +}; // Checks whether the passed node is an open function, ie, (state) => {...} const isOpenFunction = (path: NodePath) => { // is it a function? - if (n.ArrowFunctionExpression.check(path.node)) { + if (n.ArrowFunctionExpression.check(path.node)) { const arrow = path.node as n.ArrowFunctionExpression; // does it have one param? - if(arrow.params.length == 1) { - const name = (arrow.params[0] as n.Identifier).name + if (arrow.params.length == 1) { + const name = (arrow.params[0] as n.Identifier).name; // is the param called state? - if (name === "state") { + if (name === 'state') { // We already have a valid open function here return true; } - throw new Error(`invalid state operator: parameter "${name}" should be called "state"`) + throw new Error( + `invalid state operator: parameter "${name}" should be called "state"` + ); } - throw new Error('invalid state operator: parent has wrong arity') + throw new Error('invalid state operator: parent has wrong arity'); } // if we get here, then path is: diff --git a/packages/describe-package/src/fs/fake-fs.ts b/packages/describe-package/src/fs/fake-fs.ts index 1f1e4c46c..58769903b 100644 --- a/packages/describe-package/src/fs/fake-fs.ts +++ b/packages/describe-package/src/fs/fake-fs.ts @@ -1,4 +1,4 @@ -type System = import("typescript").System; +type System = import('typescript').System; let hasLocalStorage = false; try { @@ -8,19 +8,19 @@ try { const hasProcess = typeof process !== `undefined`; const shouldDebug = - (hasLocalStorage && localStorage.getItem("DEBUG")) || + (hasLocalStorage && localStorage.getItem('DEBUG')) || (hasProcess && process.env.DEBUG); const debugLog = shouldDebug ? console.log - : (_message?: any, ..._optionalParams: any[]) => ""; + : (_message?: any, ..._optionalParams: any[]) => ''; function notImplemented(methodName: string): any { throw new Error(`Method '${methodName}' is not implemented.`); } // // "/DOM.d.ts" => "/lib.dom.d.ts" -const libize = (path: string) => path.replace("/", "/lib.").toLowerCase(); +const libize = (path: string) => path.replace('/', '/lib.').toLowerCase(); function audit( name: string, @@ -29,9 +29,9 @@ function audit( return (...args) => { const res = fn(...args); - const smallres = typeof res === "string" ? res.slice(0, 80) + "..." : res; - debugLog("> " + name, ...args); - debugLog("< " + smallres); + const smallres = typeof res === 'string' ? res.slice(0, 80) + '...' : res; + debugLog('> ' + name, ...args); + debugLog('< ' + smallres); return res; }; @@ -40,31 +40,31 @@ function audit( export function createSystem(files: Map): System { return { args: [], - createDirectory: () => notImplemented("createDirectory"), - directoryExists: audit("directoryExists", (directory) => { + createDirectory: () => notImplemented('createDirectory'), + directoryExists: audit('directoryExists', (directory) => { return Array.from(files.keys()).some((path) => path.startsWith(directory) ); }), - exit: () => notImplemented("exit"), + exit: () => notImplemented('exit'), fileExists: audit( - "fileExists", + 'fileExists', (fileName) => files.has(fileName) || files.has(libize(fileName)) ), - getCurrentDirectory: () => "/", + getCurrentDirectory: () => '/', getDirectories: () => [], - getExecutingFilePath: () => notImplemented("getExecutingFilePath"), - readDirectory: audit("readDirectory", (directory) => - directory === "/" ? Array.from(files.keys()) : [] + getExecutingFilePath: () => notImplemented('getExecutingFilePath'), + readDirectory: audit('readDirectory', (directory) => + directory === '/' ? Array.from(files.keys()) : [] ), readFile: audit( - "readFile", + 'readFile', (fileName) => files.get(fileName) || files.get(libize(fileName)) ), resolvePath: (path) => path, - newLine: "\n", + newLine: '\n', useCaseSensitiveFileNames: true, - write: () => notImplemented("write"), + write: () => notImplemented('write'), writeFile: (fileName, contents) => { files.set(fileName, contents); }, diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index 79d69233f..c4d5cd032 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -2,7 +2,7 @@ import createLogger from './logger'; import createMockLogger from './mock'; import isValidLogLevel from './util/is-valid-log-level'; import printDuration from './util/duration'; -import timestamp from './util/timestamp' +import timestamp from './util/timestamp'; export { createMockLogger, isValidLogLevel, printDuration, timestamp }; @@ -12,4 +12,4 @@ export default createLogger; export type { Logger, JSONLog, StringLog } from './logger'; export type { LogOptions, LogLevel } from './options'; -export type { SanitizePolicies } from './sanitize'; \ No newline at end of file +export type { SanitizePolicies } from './sanitize'; diff --git a/packages/logger/src/util/timestamp.ts b/packages/logger/src/util/timestamp.ts index f6b421b9b..e1f409bfc 100644 --- a/packages/logger/src/util/timestamp.ts +++ b/packages/logger/src/util/timestamp.ts @@ -2,10 +2,10 @@ // We use this as a base to calculate timestamps later const start = BigInt(Date.now()) * BigInt(1e6); -const startDiff = process.hrtime.bigint() +const startDiff = process.hrtime.bigint(); // The timestamp is: workout the time elapsed (in nanoseconds) and add that to the start date -export default () => start + (process.hrtime.bigint() - startDiff) +export default () => start + (process.hrtime.bigint() - startDiff); // Util to convert a bigint timestamp to a date export const timestampToDate = (time: bigint) => diff --git a/packages/ws-worker/src/start.ts b/packages/ws-worker/src/start.ts index 5889725cb..723fd0828 100644 --- a/packages/ws-worker/src/start.ts +++ b/packages/ws-worker/src/start.ts @@ -5,7 +5,7 @@ import createMockRTE from './mock/runtime-engine'; import createWorker, { ServerOptions } from './server'; import cli from './util/cli'; -const args = cli(process.argv) +const args = cli(process.argv); const logger = createLogger('SRV', { level: args.log });