appos 0.1.2-0 → 0.1.3-0
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/build/{lib/dist-cjs-i0PJ4BkY.mjs → exports/dist-cjs-B43A5HXv.mjs} +3 -3
- package/build/{lib/dist-cjs-Ckv1CA7H.mjs → exports/dist-cjs-BmbYbMhp.mjs} +2 -2
- package/build/{lib/dist-cjs-CZJ3_gz8.mjs → exports/dist-cjs-DHlTgXUO.mjs} +1 -0
- package/build/{lib/dist-cjs-BwD8H9no.mjs → exports/dist-cjs-Ddm6Stp9.mjs} +3 -3
- package/build/{lib/sso-oidc-DihM2auV.mjs → exports/sso-oidc-Qom0PEDW.mjs} +1 -1
- package/build/{lib/sts-qpAtvsDA.mjs → exports/sts-CLRaHSW_.mjs} +2 -2
- package/build/{lib/sts-DxVJ4opX.mjs → exports/sts-Dl7yZqX1.mjs} +1 -1
- package/build/{lib → exports}/test.mjs +4 -4
- package/build/{lib → exports}/ui/index.d.ts +281 -281
- package/build/lib/caller.js +30 -0
- package/build/lib/constants.js +28 -0
- package/build/lib/deprecations.js +8 -0
- package/build/lib/levels.js +241 -0
- package/build/lib/meta.js +3 -0
- package/build/lib/multistream.js +203 -0
- package/build/lib/proto.js +256 -0
- package/build/lib/redaction.js +114 -0
- package/build/lib/symbols.js +74 -0
- package/build/lib/time.js +39 -0
- package/build/lib/tools.js +423 -0
- package/build/lib/transport-stream.js +56 -0
- package/build/lib/transport.js +167 -0
- package/build/lib/worker.js +194 -0
- package/build/main.js +4 -4
- package/package.json +19 -18
- /package/build/{lib → exports}/adapter-factory-CLtf7vT5-CTKiMV2u.mjs +0 -0
- /package/build/{lib → exports}/bun-sqlite-dialect-DN7EKoIB-0pWIoG0L.mjs +0 -0
- /package/build/{lib → exports}/chunk-BYI67GdN.mjs +0 -0
- /package/build/{lib → exports}/chunk-CkKlU7xI.mjs +0 -0
- /package/build/{lib → exports}/client-BtuhFgvy.mjs +0 -0
- /package/build/{lib → exports}/client.d.ts +0 -0
- /package/build/{lib → exports}/client.js +0 -0
- /package/build/{lib → exports}/date.d.ts +0 -0
- /package/build/{lib → exports}/date.js +0 -0
- /package/build/{lib → exports}/dialect-BeMwdQoz-D41NdSow.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-B_wkbabY.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-Cc337rwW.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-CgzfN8xY.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-DBFcizQf.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-DC-UL-xx.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-DYAmJYzN.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-GFGBhaZg.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-ieCOxrOi.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-nbOGa7i_.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-pN6ekzMW.mjs +0 -0
- /package/build/{lib → exports}/dist-cjs-yYlQ1OiO.mjs +0 -0
- /package/build/{lib → exports}/esm-DPet4lFW.mjs +0 -0
- /package/build/{lib → exports}/event-streams-x9fP9BzF.mjs +0 -0
- /package/build/{lib → exports}/file-preview-dialog-Cugg8tEc.mjs +0 -0
- /package/build/{lib → exports}/kysely-adapter-BTWfu5rn.mjs +0 -0
- /package/build/{lib → exports}/magic-string.es-jZcifc5m.mjs +0 -0
- /package/build/{lib → exports}/memory-adapter-DiU519m9.mjs +0 -0
- /package/build/{lib → exports}/node-ponyfill-Dmm1SWTU.mjs +0 -0
- /package/build/{lib → exports}/node-sqlite-dialect-BqISUSC3-DYvTLBpY.mjs +0 -0
- /package/build/{lib → exports}/package-DfozRyK6.mjs +0 -0
- /package/build/{lib → exports}/react-dom-CPjM_WCt.mjs +0 -0
- /package/build/{lib → exports}/server.d.mts +0 -0
- /package/build/{lib → exports}/server.mjs +0 -0
- /package/build/{lib → exports}/test.d.mts +0 -0
- /package/build/{lib → exports}/ui/index.js +0 -0
- /package/build/{lib → exports}/utils.d.ts +0 -0
- /package/build/{lib → exports}/utils.js +0 -0
- /package/build/{lib → exports}/zod.d.ts +0 -0
- /package/build/{lib → exports}/zod.js +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function noOpPrepareStackTrace (_, stack) {
|
|
4
|
+
return stack
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports = function getCallers () {
|
|
8
|
+
const originalPrepare = Error.prepareStackTrace
|
|
9
|
+
Error.prepareStackTrace = noOpPrepareStackTrace
|
|
10
|
+
const stack = new Error().stack
|
|
11
|
+
Error.prepareStackTrace = originalPrepare
|
|
12
|
+
|
|
13
|
+
if (!Array.isArray(stack)) {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const entries = stack.slice(2)
|
|
18
|
+
|
|
19
|
+
const fileNames = []
|
|
20
|
+
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (!entry) {
|
|
23
|
+
continue
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fileNames.push(entry.getFileName())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fileNames
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents default log level values
|
|
3
|
+
*
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_LEVELS = {
|
|
7
|
+
trace: 10,
|
|
8
|
+
debug: 20,
|
|
9
|
+
info: 30,
|
|
10
|
+
warn: 40,
|
|
11
|
+
error: 50,
|
|
12
|
+
fatal: 60
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents sort order direction: `ascending` or `descending`
|
|
17
|
+
*
|
|
18
|
+
* @enum {string}
|
|
19
|
+
*/
|
|
20
|
+
const SORTING_ORDER = {
|
|
21
|
+
ASC: 'ASC',
|
|
22
|
+
DESC: 'DESC'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
DEFAULT_LEVELS,
|
|
27
|
+
SORTING_ORDER
|
|
28
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
/* eslint no-prototype-builtins: 0 */
|
|
3
|
+
const {
|
|
4
|
+
lsCacheSym,
|
|
5
|
+
levelValSym,
|
|
6
|
+
useOnlyCustomLevelsSym,
|
|
7
|
+
streamSym,
|
|
8
|
+
formattersSym,
|
|
9
|
+
hooksSym,
|
|
10
|
+
levelCompSym
|
|
11
|
+
} = require('./symbols')
|
|
12
|
+
const { noop, genLog } = require('./tools')
|
|
13
|
+
const { DEFAULT_LEVELS, SORTING_ORDER } = require('./constants')
|
|
14
|
+
|
|
15
|
+
const levelMethods = {
|
|
16
|
+
fatal: (hook) => {
|
|
17
|
+
const logFatal = genLog(DEFAULT_LEVELS.fatal, hook)
|
|
18
|
+
return function (...args) {
|
|
19
|
+
const stream = this[streamSym]
|
|
20
|
+
logFatal.call(this, ...args)
|
|
21
|
+
if (typeof stream.flushSync === 'function') {
|
|
22
|
+
try {
|
|
23
|
+
stream.flushSync()
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// https://github.com/pinojs/pino/pull/740#discussion_r346788313
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
error: (hook) => genLog(DEFAULT_LEVELS.error, hook),
|
|
31
|
+
warn: (hook) => genLog(DEFAULT_LEVELS.warn, hook),
|
|
32
|
+
info: (hook) => genLog(DEFAULT_LEVELS.info, hook),
|
|
33
|
+
debug: (hook) => genLog(DEFAULT_LEVELS.debug, hook),
|
|
34
|
+
trace: (hook) => genLog(DEFAULT_LEVELS.trace, hook)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const nums = Object.keys(DEFAULT_LEVELS).reduce((o, k) => {
|
|
38
|
+
o[DEFAULT_LEVELS[k]] = k
|
|
39
|
+
return o
|
|
40
|
+
}, {})
|
|
41
|
+
|
|
42
|
+
const initialLsCache = Object.keys(nums).reduce((o, k) => {
|
|
43
|
+
o[k] = '{"level":' + Number(k)
|
|
44
|
+
return o
|
|
45
|
+
}, {})
|
|
46
|
+
|
|
47
|
+
function genLsCache (instance) {
|
|
48
|
+
const formatter = instance[formattersSym].level
|
|
49
|
+
const { labels } = instance.levels
|
|
50
|
+
const cache = {}
|
|
51
|
+
for (const label in labels) {
|
|
52
|
+
const level = formatter(labels[label], Number(label))
|
|
53
|
+
cache[label] = JSON.stringify(level).slice(0, -1)
|
|
54
|
+
}
|
|
55
|
+
instance[lsCacheSym] = cache
|
|
56
|
+
return instance
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isStandardLevel (level, useOnlyCustomLevels) {
|
|
60
|
+
if (useOnlyCustomLevels) {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
switch (level) {
|
|
65
|
+
case 'fatal':
|
|
66
|
+
case 'error':
|
|
67
|
+
case 'warn':
|
|
68
|
+
case 'info':
|
|
69
|
+
case 'debug':
|
|
70
|
+
case 'trace':
|
|
71
|
+
return true
|
|
72
|
+
default:
|
|
73
|
+
return false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function setLevel (level) {
|
|
78
|
+
const { labels, values } = this.levels
|
|
79
|
+
if (typeof level === 'number') {
|
|
80
|
+
if (labels[level] === undefined) throw Error('unknown level value' + level)
|
|
81
|
+
level = labels[level]
|
|
82
|
+
}
|
|
83
|
+
if (values[level] === undefined) throw Error('unknown level ' + level)
|
|
84
|
+
const preLevelVal = this[levelValSym]
|
|
85
|
+
const levelVal = this[levelValSym] = values[level]
|
|
86
|
+
const useOnlyCustomLevelsVal = this[useOnlyCustomLevelsSym]
|
|
87
|
+
const levelComparison = this[levelCompSym]
|
|
88
|
+
const hook = this[hooksSym].logMethod
|
|
89
|
+
|
|
90
|
+
for (const key in values) {
|
|
91
|
+
if (levelComparison(values[key], levelVal) === false) {
|
|
92
|
+
this[key] = noop
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
this[key] = isStandardLevel(key, useOnlyCustomLevelsVal) ? levelMethods[key](hook) : genLog(values[key], hook)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.emit(
|
|
99
|
+
'level-change',
|
|
100
|
+
level,
|
|
101
|
+
levelVal,
|
|
102
|
+
labels[preLevelVal],
|
|
103
|
+
preLevelVal,
|
|
104
|
+
this
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getLevel (level) {
|
|
109
|
+
const { levels, levelVal } = this
|
|
110
|
+
// protection against potential loss of Pino scope from serializers (edge case with circular refs - https://github.com/pinojs/pino/issues/833)
|
|
111
|
+
return (levels && levels.labels) ? levels.labels[levelVal] : ''
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isLevelEnabled (logLevel) {
|
|
115
|
+
const { values } = this.levels
|
|
116
|
+
const logLevelVal = values[logLevel]
|
|
117
|
+
return logLevelVal !== undefined && this[levelCompSym](logLevelVal, this[levelValSym])
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Determine if the given `current` level is enabled by comparing it
|
|
122
|
+
* against the current threshold (`expected`).
|
|
123
|
+
*
|
|
124
|
+
* @param {SORTING_ORDER} direction comparison direction "ASC" or "DESC"
|
|
125
|
+
* @param {number} current current log level number representation
|
|
126
|
+
* @param {number} expected threshold value to compare with
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
*/
|
|
129
|
+
function compareLevel (direction, current, expected) {
|
|
130
|
+
if (direction === SORTING_ORDER.DESC) {
|
|
131
|
+
return current <= expected
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return current >= expected
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create a level comparison function based on `levelComparison`
|
|
139
|
+
* it could a default function which compares levels either in "ascending" or "descending" order or custom comparison function
|
|
140
|
+
*
|
|
141
|
+
* @param {SORTING_ORDER | Function} levelComparison sort levels order direction or custom comparison function
|
|
142
|
+
* @returns Function
|
|
143
|
+
*/
|
|
144
|
+
function genLevelComparison (levelComparison) {
|
|
145
|
+
if (typeof levelComparison === 'string') {
|
|
146
|
+
return compareLevel.bind(null, levelComparison)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return levelComparison
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function mappings (customLevels = null, useOnlyCustomLevels = false) {
|
|
153
|
+
const customNums = customLevels
|
|
154
|
+
/* eslint-disable */
|
|
155
|
+
? Object.keys(customLevels).reduce((o, k) => {
|
|
156
|
+
o[customLevels[k]] = k
|
|
157
|
+
return o
|
|
158
|
+
}, {})
|
|
159
|
+
: null
|
|
160
|
+
/* eslint-enable */
|
|
161
|
+
|
|
162
|
+
const labels = Object.assign(
|
|
163
|
+
Object.create(Object.prototype, { Infinity: { value: 'silent' } }),
|
|
164
|
+
useOnlyCustomLevels ? null : nums,
|
|
165
|
+
customNums
|
|
166
|
+
)
|
|
167
|
+
const values = Object.assign(
|
|
168
|
+
Object.create(Object.prototype, { silent: { value: Infinity } }),
|
|
169
|
+
useOnlyCustomLevels ? null : DEFAULT_LEVELS,
|
|
170
|
+
customLevels
|
|
171
|
+
)
|
|
172
|
+
return { labels, values }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function assertDefaultLevelFound (defaultLevel, customLevels, useOnlyCustomLevels) {
|
|
176
|
+
if (typeof defaultLevel === 'number') {
|
|
177
|
+
const values = [].concat(
|
|
178
|
+
Object.keys(customLevels || {}).map(key => customLevels[key]),
|
|
179
|
+
useOnlyCustomLevels ? [] : Object.keys(nums).map(level => +level),
|
|
180
|
+
Infinity
|
|
181
|
+
)
|
|
182
|
+
if (!values.includes(defaultLevel)) {
|
|
183
|
+
throw Error(`default level:${defaultLevel} must be included in custom levels`)
|
|
184
|
+
}
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const labels = Object.assign(
|
|
189
|
+
Object.create(Object.prototype, { silent: { value: Infinity } }),
|
|
190
|
+
useOnlyCustomLevels ? null : DEFAULT_LEVELS,
|
|
191
|
+
customLevels
|
|
192
|
+
)
|
|
193
|
+
if (!(defaultLevel in labels)) {
|
|
194
|
+
throw Error(`default level:${defaultLevel} must be included in custom levels`)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function assertNoLevelCollisions (levels, customLevels) {
|
|
199
|
+
const { labels, values } = levels
|
|
200
|
+
for (const k in customLevels) {
|
|
201
|
+
if (k in values) {
|
|
202
|
+
throw Error('levels cannot be overridden')
|
|
203
|
+
}
|
|
204
|
+
if (customLevels[k] in labels) {
|
|
205
|
+
throw Error('pre-existing level values cannot be used for new levels')
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Validates whether `levelComparison` is correct
|
|
212
|
+
*
|
|
213
|
+
* @throws Error
|
|
214
|
+
* @param {SORTING_ORDER | Function} levelComparison - value to validate
|
|
215
|
+
* @returns
|
|
216
|
+
*/
|
|
217
|
+
function assertLevelComparison (levelComparison) {
|
|
218
|
+
if (typeof levelComparison === 'function') {
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (typeof levelComparison === 'string' && Object.values(SORTING_ORDER).includes(levelComparison)) {
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
throw new Error('Levels comparison should be one of "ASC", "DESC" or "function" type')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = {
|
|
230
|
+
initialLsCache,
|
|
231
|
+
genLsCache,
|
|
232
|
+
levelMethods,
|
|
233
|
+
getLevel,
|
|
234
|
+
setLevel,
|
|
235
|
+
isLevelEnabled,
|
|
236
|
+
mappings,
|
|
237
|
+
assertNoLevelCollisions,
|
|
238
|
+
assertDefaultLevelFound,
|
|
239
|
+
genLevelComparison,
|
|
240
|
+
assertLevelComparison
|
|
241
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const metadata = Symbol.for('pino.metadata')
|
|
4
|
+
const { DEFAULT_LEVELS } = require('./constants')
|
|
5
|
+
|
|
6
|
+
const DEFAULT_INFO_LEVEL = DEFAULT_LEVELS.info
|
|
7
|
+
|
|
8
|
+
function multistream (streamsArray, opts) {
|
|
9
|
+
streamsArray = streamsArray || []
|
|
10
|
+
opts = opts || { dedupe: false }
|
|
11
|
+
|
|
12
|
+
const streamLevels = Object.create(DEFAULT_LEVELS)
|
|
13
|
+
streamLevels.silent = Infinity
|
|
14
|
+
if (opts.levels && typeof opts.levels === 'object') {
|
|
15
|
+
Object.keys(opts.levels).forEach(i => {
|
|
16
|
+
streamLevels[i] = opts.levels[i]
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const res = {
|
|
21
|
+
write,
|
|
22
|
+
add,
|
|
23
|
+
remove,
|
|
24
|
+
emit,
|
|
25
|
+
flushSync,
|
|
26
|
+
end,
|
|
27
|
+
minLevel: 0,
|
|
28
|
+
lastId: 0,
|
|
29
|
+
streams: [],
|
|
30
|
+
clone,
|
|
31
|
+
[metadata]: true,
|
|
32
|
+
streamLevels
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(streamsArray)) {
|
|
36
|
+
streamsArray.forEach(add, res)
|
|
37
|
+
} else {
|
|
38
|
+
add.call(res, streamsArray)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// clean this object up
|
|
42
|
+
// or it will stay allocated forever
|
|
43
|
+
// as it is closed on the following closures
|
|
44
|
+
streamsArray = null
|
|
45
|
+
|
|
46
|
+
return res
|
|
47
|
+
|
|
48
|
+
// we can exit early because the streams are ordered by level
|
|
49
|
+
function write (data) {
|
|
50
|
+
let dest
|
|
51
|
+
const level = this.lastLevel
|
|
52
|
+
const { streams } = this
|
|
53
|
+
// for handling situation when several streams has the same level
|
|
54
|
+
let recordedLevel = 0
|
|
55
|
+
let stream
|
|
56
|
+
|
|
57
|
+
// if dedupe set to true we send logs to the stream with the highest level
|
|
58
|
+
// therefore, we have to change sorting order
|
|
59
|
+
for (let i = initLoopVar(streams.length, opts.dedupe); checkLoopVar(i, streams.length, opts.dedupe); i = adjustLoopVar(i, opts.dedupe)) {
|
|
60
|
+
dest = streams[i]
|
|
61
|
+
if (dest.level <= level) {
|
|
62
|
+
if (recordedLevel !== 0 && recordedLevel !== dest.level) {
|
|
63
|
+
break
|
|
64
|
+
}
|
|
65
|
+
stream = dest.stream
|
|
66
|
+
if (stream[metadata]) {
|
|
67
|
+
const { lastTime, lastMsg, lastObj, lastLogger } = this
|
|
68
|
+
stream.lastLevel = level
|
|
69
|
+
stream.lastTime = lastTime
|
|
70
|
+
stream.lastMsg = lastMsg
|
|
71
|
+
stream.lastObj = lastObj
|
|
72
|
+
stream.lastLogger = lastLogger
|
|
73
|
+
}
|
|
74
|
+
stream.write(data)
|
|
75
|
+
if (opts.dedupe) {
|
|
76
|
+
recordedLevel = dest.level
|
|
77
|
+
}
|
|
78
|
+
} else if (!opts.dedupe) {
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function emit (...args) {
|
|
85
|
+
for (const { stream } of this.streams) {
|
|
86
|
+
if (typeof stream.emit === 'function') {
|
|
87
|
+
stream.emit(...args)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function flushSync () {
|
|
93
|
+
for (const { stream } of this.streams) {
|
|
94
|
+
if (typeof stream.flushSync === 'function') {
|
|
95
|
+
stream.flushSync()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function add (dest) {
|
|
101
|
+
if (!dest) {
|
|
102
|
+
return res
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Check that dest implements either StreamEntry or DestinationStream
|
|
106
|
+
const isStream = typeof dest.write === 'function' || dest.stream
|
|
107
|
+
const stream_ = dest.write ? dest : dest.stream
|
|
108
|
+
// This is necessary to provide a meaningful error message, otherwise it throws somewhere inside write()
|
|
109
|
+
if (!isStream) {
|
|
110
|
+
throw Error('stream object needs to implement either StreamEntry or DestinationStream interface')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const { streams, streamLevels } = this
|
|
114
|
+
|
|
115
|
+
let level
|
|
116
|
+
if (typeof dest.levelVal === 'number') {
|
|
117
|
+
level = dest.levelVal
|
|
118
|
+
} else if (typeof dest.level === 'string') {
|
|
119
|
+
level = streamLevels[dest.level]
|
|
120
|
+
} else if (typeof dest.level === 'number') {
|
|
121
|
+
level = dest.level
|
|
122
|
+
} else {
|
|
123
|
+
level = DEFAULT_INFO_LEVEL
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const dest_ = {
|
|
127
|
+
stream: stream_,
|
|
128
|
+
level,
|
|
129
|
+
levelVal: undefined,
|
|
130
|
+
id: ++res.lastId
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
streams.unshift(dest_)
|
|
134
|
+
streams.sort(compareByLevel)
|
|
135
|
+
|
|
136
|
+
this.minLevel = streams[0].level
|
|
137
|
+
|
|
138
|
+
return res
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function remove (id) {
|
|
142
|
+
const { streams } = this
|
|
143
|
+
const index = streams.findIndex(s => s.id === id)
|
|
144
|
+
|
|
145
|
+
if (index >= 0) {
|
|
146
|
+
streams.splice(index, 1)
|
|
147
|
+
streams.sort(compareByLevel)
|
|
148
|
+
this.minLevel = streams.length > 0 ? streams[0].level : -1
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return res
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function end () {
|
|
155
|
+
for (const { stream } of this.streams) {
|
|
156
|
+
if (typeof stream.flushSync === 'function') {
|
|
157
|
+
stream.flushSync()
|
|
158
|
+
}
|
|
159
|
+
stream.end()
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function clone (level) {
|
|
164
|
+
const streams = new Array(this.streams.length)
|
|
165
|
+
|
|
166
|
+
for (let i = 0; i < streams.length; i++) {
|
|
167
|
+
streams[i] = {
|
|
168
|
+
level,
|
|
169
|
+
stream: this.streams[i].stream
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
write,
|
|
175
|
+
add,
|
|
176
|
+
remove,
|
|
177
|
+
minLevel: level,
|
|
178
|
+
streams,
|
|
179
|
+
clone,
|
|
180
|
+
emit,
|
|
181
|
+
flushSync,
|
|
182
|
+
[metadata]: true
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function compareByLevel (a, b) {
|
|
188
|
+
return a.level - b.level
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function initLoopVar (length, dedupe) {
|
|
192
|
+
return dedupe ? length - 1 : 0
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function adjustLoopVar (i, dedupe) {
|
|
196
|
+
return dedupe ? i - 1 : i + 1
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function checkLoopVar (i, length, dedupe) {
|
|
200
|
+
return dedupe ? i >= 0 : i < length
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = multistream
|