@niceties/draftlog-appender 1.0.0-alpha.2 → 1.0.0-alpha.3

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.
package/README.md CHANGED
@@ -27,6 +27,8 @@ or
27
27
  npm install --save @niceties/draftlog-appender
28
28
  ```
29
29
 
30
+ No umd packages published because draftlog appender does not exists in umd format.
31
+
30
32
  # Example
31
33
 
32
34
  To install appender use next import:
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-alpha.2",
2
+ "version": "1.0.0-alpha.3",
3
3
  "license": "MIT",
4
4
  "name": "@niceties/draftlog-appender",
5
5
  "author": "Konstantin Shutkin",
@@ -64,7 +64,7 @@
64
64
  "typescript": "4.4.x"
65
65
  },
66
66
  "dependencies": {
67
- "@niceties/logger": "^1.0.0-alpha.2",
67
+ "@niceties/logger": "^1.0.0-alpha.3",
68
68
  "draftlog": "^1.0.13"
69
69
  }
70
70
  }
package/dist/core.umd.js DELETED
@@ -1,2 +0,0 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("draftlog")):"function"==typeof define&&define.amd?define(["exports","draftlog"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).nicetiesDraftlogAppenderCore={},e.draftlog)}(this,(function(e,n){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=t(n);function l(e){const n={t:0,o:0,l:0,i:[]},t=Object.create(null);return[({message:c,inputId:u,action:f,loglevel:r,ref:s,parentId:d})=>{const a={u:c,_:r,p:s,v:d,g:[]};return 0===f&&(a.I=1),2===f&&(a.I=0),3!==f&&function(e,i){const c=t[e];if(c){const e=(i.I||0)-(c.I||0);delete i.g;const t=null!=i.v&&null==c.v;Object.assign(c,i),n.l+=e,t&&(n.i=n.i.filter((e=>e!==c)),n.l-=c.I||0,l(c.v,c))}else{const n=Object.assign({h:e},i);t[e]=n;const c=n.v;null!=c?l(c,n):o(n,!1)}}(u,a),i(),3===f&&o(a,e),n},()=>(i(),n)];function o(e,t){n.i[t?"unshift":"push"](e),n.l+=e.I||0}function l(e,l){let i=t[e];i||(i={h:e,u:"",g:[],_:0,p:new WeakRef(n)},o(i,!1),t[e]=i),i.g.push(l),n.l+=l.I||0}function i(){var e;for(const o of n.i){if((null===(e=o.p)||void 0===e?void 0:e.deref())||o.g.some((e=>{var n;return null===(n=e.p)||void 0===n?void 0:n.deref()})))break;{n.t+=1+o.g.length,n.i.shift();let e=o;do{null!=e.h&&delete t[e.h],n.l-=e.I||0}while(e=o.g.pop())}}}}e.createDraftlogAppender=function(e,n,t,i){let c;const[u,f]=l(t),r=function(e,n,t){o.default(console),o.default.defaults.canReWrite=!1;const l=[];return e=>{e.t&&(l.splice(0,e.t),e.t=0);let o=0;const c=[[...e.i]];for(;c.length;){const u=c[c.length-1].shift();let f=l[Number(o)];f||(f=console.draft(" "),l.push(f));const r=i(u.I,e.o);for(f(n(u.u,u._,r,t*(c.length-1))),++o,u.g.length&&c.push([...u.g]);c.length&&0===c[c.length-1].length;)c.pop()}};function i(n,t){return n?e.frames[t]:null!=n}}(e,n,i);return function(n){r(u(n)),function(){const n=f().l;n&&!c?(c=setInterval(s,e.interval),c.unref()):!n&&c&&(clearInterval(c),c=void 0)}()};function s(){const n=f();n.o++,n.o%=e.frames.length,r(n)}},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=core.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"core.umd.js","sources":["../src/details/model.ts","../src/core.ts","../src/details/canvas.ts"],"sourcesContent":["import { Action, LogLevel, LogMessage } from '@niceties/logger/types';\n\nexport const enum ItemStatus {\n finished,\n inprogress\n}\nexport interface ModelItem {\n inputId_?: number;\n text_: string;\n status_?: ItemStatus; // undefined means static\n loglevel_: LogLevel;\n ref_?: WeakRef<never>;\n parentId_?: number;\n next_?: ModelItem;\n children_: ModelItem[];\n}\n\nexport type Model = {\n items_: ModelItem[];\n skipLines_: number;\n tick_: number;\n spinning_: number;\n}\n\nexport function createModel(logAboveSpinners: boolean): [(logMessage: LogMessage) => Model, () => Model] {\n const model: Model = {\n skipLines_: 0,\n tick_: 0,\n spinning_: 0,\n items_: []\n };\n const itemById: {[key: number]: ModelItem} = Object.create(null);\n return [({ message: text, inputId, action, loglevel, ref, parentId }: LogMessage): Model => {\n // item has status undefined, so it is static by default\n const item: ModelItem = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, children_: [] };\n if (action === Action.start) {\n item.status_ = ItemStatus.inprogress;\n }\n if (action === Action.finish) {\n item.status_ = ItemStatus.finished;\n }\n if (action !== Action.log) {\n // if status still empty in the original item, or item does not exists it will remain empty and static\n updateModel(inputId as number, item);\n }\n cleanupModel();\n if (action === Action.log) {\n append(item, logAboveSpinners);\n }\n return model;\n }, () => {\n cleanupModel();\n return model;\n }];\n\n function append(item: ModelItem, head: boolean) {\n model.items_[head ? 'unshift' : 'push'](item);\n model.spinning_ += (item.status_ || 0);\n }\n\n function updateModel(inputId: number, options: ModelItem): void {\n const modelItem = itemById[inputId];\n if (!modelItem) {\n const item: ModelItem = {inputId_: inputId, ...options};\n itemById[inputId] = item;\n const itemParentId = item.parentId_;\n if (itemParentId != null) {\n putIntoChildren(itemParentId, item);\n } else {\n append(item, false);\n }\n } else {\n const statusDiff = (options.status_ || 0) - (modelItem.status_ || 0);\n delete (options as Partial<ModelItem>).children_;\n const moveIntoParent = options.parentId_ != null && modelItem.parentId_ == null;\n Object.assign(modelItem, options);\n model.spinning_ += statusDiff;\n if (moveIntoParent) {\n model.items_ = model.items_.filter(item => item !== modelItem);\n model.spinning_ -= (modelItem.status_ || 0);\n putIntoChildren(modelItem.parentId_ as number, modelItem);\n }\n }\n }\n\n function putIntoChildren(itemParentId: number, item: ModelItem) {\n let parent = itemById[itemParentId];\n if (!parent) {\n parent = { inputId_: itemParentId, text_: '', children_: [], loglevel_: 0, ref_: new WeakRef(model) as WeakRef<never> };\n append(parent, false);\n itemById[itemParentId] = parent;\n }\n parent.children_.push(item);\n model.spinning_ += (item.status_ || 0);\n }\n\n function cleanupModel() {\n for (const item of model.items_) {\n if (!item.ref_?.deref() && !item.children_.some(item => item.ref_?.deref())) {\n model.skipLines_ += 1 + item.children_.length;\n model.items_.shift();\n let currentItem: ModelItem | undefined = item;\n do {\n currentItem.inputId_ != null && delete itemById[currentItem.inputId_];\n model.spinning_ -= (currentItem.status_ || 0);\n } while ((currentItem = item.children_.pop()));\n } else {\n break;\n }\n }\n }\n}","import { Formatter, LogMessage } from '@niceties/logger/types';\nimport { createCanvas } from './details/canvas';\nimport { createModel } from './details/model';\nimport { Spinner } from './spinners';\n\nexport function createDraftlogAppender(spinner: Spinner, formatter: Formatter, logAboveSpinners: boolean, ident: number) {\n let interval: NodeJS.Timer | undefined;\n\n const [updateModel, getModel] = createModel(logAboveSpinners);\n const renderModel = createCanvas(spinner, formatter, ident);\n\n return function draftlogAppender(message: LogMessage) {\n renderModel(updateModel(message));\n checkTimeout();\n };\n\n function checkTimeout() {\n const spinning = getModel().spinning_;\n if (spinning && !interval) {\n interval = setInterval(updateSpinners, spinner.interval);\n interval.unref(); // unref immidiately just in case\n } else if (!spinning && interval) {\n clearInterval(interval);\n interval = undefined;\n }\n }\n\n function updateSpinners() {\n const model = getModel();\n model.tick_++;\n model.tick_ %= spinner.frames.length;\n renderModel(model);\n }\n}\n\n\n","import draftlog from 'draftlog';\n\nimport { Formatter } from '@niceties/logger/types';\n\nimport { ItemStatus, Model, ModelItem } from './model';\nimport { Spinner } from '../spinners';\n\ninterface DraftlogConfig {\n defaults: {\n canReWrite: boolean,\n maximumLinesUp: number\n }\n}\n\nexport function createCanvas(spinner: Spinner, formatter: Formatter, ident: number) {\n draftlog(console);\n (draftlog as never as DraftlogConfig).defaults.canReWrite = false;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const updaters: Array<(message?: any, ...optionalParams: any[]) => void> = [];\n\n return (model: Model) => {\n if (model.skipLines_) {\n updaters.splice(0, model.skipLines_);\n model.skipLines_ = 0;\n }\n let key = 0;\n const stack = [[...model.items_]];\n while (stack.length) {\n const item = stack[stack.length - 1].shift() as ModelItem;\n let updater = updaters[Number(key)];\n if (!updater) {\n updater = console.draft(' ');\n updaters.push(updater);\n }\n const prefix = getMessageFormat(item.status_ as ItemStatus, model.tick_);\n updater(formatter(item.text_, item.loglevel_, prefix, ident * (stack.length - 1)));\n // iterate\n ++key;\n if (item.children_.length) {\n stack.push([...item.children_]);\n }\n while (stack.length && stack[stack.length - 1].length === 0) {\n stack.pop();\n }\n }\n };\n\n function getMessageFormat(status: ItemStatus, tick: number): string | boolean {\n // status is truthy when it is inprogress\n const prefix = status ? (spinner.frames[tick]) :\n // status not null when it is finished\n status != null;\n return prefix;\n }\n}\n"],"names":["createModel","logAboveSpinners","model","skipLines_","tick_","spinning_","items_","itemById","Object","create","message","text","inputId","action","loglevel","ref","parentId","item","text_","loglevel_","ref_","parentId_","children_","status_","options","modelItem","statusDiff","moveIntoParent","assign","filter","putIntoChildren","inputId_","itemParentId","append","updateModel","cleanupModel","head","parent","WeakRef","push","deref","some","length","shift","currentItem","pop","spinner","formatter","ident","interval","getModel","renderModel","draftlog","console","defaults","canReWrite","updaters","splice","key","stack","updater","Number","draft","prefix","getMessageFormat","status","tick","frames","createCanvas","spinning","setInterval","updateSpinners","unref","clearInterval","undefined","checkTimeout"],"mappings":"4YAwBgBA,EAAYC,GACxB,MAAMC,EAAe,CACjBC,EAAY,EACZC,EAAO,EACPC,EAAW,EACXC,EAAQ,IAENC,EAAuCC,OAAOC,OAAO,MAC3D,MAAO,CAAC,EAAGC,QAASC,EAAMC,QAAAA,EAASC,OAAAA,EAAQC,SAAAA,EAAUC,IAAAA,EAAKC,SAAAA,MAEtD,MAAMC,EAAkB,CAAEC,EAAOP,EAAMQ,EAAWL,EAAUM,EAAML,EAAKM,EAAWL,EAAUM,EAAW,IAevG,WAdIT,IACAI,EAAKM,SAELV,IACAI,EAAKM,SAELV,GAmBR,S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,UACDH,GAAYpB,IACpBwB,cAAcxB,GACdA,OAAWyB,GAVfC,IAcJ,SAASJ,IACL,MAAMrE,EAAQgD,IACdhD,EAAME,IACNF,EAAME,GAAS0C,EAAQqB,OAAOzB,OAC9BS,EAAYjD"}
package/dist/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- !function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("@niceties/logger/core"),require("@niceties/logger/format-utils"),require("@niceties/logger/default-formatting"),require("./core"),require("./spinners")):"function"==typeof define&&define.amd?define(["@niceties/logger/core","@niceties/logger/format-utils","@niceties/logger/default-formatting","./core","./spinners"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).nicetiesLoggerCore,e.nicetiesLoggerFormatUtils,e.nicetiesLoggerDefaultFormatting,e.nicetiesDraftlogAppenderCore,e.nicetiesDraftlogAppenderSpinners)}(this,(function(e,i,t,r,o){"use strict";const n=i.terminalSupportsUnicode(),s=n?o.dots:o.line,f=i.createFormatter(t.colors,n?t.unicodePrefixes:t.asciiPrefixes);e.appender(r.createDraftlogAppender(s,f,!1,2))}));
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { appender } from '@niceties/logger/core';\nimport { terminalSupportsUnicode, createFormatter } from '@niceties/logger/format-utils';\nimport { colors, unicodePrefixes, asciiPrefixes } from '@niceties/logger/default-formatting';\nimport { createDraftlogAppender } from './core';\nimport { dots, line } from './spinners';\n\nconst supportsUnicode = terminalSupportsUnicode();\nconst spinner = supportsUnicode ? dots : line;\nconst formatter = createFormatter(colors, supportsUnicode ? unicodePrefixes : asciiPrefixes);\n\nappender(createDraftlogAppender(spinner, formatter, false, 2));\n\n"],"names":["supportsUnicode","terminalSupportsUnicode","spinner","dots","line","formatter","createFormatter","colors","unicodePrefixes","asciiPrefixes","createDraftlogAppender"],"mappings":"koBAMA,MAAMA,EAAkBC,4BAClBC,EAAUF,EAAkBG,OAAOC,OACnCC,EAAYC,kBAAgBC,SAAQP,EAAkBQ,kBAAkBC,4BAErEC,yBAAuBR,EAASG,GAAW,EAAO"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).nicetiesDraftlogAppenderSpinners={})}(this,(function(e){"use strict";e.dots={interval:50,frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"]},e.line={interval:130,frames:["-","\\","|","/"]},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=spinners.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spinners.umd.js","sources":["../src/spinners.ts"],"sourcesContent":["export interface Spinner {\n\tinterval: number;\n\tframes: string[];\n}\n\nexport const dots = {\n interval: 50,\n frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']\n};\n\nexport const line = {\n interval: 130,\n frames: ['-', '\\\\', '|', '/']\n};\n"],"names":["interval","frames"],"mappings":"+QAKoB,CAChBA,SAAU,GACVC,OAAQ,CAAC,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,aAGtC,CAChBD,SAAU,IACVC,OAAQ,CAAC,IAAK,KAAM,IAAK"}