appos 0.1.1-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.
Files changed (64) hide show
  1. package/build/lib/caller.js +30 -0
  2. package/build/lib/constants.js +28 -0
  3. package/build/lib/deprecations.js +8 -0
  4. package/build/lib/levels.js +241 -0
  5. package/build/lib/meta.js +3 -0
  6. package/build/lib/multistream.js +203 -0
  7. package/build/lib/proto.js +256 -0
  8. package/build/lib/redaction.js +114 -0
  9. package/build/lib/symbols.js +74 -0
  10. package/build/lib/time.js +39 -0
  11. package/build/lib/tools.js +423 -0
  12. package/build/lib/transport-stream.js +56 -0
  13. package/build/lib/transport.js +167 -0
  14. package/build/lib/worker.js +194 -0
  15. package/build/main.js +758 -754
  16. package/package.json +19 -22
  17. /package/build/{lib → exports}/adapter-factory-CLtf7vT5-CTKiMV2u.mjs +0 -0
  18. /package/build/{lib → exports}/bun-sqlite-dialect-DN7EKoIB-0pWIoG0L.mjs +0 -0
  19. /package/build/{lib → exports}/chunk-BYI67GdN.mjs +0 -0
  20. /package/build/{lib → exports}/chunk-CkKlU7xI.mjs +0 -0
  21. /package/build/{lib → exports}/client-BtuhFgvy.mjs +0 -0
  22. /package/build/{lib → exports}/client.d.ts +0 -0
  23. /package/build/{lib → exports}/client.js +0 -0
  24. /package/build/{lib → exports}/date.d.ts +0 -0
  25. /package/build/{lib → exports}/date.js +0 -0
  26. /package/build/{lib → exports}/dialect-BeMwdQoz-D41NdSow.mjs +0 -0
  27. /package/build/{lib → exports}/dist-cjs-B43A5HXv.mjs +0 -0
  28. /package/build/{lib → exports}/dist-cjs-B_wkbabY.mjs +0 -0
  29. /package/build/{lib → exports}/dist-cjs-BmbYbMhp.mjs +0 -0
  30. /package/build/{lib → exports}/dist-cjs-Cc337rwW.mjs +0 -0
  31. /package/build/{lib → exports}/dist-cjs-CgzfN8xY.mjs +0 -0
  32. /package/build/{lib → exports}/dist-cjs-DBFcizQf.mjs +0 -0
  33. /package/build/{lib → exports}/dist-cjs-DC-UL-xx.mjs +0 -0
  34. /package/build/{lib → exports}/dist-cjs-DHlTgXUO.mjs +0 -0
  35. /package/build/{lib → exports}/dist-cjs-DYAmJYzN.mjs +0 -0
  36. /package/build/{lib → exports}/dist-cjs-Ddm6Stp9.mjs +0 -0
  37. /package/build/{lib → exports}/dist-cjs-GFGBhaZg.mjs +0 -0
  38. /package/build/{lib → exports}/dist-cjs-ieCOxrOi.mjs +0 -0
  39. /package/build/{lib → exports}/dist-cjs-nbOGa7i_.mjs +0 -0
  40. /package/build/{lib → exports}/dist-cjs-pN6ekzMW.mjs +0 -0
  41. /package/build/{lib → exports}/dist-cjs-yYlQ1OiO.mjs +0 -0
  42. /package/build/{lib → exports}/esm-DPet4lFW.mjs +0 -0
  43. /package/build/{lib → exports}/event-streams-x9fP9BzF.mjs +0 -0
  44. /package/build/{lib → exports}/file-preview-dialog-Cugg8tEc.mjs +0 -0
  45. /package/build/{lib → exports}/kysely-adapter-BTWfu5rn.mjs +0 -0
  46. /package/build/{lib → exports}/magic-string.es-jZcifc5m.mjs +0 -0
  47. /package/build/{lib → exports}/memory-adapter-DiU519m9.mjs +0 -0
  48. /package/build/{lib → exports}/node-ponyfill-Dmm1SWTU.mjs +0 -0
  49. /package/build/{lib → exports}/node-sqlite-dialect-BqISUSC3-DYvTLBpY.mjs +0 -0
  50. /package/build/{lib → exports}/package-DfozRyK6.mjs +0 -0
  51. /package/build/{lib → exports}/react-dom-CPjM_WCt.mjs +0 -0
  52. /package/build/{lib → exports}/server.d.mts +0 -0
  53. /package/build/{lib → exports}/server.mjs +0 -0
  54. /package/build/{lib → exports}/sso-oidc-Qom0PEDW.mjs +0 -0
  55. /package/build/{lib → exports}/sts-CLRaHSW_.mjs +0 -0
  56. /package/build/{lib → exports}/sts-Dl7yZqX1.mjs +0 -0
  57. /package/build/{lib → exports}/test.d.mts +0 -0
  58. /package/build/{lib → exports}/test.mjs +0 -0
  59. /package/build/{lib → exports}/ui/index.d.ts +0 -0
  60. /package/build/{lib → exports}/ui/index.js +0 -0
  61. /package/build/{lib → exports}/utils.d.ts +0 -0
  62. /package/build/{lib → exports}/utils.js +0 -0
  63. /package/build/{lib → exports}/zod.d.ts +0 -0
  64. /package/build/{lib → exports}/zod.js +0 -0
