@openfn/logger
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -27,2 +27,4 @@ declare type LogLevel = 'debug' | 'info' | 'default' | 'none'; | ||
success(...args: any[]): void; | ||
confirm(message: string, force?: boolean): Promise<boolean>; | ||
timer(name: string): string | undefined; | ||
break(): void; | ||
@@ -32,3 +34,3 @@ } | ||
declare type LogMessage = [LogFns, ...any[]]; | ||
declare type LogMessage = [LogFns | 'confirm', ...any[]]; | ||
declare type MockLogger = Logger & { | ||
@@ -51,2 +53,4 @@ _last: LogMessage; | ||
export { LogLevel, LogOptions, Logger, mockLogger as createMockLogger, export_default as default, _default$1 as isValidLogLevel, _default as printDuration }; | ||
declare const defaultLogger: Logger; | ||
export { LogLevel, LogOptions, Logger, mockLogger as createMockLogger, export_default as default, defaultLogger, _default$1 as isValidLogLevel, _default as printDuration }; |
// src/logger.ts | ||
import c from "chalk"; | ||
import Confirm from "prompt-confirm"; | ||
@@ -33,2 +34,15 @@ // src/symbols.ts | ||
// src/util/duration.ts | ||
var duration_default = (timeInMs) => { | ||
if (timeInMs < 1e3) { | ||
return `${timeInMs}ms`; | ||
} | ||
const seconds = timeInMs / 1e3; | ||
if (seconds < 60) { | ||
return `${seconds}s`; | ||
} | ||
const minutes = seconds / 60; | ||
return `${Math.floor(minutes)}m ${seconds % 60}s`; | ||
}; | ||
// src/options.ts | ||
@@ -112,2 +126,18 @@ var defaultEmitter = { | ||
}; | ||
const confirm = async (message, force = false) => { | ||
if (force) { | ||
return true; | ||
} | ||
const prompt = new Confirm({ message }); | ||
return prompt.run(); | ||
}; | ||
const timers = {}; | ||
const timer = (name2) => { | ||
if (timers[name2]) { | ||
const startTime = timers[name2]; | ||
delete timers[name2]; | ||
return duration_default(new Date().getTime() - startTime); | ||
} | ||
timers[name2] = new Date().getTime(); | ||
}; | ||
const wrap = (level) => (...args) => log(level, ...args); | ||
@@ -121,2 +151,4 @@ const logger = { | ||
success: wrap(SUCCESS), | ||
confirm, | ||
timer, | ||
force: () => { | ||
@@ -165,2 +197,5 @@ }, | ||
let messageParts = []; | ||
if (log[0] === "confirm") { | ||
return { level: "confirm", message: log[1] }; | ||
} | ||
if (name && !opts.hideNamespace && !opts.hideIcons) { | ||
@@ -188,2 +223,7 @@ [level, namespace, icon, ...messageParts] = log; | ||
}; | ||
mock.confirm = async (message) => { | ||
console.log(message); | ||
history.push(["confirm", message]); | ||
return true; | ||
}; | ||
return mock; | ||
@@ -196,16 +236,4 @@ }; | ||
// src/util/duration.ts | ||
var duration_default = (timeInMs) => { | ||
if (timeInMs < 1e3) { | ||
return `${timeInMs}ms`; | ||
} | ||
const seconds = timeInMs / 1e3; | ||
if (seconds < 60) { | ||
return `${seconds}s`; | ||
} | ||
const minutes = seconds / 60; | ||
return `${Math.floor(minutes)}m ${seconds % 60}s`; | ||
}; | ||
// src/index.ts | ||
var defaultLogger = logger_default(); | ||
var src_default = logger_default; | ||
@@ -215,4 +243,5 @@ export { | ||
src_default as default, | ||
defaultLogger, | ||
is_valid_log_level_default as isValidLogLevel, | ||
duration_default as printDuration | ||
}; |
{ | ||
"name": "@openfn/logger", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Cross-package logging utility", | ||
@@ -23,3 +23,4 @@ "module": "dist/index.js", | ||
"chalk": "4", | ||
"figures": "^5.0.0" | ||
"figures": "^5.0.0", | ||
"prompt-confirm": "^2.0.4" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10519
279
0
3
+ Addedprompt-confirm@^2.0.4
+ Addedansi-bgblack@0.1.1(transitive)
+ Addedansi-bgblue@0.1.1(transitive)
+ Addedansi-bgcyan@0.1.1(transitive)
+ Addedansi-bggreen@0.1.1(transitive)
+ Addedansi-bgmagenta@0.1.1(transitive)
+ Addedansi-bgred@0.1.1(transitive)
+ Addedansi-bgwhite@0.1.1(transitive)
+ Addedansi-bgyellow@0.1.1(transitive)
+ Addedansi-black@0.1.1(transitive)
+ Addedansi-blue@0.1.1(transitive)
+ Addedansi-bold@0.1.1(transitive)
+ Addedansi-colors@0.2.0(transitive)
+ Addedansi-cyan@0.1.1(transitive)
+ Addedansi-dim@0.1.1(transitive)
+ Addedansi-gray@0.1.1(transitive)
+ Addedansi-green@0.1.1(transitive)
+ Addedansi-grey@0.1.1(transitive)
+ Addedansi-hidden@0.1.1(transitive)
+ Addedansi-inverse@0.1.1(transitive)
+ Addedansi-italic@0.1.1(transitive)
+ Addedansi-magenta@0.1.1(transitive)
+ Addedansi-red@0.1.1(transitive)
+ Addedansi-regex@3.0.1(transitive)
+ Addedansi-reset@0.1.1(transitive)
+ Addedansi-strikethrough@0.1.1(transitive)
+ Addedansi-underline@0.1.1(transitive)
+ Addedansi-white@0.1.1(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedansi-yellow@0.1.1(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-swap@1.0.1(transitive)
+ Addedchoices-separator@2.0.0(transitive)
+ Addedclone-deep@1.0.04.0.1(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddebug@2.6.93.2.7(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addederror-symbol@0.1.0(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedfor-in@0.1.81.0.2(transitive)
+ Addedfor-own@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinfo-symbol@0.1.0(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedis-number@3.0.06.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedkind-of@3.2.25.1.06.0.3(transitive)
+ Addedkoalas@1.0.2(transitive)
+ Addedlazy-cache@2.0.2(transitive)
+ Addedlog-ok@0.1.1(transitive)
+ Addedlog-utils@0.2.1(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmixin-object@2.0.1(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addedmute-stream@0.0.7(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedpointer-symbol@1.0.0(transitive)
+ Addedprompt-actions@3.0.2(transitive)
+ Addedprompt-base@4.1.0(transitive)
+ Addedprompt-choices@4.1.0(transitive)
+ Addedprompt-confirm@2.0.4(transitive)
+ Addedprompt-question@5.0.2(transitive)
+ Addedradio-symbol@2.0.0(transitive)
+ Addedreadline-ui@2.2.3(transitive)
+ Addedreadline-utils@2.2.3(transitive)
+ Addedset-getter@0.1.1(transitive)
+ Addedset-value@3.0.3(transitive)
+ Addedshallow-clone@1.0.03.0.1(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
+ Addedstrip-color@0.1.0(transitive)
+ Addedsuccess-symbol@0.1.0(transitive)
+ Addedterminal-paginator@2.0.2(transitive)
+ Addedtime-stamp@1.1.0(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedtoggle-array@1.0.1(transitive)
+ Addedwarning-symbol@0.1.0(transitive)
+ Addedwindow-size@1.1.1(transitive)