@@ -0,0 +1,256 @@
1
+ 'use strict'
2
+
3
+ /* eslint no-prototype-builtins: 0 */
4
+
5
+ const { EventEmitter } = require('node:events')
6
+ const {
7
+ lsCacheSym,
8
+ levelValSym,
9
+ setLevelSym,
10
+ getLevelSym,
11
+ chindingsSym,
12
+ mixinSym,
13
+ asJsonSym,
14
+ writeSym,
15
+ mixinMergeStrategySym,
16
+ timeSym,
17
+ timeSliceIndexSym,
18
+ streamSym,
19
+ serializersSym,
20
+ formattersSym,
21
+ errorKeySym,
22
+ messageKeySym,
23
+ useOnlyCustomLevelsSym,
24
+ needsMetadataGsym,
25
+ redactFmtSym,
26
+ stringifySym,
27
+ formatOptsSym,
28
+ stringifiersSym,
29
+ msgPrefixSym,
30
+ hooksSym
31
+ } = require('./symbols')
32
+ const {
33
+ getLevel,
34
+ setLevel,
35
+ isLevelEnabled,
36
+ mappings,
37
+ initialLsCache,
38
+ genLsCache,
39
+ assertNoLevelCollisions
40
+ } = require('./levels')
41
+ const {
42
+ asChindings,
43
+ asJson,
44
+ buildFormatters,
45
+ stringify,
46
+ noop
47
+ } = require('./tools')
48
+ const {
49
+ version
50
+ } = require('./meta')
51
+ const redaction = require('./redaction')
52
+
53
+ // note: use of class is satirical
54
+ // https://github.com/pinojs/pino/pull/433#pullrequestreview-127703127
55
+ const constructor = class Pino {}
56
+ const prototype = {
57
+ constructor,
58
+ child,
59
+ bindings,
60
+ setBindings,
61
+ flush,
62
+ isLevelEnabled,
63
+ version,
64
+ get level () { return this[getLevelSym]() },
65
+ set level (lvl) { this[setLevelSym](lvl) },
66
+ get levelVal () { return this[levelValSym] },
67
+ set levelVal (n) { throw Error('levelVal is read-only') },
68
+ get msgPrefix () { return this[msgPrefixSym] },
69
+ get [Symbol.toStringTag] () { return 'Pino' },
70
+ [lsCacheSym]: initialLsCache,
71
+ [writeSym]: write,
72
+ [asJsonSym]: asJson,
73
+ [getLevelSym]: getLevel,
74
+ [setLevelSym]: setLevel
75
+ }
76
+
77
+ Object.setPrototypeOf(prototype, EventEmitter.prototype)
78
+
79
+ // exporting and consuming the prototype object using factory pattern fixes scoping issues with getters when serializing
80
+ module.exports = function () {
81
+ return Object.create(prototype)
82
+ }
83
+
84
+ const resetChildingsFormatter = bindings => bindings
85
+ function child (bindings, options) {
86
+ if (!bindings) {
87
+ throw Error('missing bindings for child Pino')
88
+ }
89
+ const serializers = this[serializersSym]
90
+ const formatters = this[formattersSym]
91
+ const instance = Object.create(this)
92
+
93
+ // If an `options` object was not supplied, we can improve
94
+ // the performance of child creation by skipping
95
+ // the checks for set options and simply return
96
+ // a baseline instance.
97
+ if (options == null) {
98
+ if (instance[formattersSym].bindings !== resetChildingsFormatter) {
99
+ instance[formattersSym] = buildFormatters(
100
+ formatters.level,
101
+ resetChildingsFormatter,
102
+ formatters.log
103
+ )
104
+ }
105
+
106
+ instance[chindingsSym] = asChindings(instance, bindings)
107
+
108
+ if (this.onChild !== noop) {
109
+ this.onChild(instance)
110
+ }
111
+
112
+ return instance
113
+ }
114
+
115
+ if (options.hasOwnProperty('serializers') === true) {
116
+ instance[serializersSym] = Object.create(null)
117
+
118
+ for (const k in serializers) {
119
+ instance[serializersSym][k] = serializers[k]
120
+ }
121
+ const parentSymbols = Object.getOwnPropertySymbols(serializers)
122
+ /* eslint no-var: off */
123
+ for (var i = 0; i < parentSymbols.length; i++) {
124
+ const ks = parentSymbols[i]
125
+ instance[serializersSym][ks] = serializers[ks]
126
+ }
127
+
128
+ for (const bk in options.serializers) {
129
+ instance[serializersSym][bk] = options.serializers[bk]
130
+ }
131
+ const bindingsSymbols = Object.getOwnPropertySymbols(options.serializers)
132
+ for (var bi = 0; bi < bindingsSymbols.length; bi++) {
133
+ const bks = bindingsSymbols[bi]
134
+ instance[serializersSym][bks] = options.serializers[bks]
135
+ }
136
+ } else instance[serializersSym] = serializers
137
+ if (options.hasOwnProperty('formatters')) {
138
+ const { level, bindings: chindings, log } = options.formatters
139
+ instance[formattersSym] = buildFormatters(
140
+ level || formatters.level,
141
+ chindings || resetChildingsFormatter,
142
+ log || formatters.log
143
+ )
144
+ } else {
145
+ instance[formattersSym] = buildFormatters(
146
+ formatters.level,
147
+ resetChildingsFormatter,
148
+ formatters.log
149
+ )
150
+ }
151
+ if (options.hasOwnProperty('customLevels') === true) {
152
+ assertNoLevelCollisions(this.levels, options.customLevels)
153
+ instance.levels = mappings(options.customLevels, instance[useOnlyCustomLevelsSym])
154
+ genLsCache(instance)
155
+ }
156
+
157
+ // redact must place before asChindings and only replace if exist
158
+ if ((typeof options.redact === 'object' && options.redact !== null) || Array.isArray(options.redact)) {
159
+ instance.redact = options.redact // replace redact directly
160
+ const stringifiers = redaction(instance.redact, stringify)
161
+ const formatOpts = { stringify: stringifiers[redactFmtSym] }
162
+ instance[stringifySym] = stringify
163
+ instance[stringifiersSym] = stringifiers
164
+ instance[formatOptsSym] = formatOpts
165
+ }
166
+
167
+ if (typeof options.msgPrefix === 'string') {
168
+ instance[msgPrefixSym] = (this[msgPrefixSym] || '') + options.msgPrefix
169
+ }
170
+
171
+ instance[chindingsSym] = asChindings(instance, bindings)
172
+ if ((options.level !== undefined && options.level !== this.level) || options.hasOwnProperty('customLevels')) {
173
+ const childLevel = options.level || this.level
174
+ instance[setLevelSym](childLevel)
175
+ }
176
+ this.onChild(instance)
177
+ return instance
178
+ }
179
+
180
+ function bindings () {
181
+ const chindings = this[chindingsSym]
182
+ const chindingsJson = `{${chindings.substr(1)}}` // at least contains ,"pid":7068,"hostname":"myMac"
183
+ const bindingsFromJson = JSON.parse(chindingsJson)
184
+ delete bindingsFromJson.pid
185
+ delete bindingsFromJson.hostname
186
+ return bindingsFromJson
187
+ }
188
+
189
+ function setBindings (newBindings) {
190
+ const chindings = asChindings(this, newBindings)
191
+ this[chindingsSym] = chindings
192
+ }
193
+
194
+ /**
195
+ * Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
196
+ * Fields from `mergeObject` have higher priority in this strategy.
197
+ *
198
+ * @param {Object} mergeObject The object a user has supplied to the logging function.
199
+ * @param {Object} mixinObject The result of the `mixin` method.
200
+ * @return {Object}
201
+ */
202
+ function defaultMixinMergeStrategy (mergeObject, mixinObject) {
203
+ return Object.assign(mixinObject, mergeObject)
204
+ }
205
+
206
+ function write (_obj, msg, num) {
207
+ const t = this[timeSym]()
208
+ const mixin = this[mixinSym]
209
+ const errorKey = this[errorKeySym]
210
+ const messageKey = this[messageKeySym]
211
+ const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy
212
+ let obj
213
+ const streamWriteHook = this[hooksSym].streamWrite
214
+
215
+ if (_obj === undefined || _obj === null) {
216
+ obj = {}
217
+ } else if (_obj instanceof Error) {
218
+ obj = { [errorKey]: _obj }
219
+ if (msg === undefined) {
220
+ msg = _obj.message
221
+ }
222
+ } else {
223
+ obj = _obj
224
+ if (msg === undefined && _obj[messageKey] === undefined && _obj[errorKey]) {
225
+ msg = _obj[errorKey].message
226
+ }
227
+ }
228
+
229
+ if (mixin) {
230
+ obj = mixinMergeStrategy(obj, mixin(obj, num, this))
231
+ }
232
+
233
+ const s = this[asJsonSym](obj, msg, num, t)
234
+
235
+ const stream = this[streamSym]
236
+ if (stream[needsMetadataGsym] === true) {
237
+ stream.lastLevel = num
238
+ stream.lastObj = obj
239
+ stream.lastMsg = msg
240
+ stream.lastTime = t.slice(this[timeSliceIndexSym])
241
+ stream.lastLogger = this // for child loggers
242
+ }
243
+ stream.write(streamWriteHook ? streamWriteHook(s) : s)
244
+ }
245
+
246
+ function flush (cb) {
247
+ if (cb != null && typeof cb !== 'function') {
248
+ throw Error('callback must be a function')
249
+ }
250
+
251
+ const stream = this[streamSym]
252
+
253
+ if (typeof stream.flush === 'function') {
254
+ stream.flush(cb || noop)
255
+ } else if (cb) cb()
256
+ }
@@ -0,0 +1,114 @@
1
+ 'use strict'
2
+
3
+ const Redact = require('@pinojs/redact')
4
+ const { redactFmtSym, wildcardFirstSym } = require('./symbols')
5
+
6
+ // Custom rx regex equivalent to fast-redact's rx
7
+ const rx = /[^.[\]]+|\[([^[\]]*?)\]/g
8
+
9
+ const CENSOR = '[Redacted]'
10
+ const strict = false // TODO should this be configurable?
11
+
12
+ function redaction (opts, serialize) {
13
+ const { paths, censor, remove } = handle(opts)
14
+
15
+ const shape = paths.reduce((o, str) => {
16
+ rx.lastIndex = 0
17
+ const first = rx.exec(str)
18
+ const next = rx.exec(str)
19
+
20
+ // ns is the top-level path segment, brackets + quoting removed.
21
+ let ns = first[1] !== undefined
22
+ ? first[1].replace(/^(?:"|'|`)(.*)(?:"|'|`)$/, '$1')
23
+ : first[0]
24
+
25
+ if (ns === '*') {
26
+ ns = wildcardFirstSym
27
+ }
28
+
29
+ // top level key:
30
+ if (next === null) {
31
+ o[ns] = null
32
+ return o
33
+ }
34
+
35
+ // path with at least two segments:
36
+ // if ns is already redacted at the top level, ignore lower level redactions
37
+ if (o[ns] === null) {
38
+ return o
39
+ }
40
+
41
+ const { index } = next
42
+ const nextPath = `${str.substr(index, str.length - 1)}`
43
+
44
+ o[ns] = o[ns] || []
45
+
46
+ // shape is a mix of paths beginning with literal values and wildcard
47
+ // paths [ "a.b.c", "*.b.z" ] should reduce to a shape of
48
+ // { "a": [ "b.c", "b.z" ], *: [ "b.z" ] }
49
+ // note: "b.z" is in both "a" and * arrays because "a" matches the wildcard.
50
+ // (* entry has wildcardFirstSym as key)
51
+ if (ns !== wildcardFirstSym && o[ns].length === 0) {
52
+ // first time ns's get all '*' redactions so far
53
+ o[ns].push(...(o[wildcardFirstSym] || []))
54
+ }
55
+
56
+ if (ns === wildcardFirstSym) {
57
+ // new * path gets added to all previously registered literal ns's.
58
+ Object.keys(o).forEach(function (k) {
59
+ if (o[k]) {
60
+ o[k].push(nextPath)
61
+ }
62
+ })
63
+ }
64
+
65
+ o[ns].push(nextPath)
66
+ return o
67
+ }, {})
68
+
69
+ // the redactor assigned to the format symbol key
70
+ // provides top level redaction for instances where
71
+ // an object is interpolated into the msg string
72
+ const result = {
73
+ [redactFmtSym]: Redact({ paths, censor, serialize, strict, remove })
74
+ }
75
+
76
+ const topCensor = (...args) => {
77
+ return typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor)
78
+ }
79
+
80
+ return [...Object.keys(shape), ...Object.getOwnPropertySymbols(shape)].reduce((o, k) => {
81
+ // top level key:
82
+ if (shape[k] === null) {
83
+ o[k] = (value) => topCensor(value, [k])
84
+ } else {
85
+ const wrappedCensor = typeof censor === 'function'
86
+ ? (value, path) => {
87
+ return censor(value, [k, ...path])
88
+ }
89
+ : censor
90
+ o[k] = Redact({
91
+ paths: shape[k],
92
+ censor: wrappedCensor,
93
+ serialize,
94
+ strict,
95
+ remove
96
+ })
97
+ }
98
+ return o
99
+ }, result)
100
+ }
101
+
102
+ function handle (opts) {
103
+ if (Array.isArray(opts)) {
104
+ opts = { paths: opts, censor: CENSOR }
105
+ return opts
106
+ }
107
+ let { paths, censor = CENSOR, remove } = opts
108
+ if (Array.isArray(paths) === false) { throw Error('pino – redact must contain an array of strings') }
109
+ if (remove === true) censor = undefined
110
+
111
+ return { paths, censor, remove }
112
+ }
113
+
114
+ module.exports = redaction
@@ -0,0 +1,74 @@
1
+ 'use strict'
2
+
3
+ const setLevelSym = Symbol('pino.setLevel')
4
+ const getLevelSym = Symbol('pino.getLevel')
5
+ const levelValSym = Symbol('pino.levelVal')
6
+ const levelCompSym = Symbol('pino.levelComp')
7
+ const useLevelLabelsSym = Symbol('pino.useLevelLabels')
8
+ const useOnlyCustomLevelsSym = Symbol('pino.useOnlyCustomLevels')
9
+ const mixinSym = Symbol('pino.mixin')
10
+
11
+ const lsCacheSym = Symbol('pino.lsCache')
12
+ const chindingsSym = Symbol('pino.chindings')
13
+
14
+ const asJsonSym = Symbol('pino.asJson')
15
+ const writeSym = Symbol('pino.write')
16
+ const redactFmtSym = Symbol('pino.redactFmt')
17
+
18
+ const timeSym = Symbol('pino.time')
19
+ const timeSliceIndexSym = Symbol('pino.timeSliceIndex')
20
+ const streamSym = Symbol('pino.stream')
21
+ const stringifySym = Symbol('pino.stringify')
22
+ const stringifySafeSym = Symbol('pino.stringifySafe')
23
+ const stringifiersSym = Symbol('pino.stringifiers')
24
+ const endSym = Symbol('pino.end')
25
+ const formatOptsSym = Symbol('pino.formatOpts')
26
+ const messageKeySym = Symbol('pino.messageKey')
27
+ const errorKeySym = Symbol('pino.errorKey')
28
+ const nestedKeySym = Symbol('pino.nestedKey')
29
+ const nestedKeyStrSym = Symbol('pino.nestedKeyStr')
30
+ const mixinMergeStrategySym = Symbol('pino.mixinMergeStrategy')
31
+ const msgPrefixSym = Symbol('pino.msgPrefix')
32
+
33
+ const wildcardFirstSym = Symbol('pino.wildcardFirst')
34
+
35
+ // public symbols, no need to use the same pino
36
+ // version for these
37
+ const serializersSym = Symbol.for('pino.serializers')
38
+ const formattersSym = Symbol.for('pino.formatters')
39
+ const hooksSym = Symbol.for('pino.hooks')
40
+ const needsMetadataGsym = Symbol.for('pino.metadata')
41
+
42
+ module.exports = {
43
+ setLevelSym,
44
+ getLevelSym,
45
+ levelValSym,
46
+ levelCompSym,
47
+ useLevelLabelsSym,
48
+ mixinSym,
49
+ lsCacheSym,
50
+ chindingsSym,
51
+ asJsonSym,
52
+ writeSym,
53
+ serializersSym,
54
+ redactFmtSym,
55
+ timeSym,
56
+ timeSliceIndexSym,
57
+ streamSym,
58
+ stringifySym,
59
+ stringifySafeSym,
60
+ stringifiersSym,
61
+ endSym,
62
+ formatOptsSym,
63
+ messageKeySym,
64
+ errorKeySym,
65
+ nestedKeySym,
66
+ wildcardFirstSym,
67
+ needsMetadataGsym,
68
+ useOnlyCustomLevelsSym,
69
+ formattersSym,
70
+ hooksSym,
71
+ nestedKeyStrSym,
72
+ mixinMergeStrategySym,
73
+ msgPrefixSym
74
+ }
@@ -0,0 +1,39 @@
1
+ 'use strict'
2
+
3
+ const nullTime = () => ''
4
+
5
+ const epochTime = () => `,"time":${Date.now()}`
6
+
7
+ const unixTime = () => `,"time":${Math.round(Date.now() / 1000.0)}`
8
+
9
+ const isoTime = () => `,"time":"${new Date(Date.now()).toISOString()}"` // using Date.now() for testability
10
+
11
+ const NS_PER_MS = 1_000_000n
12
+ const NS_PER_SEC = 1_000_000_000n
13
+
14
+ const startWallTimeNs = BigInt(Date.now()) * NS_PER_MS
15
+ const startHrTime = process.hrtime.bigint()
16
+
17
+ const isoTimeNano = () => {
18
+ const elapsedNs = process.hrtime.bigint() - startHrTime
19
+ const currentTimeNs = startWallTimeNs + elapsedNs
20
+
21
+ const secondsSinceEpoch = currentTimeNs / NS_PER_SEC
22
+ const nanosWithinSecond = currentTimeNs % NS_PER_SEC
23
+
24
+ const msSinceEpoch = Number(secondsSinceEpoch * 1000n + nanosWithinSecond / 1_000_000n)
25
+ const date = new Date(msSinceEpoch)
26
+
27
+ const year = date.getUTCFullYear()
28
+ const month = (date.getUTCMonth() + 1).toString().padStart(2, '0')
29
+ const day = date.getUTCDate().toString().padStart(2, '0')
30
+ const hours = date.getUTCHours().toString().padStart(2, '0')
31
+ const minutes = date.getUTCMinutes().toString().padStart(2, '0')
32
+ const seconds = date.getUTCSeconds().toString().padStart(2, '0')
33
+
34
+ return `,"time":"${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${nanosWithinSecond
35
+ .toString()
36
+ .padStart(9, '0')}Z"`
37
+ }
38
+
39
+ module.exports = { nullTime, epochTime, unixTime, isoTime, isoTimeNano }