@bazariodev/docket 0.0.0 → 1.0.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/CHANGELOG.md +36 -0
- package/README.md +715 -173
- package/dist/{chunk-B-SP8Od_.js → chunk-DkvWLziD.js} +3 -3
- package/dist/{chunk-B-SP8Od_.js.map → chunk-DkvWLziD.js.map} +1 -1
- package/dist/{chunk-Bvq4tF_F.cjs → chunk-ieB8yTEn.cjs} +2 -3
- package/dist/{chunk-Bvq4tF_F.cjs.map → chunk-ieB8yTEn.cjs.map} +1 -1
- package/dist/client/index.cjs +167 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +40 -0
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +165 -0
- package/dist/client/index.js.map +1 -0
- package/dist/constants.d.cts +2 -4
- package/dist/constants.d.ts +2 -4
- package/dist/export/index.cjs +39 -11
- package/dist/export/index.cjs.map +1 -1
- package/dist/export/index.js +39 -11
- package/dist/export/index.js.map +1 -1
- package/dist/history/index.cjs +21 -1187
- package/dist/history/index.cjs.map +1 -1
- package/dist/history/index.d.cts +10 -112
- package/dist/history/index.d.ts +10 -112
- package/dist/history/index.js +22 -1188
- package/dist/history/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/indexeddb/index.cjs +18 -7
- package/dist/indexeddb/index.cjs.map +1 -1
- package/dist/indexeddb/index.d.cts +19 -4
- package/dist/indexeddb/index.d.ts +19 -4
- package/dist/indexeddb/index.js +18 -8
- package/dist/indexeddb/index.js.map +1 -1
- package/dist/storage/contracts.d.cts +0 -4
- package/dist/storage/contracts.d.ts +0 -4
- package/dist/upload/constants.d.cts +17 -0
- package/dist/upload/constants.d.ts +17 -0
- package/dist/upload/index.cjs +246 -0
- package/dist/upload/index.cjs.map +1 -0
- package/dist/upload/index.d.cts +51 -0
- package/dist/upload/index.d.ts +51 -0
- package/dist/upload/index.js +244 -0
- package/dist/upload/index.js.map +1 -0
- package/package.json +25 -2
- package/dist/core/errors.d.cts +0 -8
- package/dist/core/errors.d.ts +0 -8
- package/dist/history/constants.d.cts +0 -35
- package/dist/history/constants.d.ts +0 -35
- package/dist/sip/constants.d.cts +0 -5
- package/dist/sip/constants.d.ts +0 -5
|
@@ -207,6 +207,7 @@ function createLogging(options) {
|
|
|
207
207
|
busy = wasBusy;
|
|
208
208
|
reporting = false;
|
|
209
209
|
}
|
|
210
|
+
for (const sink of options.sinks ?? []) addSink(sink);
|
|
210
211
|
const levels = createLevels({ ...options, now, scheduler: scheduler$1 }, onError);
|
|
211
212
|
|
|
212
213
|
function emit(area, scope, binding, level, message, data, bypass = false) {
|
|
@@ -352,7 +353,6 @@ function createLogging(options) {
|
|
|
352
353
|
sinks.delete(registration);
|
|
353
354
|
};
|
|
354
355
|
}
|
|
355
|
-
for (const sink of options.sinks ?? []) addSink(sink);
|
|
356
356
|
|
|
357
357
|
async function lifecycle(registrations, methods) {
|
|
358
358
|
const failures = [];
|
|
@@ -433,5 +433,5 @@ function createLogging(options) {
|
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
export { createLogging as c
|
|
437
|
-
//# sourceMappingURL=chunk-
|
|
436
|
+
export { createLogging as c };
|
|
437
|
+
//# sourceMappingURL=chunk-DkvWLziD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-B-SP8Od_.js","sources":["../src/core/errors.js","../src/core/levels.js","../src/core/hub.js"],"sourcesContent":["import { LOGGING_ERROR_CODES } from './constants.js';\n\nexport const LOGGING_ERRORS = /* @__PURE__ */ Object.freeze({\n [LOGGING_ERROR_CODES.RECURSIVE_LOGGING]: 'Recursive logging is rejected',\n [LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT]:\n 'Root logger cache exceeds 1000 pairs',\n [LOGGING_ERROR_CODES.STOPPED]: 'Logging is stopped',\n});\n\nexport function loggingError(code) {\n return Object.assign(new Error(LOGGING_ERRORS[code]), { code });\n}\n","import { assertLevel, define, levelRank, positive } from './common.js';\nimport { LOGGING_ERROR_SOURCES, LOGGING_LIMITS } from './constants.js';\n\nexport function createLevels(options, reportError) {\n const { now, scheduler, levelStorage, areas } = options;\n const maxDuration = positive(\n options.maxOverrideMs ?? LOGGING_LIMITS.DEFAULT_LEVEL_OVERRIDE_MS,\n 'maxOverrideMs',\n );\n const states = new Map();\n let stopped = false;\n for (const { id, level = 'info' } of areas) {\n assertLevel(level);\n if (typeof id !== 'string' || !id || states.has(id))\n throw new TypeError('Areas must have unique non-empty IDs');\n states.set(id, {\n level,\n defaultLevel: level,\n rank: levelRank(level),\n until: undefined,\n timer: undefined,\n });\n }\n const requireArea = (area) => {\n const state = states.get(area);\n if (!state) throw new TypeError('Unknown log area');\n return state;\n };\n\n function save() {\n if (!levelStorage || stopped) return;\n const overrides = {};\n for (const [id, state] of states)\n if (state.until)\n define(overrides, id, { level: state.level, until: state.until });\n try {\n levelStorage.storage.setItem(levelStorage.key, JSON.stringify(overrides));\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n\n function reset(state) {\n scheduler.clearTimeout(state.timer);\n state.timer = undefined;\n state.until = undefined;\n state.level = state.defaultLevel;\n state.rank = levelRank(state.level);\n }\n\n function apply(state, level, until) {\n reset(state);\n state.level = level;\n state.rank = levelRank(level);\n state.until = until;\n state.timer = scheduler.setTimeout(\n () => {\n if (stopped) return;\n if (until > now()) {\n apply(state, level, until);\n return;\n }\n reset(state);\n save();\n },\n Math.min(LOGGING_LIMITS.MAX_TIMER_DELAY_MS, Math.max(0, until - now())),\n );\n }\n\n function reloadLevels() {\n if (stopped) return;\n for (const state of states.values()) reset(state);\n if (!levelStorage) return;\n try {\n const saved = JSON.parse(\n levelStorage.storage.getItem(levelStorage.key) ?? '{}',\n );\n if (!saved || typeof saved !== 'object') return;\n const time = now();\n for (const [id, state] of states) {\n const override = Object.hasOwn(saved, id) && saved[id];\n if (\n override &&\n levelRank(override.level) >= 0 &&\n Number.isFinite(override.until) &&\n override.until > time\n )\n apply(\n state,\n override.level,\n Math.min(override.until, time + maxDuration),\n );\n }\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n reloadLevels();\n return {\n requireArea,\n enabled(area, level) {\n const state = requireArea(area);\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n return levelRank(level) >= state.rank;\n },\n\n setLevel(area, level, { durationMs = maxDuration } = {}) {\n assertLevel(level);\n positive(durationMs, 'durationMs');\n const state = requireArea(area);\n if (stopped) return;\n apply(state, level, now() + Math.min(durationMs, maxDuration));\n save();\n },\n\n resetLevel(area) {\n if (stopped) return;\n if (area !== undefined) reset(requireArea(area));\n else for (const state of states.values()) reset(state);\n save();\n },\n reloadLevels,\n getLevels() {\n const result = {};\n for (const [id, state] of states) {\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n define(\n result,\n id,\n Object.freeze({\n level: state.level,\n defaultLevel: state.defaultLevel,\n ...(state.until ? { until: state.until } : {}),\n }),\n );\n }\n return Object.freeze(result);\n },\n\n stop() {\n stopped = true;\n for (const state of states.values()) scheduler.clearTimeout(state.timer);\n },\n };\n}\n","import {\n assertStormLimit,\n copyBindings,\n scheduler as hostScheduler,\n randomHex,\n report,\n resolveLimits,\n} from './common.js';\nimport {\n LEVELS,\n LOGGING_ERROR_CODES,\n LOGGING_ERROR_SOURCES,\n LOGGING_LIMITS,\n} from './constants.js';\nimport { ownRecord } from './conversion.js';\nimport { loggingError } from './errors.js';\nimport { createLevels } from './levels.js';\n\nexport function createLogging(options) {\n if (\n !Array.isArray(options?.areas) ||\n !options.redactor ||\n typeof options.redactor.redact !== 'function'\n )\n throw new TypeError('Areas and an explicit redactor are required');\n const {\n redactor,\n now = Date.now,\n monotonicNow = () => globalThis.performance?.now() ?? Date.now(),\n scheduler = hostScheduler,\n stormLimit = LOGGING_LIMITS.DEFAULT_STORM_LIMIT,\n } = options;\n const limits = resolveLimits(redactor.limits);\n if (\n !redactor.limits ||\n Object.keys(limits).some((key) => !Object.hasOwn(redactor.limits, key))\n )\n throw new TypeError('Redactor limits are required');\n assertStormLimit(stormLimit);\n const runId = options.createRunId?.() ?? randomHex(16);\n if (typeof runId !== 'string' || !runId)\n throw new TypeError('Invalid run ID');\n const sinks = new Set();\n const roots = new Map();\n const storms = new Map();\n let context = copyBindings(options.context);\n let seq = 0;\n let closed = false;\n let busy = false;\n let scopeReported = false;\n let reporting = false;\n let stormTimer;\n let stopPromise;\n\n function onError(error, source) {\n if (reporting) return;\n reporting = true;\n const wasBusy = busy;\n busy = true;\n report(options.onError, error, source);\n busy = wasBusy;\n reporting = false;\n }\n const levels = createLevels({ ...options, now, scheduler }, onError);\n\n function emit(area, scope, binding, level, message, data, bypass = false) {\n try {\n if (busy) {\n onError(\n loggingError(LOGGING_ERROR_CODES.RECURSIVE_LOGGING),\n LOGGING_ERROR_SOURCES.REENTRY,\n );\n return;\n }\n if (\n closed ||\n options.isActive?.() === false ||\n sinks.size === 0 ||\n (!bypass && !levels.enabled(area, level))\n )\n return;\n if (!bypass && stormLimit !== false) {\n const key = JSON.stringify([area, scope]);\n let counter = storms.get(key);\n if (!counter) {\n const cacheKey =\n storms.size < LOGGING_LIMITS.STORM_SCOPE_PAIRS ? key : 'overflow';\n counter = storms.get(cacheKey);\n if (!counter) {\n counter = {\n area,\n scope,\n start: monotonicNow(),\n count: 0,\n dropped: 0,\n };\n storms.set(cacheKey, counter);\n }\n }\n const time = monotonicNow();\n if (\n time - counter.start >= LOGGING_LIMITS.STORM_WINDOW_MS ||\n time < counter.start\n ) {\n counter.start = time;\n counter.count = 0;\n }\n if (counter.count++ >= stormLimit) {\n counter.dropped++;\n if (stormTimer === undefined)\n stormTimer = scheduler.setTimeout(\n summarize,\n LOGGING_LIMITS.STORM_SUMMARY_DELAY_MS,\n );\n return;\n }\n }\n const registrations = Array.from(sinks);\n busy = true;\n try {\n let value;\n try {\n value = typeof data === 'function' ? data() : data;\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n return;\n }\n if (options.isActive?.() === false || sinks.size === 0) return;\n let record;\n try {\n record = ownRecord(\n redactor.redact({\n runId,\n seq: ++seq,\n at: now(),\n area,\n scope,\n level,\n message,\n context: { ...context, ...binding },\n data: value,\n }),\n limits,\n );\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.REDACTOR);\n return;\n }\n if (options.isActive?.() === false) return;\n for (const registration of registrations) {\n if (options.isActive?.() === false || !sinks.has(registration))\n continue;\n try {\n registration.sink.write(record);\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }\n } finally {\n busy = false;\n }\n } catch (error) {\n busy = false;\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n }\n }\n\n function summarize() {\n stormTimer = undefined;\n for (const counter of storms.values()) {\n if (!counter.dropped) continue;\n const dropped = counter.dropped;\n counter.dropped = 0;\n emit(\n counter.area,\n counter.scope,\n {},\n 'warn',\n 'logging.suppressed',\n { scope: counter.scope, dropped },\n true,\n );\n }\n }\n\n function logger(area, scope, binding = {}) {\n const result = {};\n for (const level of Object.values(LEVELS))\n result[level] = (message, data) =>\n emit(area, scope, binding, level, message, data);\n result.child = ({\n scope: childScope = scope,\n context: childContext = {},\n } = {}) =>\n logger(area, childScope, { ...binding, ...copyBindings(childContext) });\n return Object.freeze(result);\n }\n\n function addSink(sink) {\n if (!sink || typeof sink.write !== 'function')\n throw new TypeError('A sink must have write');\n if (closed) throw loggingError(LOGGING_ERROR_CODES.STOPPED);\n const registration = { sink };\n sinks.add(registration);\n return () => {\n sinks.delete(registration);\n };\n }\n for (const sink of options.sinks ?? []) addSink(sink);\n\n async function lifecycle(registrations, methods) {\n const failures = [];\n for (const method of methods) {\n await Promise.all(\n registrations.map(async ({ sink }) => {\n try {\n const previous = busy;\n busy = true;\n let result;\n try {\n result = sink[method]?.();\n } finally {\n busy = previous;\n }\n await result;\n } catch (error) {\n failures.push(error);\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }),\n );\n }\n if (failures.length)\n throw new AggregateError(failures, 'Logging lifecycle failed');\n }\n return Object.freeze({\n runId,\n getLogger(area, scope) {\n levels.requireArea(area);\n if (typeof scope !== 'string')\n throw new TypeError('Scope must be a string');\n const key = JSON.stringify([area, scope]);\n const cached = roots.get(key);\n if (cached) return cached;\n const created = logger(area, scope);\n if (roots.size < LOGGING_LIMITS.ROOT_LOGGER_CACHE_PAIRS) {\n roots.set(key, created);\n return created;\n }\n if (!scopeReported) {\n scopeReported = true;\n onError(\n loggingError(LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT),\n LOGGING_ERROR_SOURCES.SCOPE,\n );\n }\n return created;\n },\n\n setContext(values) {\n context = { ...context, ...copyBindings(values) };\n for (const key of Object.keys(context))\n if (context[key] === undefined) delete context[key];\n },\n setLevel: levels.setLevel,\n resetLevel: levels.resetLevel,\n reloadLevels: levels.reloadLevels,\n getLevels: levels.getLevels,\n addSink,\n flush() {\n const registrations = Array.from(sinks);\n return Promise.resolve().then(() => lifecycle(registrations, ['flush']));\n },\n\n stop() {\n if (!stopPromise) {\n closed = true;\n levels.stop();\n scheduler.clearTimeout(stormTimer);\n const registrations = Array.from(sinks);\n stopPromise = Promise.resolve().then(() =>\n lifecycle(registrations, ['flush', 'stop']),\n );\n }\n return stopPromise;\n },\n });\n}\n"],"names":["scheduler","hostScheduler"],"mappings":";;;;AAEO,MAAM,cAAc,mBAAmB,MAAM,CAAC,MAAM,CAAC;AAC5D,EAAE,CAAC,mBAAmB,CAAC,iBAAiB,GAAG,+BAA+B;AAC1E,EAAE,CAAC,mBAAmB,CAAC,uBAAuB;AAC9C,IAAI,sCAAsC;AAC1C,EAAE,CAAC,mBAAmB,CAAC,OAAO,GAAG,oBAAoB;AACrD,CAAC,CAAC;;AAEK,SAAS,YAAY,CAAC,IAAI,EAAE;AACnC,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,EAAE,CAAC,IAAI,CAAC;AAC7C,UAAU,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,SAAS;AACT,MAAM;AACN,MAAM,OAAO,WAAW;AACxB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"chunk-DkvWLziD.js","sources":["../src/core/errors.js","../src/core/levels.js","../src/core/hub.js"],"sourcesContent":["import { LOGGING_ERROR_CODES } from './constants.js';\n\nexport const LOGGING_ERRORS = /* @__PURE__ */ Object.freeze({\n [LOGGING_ERROR_CODES.RECURSIVE_LOGGING]: 'Recursive logging is rejected',\n [LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT]:\n 'Root logger cache exceeds 1000 pairs',\n [LOGGING_ERROR_CODES.STOPPED]: 'Logging is stopped',\n});\n\nexport function loggingError(code) {\n return Object.assign(new Error(LOGGING_ERRORS[code]), { code });\n}\n","import { assertLevel, define, levelRank, positive } from './common.js';\nimport { LOGGING_ERROR_SOURCES, LOGGING_LIMITS } from './constants.js';\n\nexport function createLevels(options, reportError) {\n const { now, scheduler, levelStorage, areas } = options;\n const maxDuration = positive(\n options.maxOverrideMs ?? LOGGING_LIMITS.DEFAULT_LEVEL_OVERRIDE_MS,\n 'maxOverrideMs',\n );\n const states = new Map();\n let stopped = false;\n for (const { id, level = 'info' } of areas) {\n assertLevel(level);\n if (typeof id !== 'string' || !id || states.has(id))\n throw new TypeError('Areas must have unique non-empty IDs');\n states.set(id, {\n level,\n defaultLevel: level,\n rank: levelRank(level),\n until: undefined,\n timer: undefined,\n });\n }\n const requireArea = (area) => {\n const state = states.get(area);\n if (!state) throw new TypeError('Unknown log area');\n return state;\n };\n\n function save() {\n if (!levelStorage || stopped) return;\n const overrides = {};\n for (const [id, state] of states)\n if (state.until)\n define(overrides, id, { level: state.level, until: state.until });\n try {\n levelStorage.storage.setItem(levelStorage.key, JSON.stringify(overrides));\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n\n function reset(state) {\n scheduler.clearTimeout(state.timer);\n state.timer = undefined;\n state.until = undefined;\n state.level = state.defaultLevel;\n state.rank = levelRank(state.level);\n }\n\n function apply(state, level, until) {\n reset(state);\n state.level = level;\n state.rank = levelRank(level);\n state.until = until;\n state.timer = scheduler.setTimeout(\n () => {\n if (stopped) return;\n if (until > now()) {\n apply(state, level, until);\n return;\n }\n reset(state);\n save();\n },\n Math.min(LOGGING_LIMITS.MAX_TIMER_DELAY_MS, Math.max(0, until - now())),\n );\n }\n\n function reloadLevels() {\n if (stopped) return;\n for (const state of states.values()) reset(state);\n if (!levelStorage) return;\n try {\n const saved = JSON.parse(\n levelStorage.storage.getItem(levelStorage.key) ?? '{}',\n );\n if (!saved || typeof saved !== 'object') return;\n const time = now();\n for (const [id, state] of states) {\n const override = Object.hasOwn(saved, id) && saved[id];\n if (\n override &&\n levelRank(override.level) >= 0 &&\n Number.isFinite(override.until) &&\n override.until > time\n )\n apply(\n state,\n override.level,\n Math.min(override.until, time + maxDuration),\n );\n }\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n reloadLevels();\n return {\n requireArea,\n enabled(area, level) {\n const state = requireArea(area);\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n return levelRank(level) >= state.rank;\n },\n\n setLevel(area, level, { durationMs = maxDuration } = {}) {\n assertLevel(level);\n positive(durationMs, 'durationMs');\n const state = requireArea(area);\n if (stopped) return;\n apply(state, level, now() + Math.min(durationMs, maxDuration));\n save();\n },\n\n resetLevel(area) {\n if (stopped) return;\n if (area !== undefined) reset(requireArea(area));\n else for (const state of states.values()) reset(state);\n save();\n },\n reloadLevels,\n getLevels() {\n const result = {};\n for (const [id, state] of states) {\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n define(\n result,\n id,\n Object.freeze({\n level: state.level,\n defaultLevel: state.defaultLevel,\n ...(state.until ? { until: state.until } : {}),\n }),\n );\n }\n return Object.freeze(result);\n },\n\n stop() {\n stopped = true;\n for (const state of states.values()) scheduler.clearTimeout(state.timer);\n },\n };\n}\n","import {\n assertStormLimit,\n copyBindings,\n scheduler as hostScheduler,\n randomHex,\n report,\n resolveLimits,\n} from './common.js';\nimport {\n LEVELS,\n LOGGING_ERROR_CODES,\n LOGGING_ERROR_SOURCES,\n LOGGING_LIMITS,\n} from './constants.js';\nimport { ownRecord } from './conversion.js';\nimport { loggingError } from './errors.js';\nimport { createLevels } from './levels.js';\n\nexport function createLogging(options) {\n if (\n !Array.isArray(options?.areas) ||\n !options.redactor ||\n typeof options.redactor.redact !== 'function'\n )\n throw new TypeError('Areas and an explicit redactor are required');\n const {\n redactor,\n now = Date.now,\n monotonicNow = () => globalThis.performance?.now() ?? Date.now(),\n scheduler = hostScheduler,\n stormLimit = LOGGING_LIMITS.DEFAULT_STORM_LIMIT,\n } = options;\n const limits = resolveLimits(redactor.limits);\n if (\n !redactor.limits ||\n Object.keys(limits).some((key) => !Object.hasOwn(redactor.limits, key))\n )\n throw new TypeError('Redactor limits are required');\n assertStormLimit(stormLimit);\n const runId = options.createRunId?.() ?? randomHex(16);\n if (typeof runId !== 'string' || !runId)\n throw new TypeError('Invalid run ID');\n const sinks = new Set();\n const roots = new Map();\n const storms = new Map();\n let context = copyBindings(options.context);\n let seq = 0;\n let closed = false;\n let busy = false;\n let scopeReported = false;\n let reporting = false;\n let stormTimer;\n let stopPromise;\n\n function onError(error, source) {\n if (reporting) return;\n reporting = true;\n const wasBusy = busy;\n busy = true;\n report(options.onError, error, source);\n busy = wasBusy;\n reporting = false;\n }\n for (const sink of options.sinks ?? []) addSink(sink);\n const levels = createLevels({ ...options, now, scheduler }, onError);\n\n function emit(area, scope, binding, level, message, data, bypass = false) {\n try {\n if (busy) {\n onError(\n loggingError(LOGGING_ERROR_CODES.RECURSIVE_LOGGING),\n LOGGING_ERROR_SOURCES.REENTRY,\n );\n return;\n }\n if (\n closed ||\n options.isActive?.() === false ||\n sinks.size === 0 ||\n (!bypass && !levels.enabled(area, level))\n )\n return;\n if (!bypass && stormLimit !== false) {\n const key = JSON.stringify([area, scope]);\n let counter = storms.get(key);\n if (!counter) {\n const cacheKey =\n storms.size < LOGGING_LIMITS.STORM_SCOPE_PAIRS ? key : 'overflow';\n counter = storms.get(cacheKey);\n if (!counter) {\n counter = {\n area,\n scope,\n start: monotonicNow(),\n count: 0,\n dropped: 0,\n };\n storms.set(cacheKey, counter);\n }\n }\n const time = monotonicNow();\n if (\n time - counter.start >= LOGGING_LIMITS.STORM_WINDOW_MS ||\n time < counter.start\n ) {\n counter.start = time;\n counter.count = 0;\n }\n if (counter.count++ >= stormLimit) {\n counter.dropped++;\n if (stormTimer === undefined)\n stormTimer = scheduler.setTimeout(\n summarize,\n LOGGING_LIMITS.STORM_SUMMARY_DELAY_MS,\n );\n return;\n }\n }\n const registrations = Array.from(sinks);\n busy = true;\n try {\n let value;\n try {\n value = typeof data === 'function' ? data() : data;\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n return;\n }\n if (options.isActive?.() === false || sinks.size === 0) return;\n let record;\n try {\n record = ownRecord(\n redactor.redact({\n runId,\n seq: ++seq,\n at: now(),\n area,\n scope,\n level,\n message,\n context: { ...context, ...binding },\n data: value,\n }),\n limits,\n );\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.REDACTOR);\n return;\n }\n if (options.isActive?.() === false) return;\n for (const registration of registrations) {\n if (options.isActive?.() === false || !sinks.has(registration))\n continue;\n try {\n registration.sink.write(record);\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }\n } finally {\n busy = false;\n }\n } catch (error) {\n busy = false;\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n }\n }\n\n function summarize() {\n stormTimer = undefined;\n for (const counter of storms.values()) {\n if (!counter.dropped) continue;\n const dropped = counter.dropped;\n counter.dropped = 0;\n emit(\n counter.area,\n counter.scope,\n {},\n 'warn',\n 'logging.suppressed',\n { scope: counter.scope, dropped },\n true,\n );\n }\n }\n\n function logger(area, scope, binding = {}) {\n const result = {};\n for (const level of Object.values(LEVELS))\n result[level] = (message, data) =>\n emit(area, scope, binding, level, message, data);\n result.child = ({\n scope: childScope = scope,\n context: childContext = {},\n } = {}) =>\n logger(area, childScope, { ...binding, ...copyBindings(childContext) });\n return Object.freeze(result);\n }\n\n function addSink(sink) {\n if (!sink || typeof sink.write !== 'function')\n throw new TypeError('A sink must have write');\n if (closed) throw loggingError(LOGGING_ERROR_CODES.STOPPED);\n const registration = { sink };\n sinks.add(registration);\n return () => {\n sinks.delete(registration);\n };\n }\n\n async function lifecycle(registrations, methods) {\n const failures = [];\n for (const method of methods) {\n await Promise.all(\n registrations.map(async ({ sink }) => {\n try {\n const previous = busy;\n busy = true;\n let result;\n try {\n result = sink[method]?.();\n } finally {\n busy = previous;\n }\n await result;\n } catch (error) {\n failures.push(error);\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }),\n );\n }\n if (failures.length)\n throw new AggregateError(failures, 'Logging lifecycle failed');\n }\n return Object.freeze({\n runId,\n getLogger(area, scope) {\n levels.requireArea(area);\n if (typeof scope !== 'string')\n throw new TypeError('Scope must be a string');\n const key = JSON.stringify([area, scope]);\n const cached = roots.get(key);\n if (cached) return cached;\n const created = logger(area, scope);\n if (roots.size < LOGGING_LIMITS.ROOT_LOGGER_CACHE_PAIRS) {\n roots.set(key, created);\n return created;\n }\n if (!scopeReported) {\n scopeReported = true;\n onError(\n loggingError(LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT),\n LOGGING_ERROR_SOURCES.SCOPE,\n );\n }\n return created;\n },\n\n setContext(values) {\n context = { ...context, ...copyBindings(values) };\n for (const key of Object.keys(context))\n if (context[key] === undefined) delete context[key];\n },\n setLevel: levels.setLevel,\n resetLevel: levels.resetLevel,\n reloadLevels: levels.reloadLevels,\n getLevels: levels.getLevels,\n addSink,\n flush() {\n const registrations = Array.from(sinks);\n return Promise.resolve().then(() => lifecycle(registrations, ['flush']));\n },\n\n stop() {\n if (!stopPromise) {\n closed = true;\n levels.stop();\n scheduler.clearTimeout(stormTimer);\n const registrations = Array.from(sinks);\n stopPromise = Promise.resolve().then(() =>\n lifecycle(registrations, ['flush', 'stop']),\n );\n }\n return stopPromise;\n },\n });\n}\n"],"names":["scheduler","hostScheduler"],"mappings":";;;;AAEO,MAAM,cAAc,mBAAmB,MAAM,CAAC,MAAM,CAAC;AAC5D,EAAE,CAAC,mBAAmB,CAAC,iBAAiB,GAAG,+BAA+B;AAC1E,EAAE,CAAC,mBAAmB,CAAC,uBAAuB;AAC9C,IAAI,sCAAsC;AAC1C,EAAE,CAAC,mBAAmB,CAAC,OAAO,GAAG,oBAAoB;AACrD,CAAC,CAAC;;AAEK,SAAS,YAAY,CAAC,IAAI,EAAE;AACnC,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC;AACjE;;ACRO,SAAS,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE;AACnD,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,OAAO;AACzD,EAAE,MAAM,WAAW,GAAG,QAAQ;AAC9B,IAAI,OAAO,CAAC,aAAa,IAAI,cAAc,CAAC,yBAAyB;AACrE,IAAI,eAAe;AACnB,GAAG;AACH,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE;AAC1B,EAAE,IAAI,OAAO,GAAG,KAAK;AACrB,EAAE,KAAK,MAAM,EAAE,EAAE,EAAE,KAAK,GAAG,MAAM,EAAE,IAAI,KAAK,EAAE;AAC9C,IAAI,WAAW,CAAC,KAAK,CAAC;AACtB,IAAI,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AACvD,MAAM,MAAM,IAAI,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AACX,IAAI,KAAK,GAAG;AACZ,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7C,MAAM,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9E,IAAI,CAAC;;AAEL,IAAI,IAAI,GAAG;AACX,MAAM,IAAI,CAAC,WAAW,EAAE;AACxB,QAAQ,MAAM,GAAG,IAAI;AACrB,QAAQ,MAAM,CAAC,IAAI,EAAE;AACrB,QAAQA,WAAS,CAAC,YAAY,CAAC,UAAU,CAAC;AAC1C,QAAQ,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC/C,QAAQ,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;AAC7C,UAAU,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,SAAS;AACT,MAAM;AACN,MAAM,OAAO,WAAW;AACxB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;"}
|
|
@@ -209,6 +209,7 @@ function createLogging(options) {
|
|
|
209
209
|
busy = wasBusy;
|
|
210
210
|
reporting = false;
|
|
211
211
|
}
|
|
212
|
+
for (const sink of options.sinks ?? []) addSink(sink);
|
|
212
213
|
const levels = createLevels({ ...options, now, scheduler }, onError);
|
|
213
214
|
|
|
214
215
|
function emit(area, scope, binding, level, message, data, bypass = false) {
|
|
@@ -354,7 +355,6 @@ function createLogging(options) {
|
|
|
354
355
|
sinks.delete(registration);
|
|
355
356
|
};
|
|
356
357
|
}
|
|
357
|
-
for (const sink of options.sinks ?? []) addSink(sink);
|
|
358
358
|
|
|
359
359
|
async function lifecycle(registrations, methods) {
|
|
360
360
|
const failures = [];
|
|
@@ -436,5 +436,4 @@ function createLogging(options) {
|
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
exports.createLogging = createLogging;
|
|
439
|
-
|
|
440
|
-
//# sourceMappingURL=chunk-Bvq4tF_F.cjs.map
|
|
439
|
+
//# sourceMappingURL=chunk-ieB8yTEn.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-Bvq4tF_F.cjs","sources":["../src/core/errors.js","../src/core/levels.js","../src/core/hub.js"],"sourcesContent":["import { LOGGING_ERROR_CODES } from './constants.js';\n\nexport const LOGGING_ERRORS = /* @__PURE__ */ Object.freeze({\n [LOGGING_ERROR_CODES.RECURSIVE_LOGGING]: 'Recursive logging is rejected',\n [LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT]:\n 'Root logger cache exceeds 1000 pairs',\n [LOGGING_ERROR_CODES.STOPPED]: 'Logging is stopped',\n});\n\nexport function loggingError(code) {\n return Object.assign(new Error(LOGGING_ERRORS[code]), { code });\n}\n","import { assertLevel, define, levelRank, positive } from './common.js';\nimport { LOGGING_ERROR_SOURCES, LOGGING_LIMITS } from './constants.js';\n\nexport function createLevels(options, reportError) {\n const { now, scheduler, levelStorage, areas } = options;\n const maxDuration = positive(\n options.maxOverrideMs ?? LOGGING_LIMITS.DEFAULT_LEVEL_OVERRIDE_MS,\n 'maxOverrideMs',\n );\n const states = new Map();\n let stopped = false;\n for (const { id, level = 'info' } of areas) {\n assertLevel(level);\n if (typeof id !== 'string' || !id || states.has(id))\n throw new TypeError('Areas must have unique non-empty IDs');\n states.set(id, {\n level,\n defaultLevel: level,\n rank: levelRank(level),\n until: undefined,\n timer: undefined,\n });\n }\n const requireArea = (area) => {\n const state = states.get(area);\n if (!state) throw new TypeError('Unknown log area');\n return state;\n };\n\n function save() {\n if (!levelStorage || stopped) return;\n const overrides = {};\n for (const [id, state] of states)\n if (state.until)\n define(overrides, id, { level: state.level, until: state.until });\n try {\n levelStorage.storage.setItem(levelStorage.key, JSON.stringify(overrides));\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n\n function reset(state) {\n scheduler.clearTimeout(state.timer);\n state.timer = undefined;\n state.until = undefined;\n state.level = state.defaultLevel;\n state.rank = levelRank(state.level);\n }\n\n function apply(state, level, until) {\n reset(state);\n state.level = level;\n state.rank = levelRank(level);\n state.until = until;\n state.timer = scheduler.setTimeout(\n () => {\n if (stopped) return;\n if (until > now()) {\n apply(state, level, until);\n return;\n }\n reset(state);\n save();\n },\n Math.min(LOGGING_LIMITS.MAX_TIMER_DELAY_MS, Math.max(0, until - now())),\n );\n }\n\n function reloadLevels() {\n if (stopped) return;\n for (const state of states.values()) reset(state);\n if (!levelStorage) return;\n try {\n const saved = JSON.parse(\n levelStorage.storage.getItem(levelStorage.key) ?? '{}',\n );\n if (!saved || typeof saved !== 'object') return;\n const time = now();\n for (const [id, state] of states) {\n const override = Object.hasOwn(saved, id) && saved[id];\n if (\n override &&\n levelRank(override.level) >= 0 &&\n Number.isFinite(override.until) &&\n override.until > time\n )\n apply(\n state,\n override.level,\n Math.min(override.until, time + maxDuration),\n );\n }\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n reloadLevels();\n return {\n requireArea,\n enabled(area, level) {\n const state = requireArea(area);\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n return levelRank(level) >= state.rank;\n },\n\n setLevel(area, level, { durationMs = maxDuration } = {}) {\n assertLevel(level);\n positive(durationMs, 'durationMs');\n const state = requireArea(area);\n if (stopped) return;\n apply(state, level, now() + Math.min(durationMs, maxDuration));\n save();\n },\n\n resetLevel(area) {\n if (stopped) return;\n if (area !== undefined) reset(requireArea(area));\n else for (const state of states.values()) reset(state);\n save();\n },\n reloadLevels,\n getLevels() {\n const result = {};\n for (const [id, state] of states) {\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n define(\n result,\n id,\n Object.freeze({\n level: state.level,\n defaultLevel: state.defaultLevel,\n ...(state.until ? { until: state.until } : {}),\n }),\n );\n }\n return Object.freeze(result);\n },\n\n stop() {\n stopped = true;\n for (const state of states.values()) scheduler.clearTimeout(state.timer);\n },\n };\n}\n","import {\n assertStormLimit,\n copyBindings,\n scheduler as hostScheduler,\n randomHex,\n report,\n resolveLimits,\n} from './common.js';\nimport {\n LEVELS,\n LOGGING_ERROR_CODES,\n LOGGING_ERROR_SOURCES,\n LOGGING_LIMITS,\n} from './constants.js';\nimport { ownRecord } from './conversion.js';\nimport { loggingError } from './errors.js';\nimport { createLevels } from './levels.js';\n\nexport function createLogging(options) {\n if (\n !Array.isArray(options?.areas) ||\n !options.redactor ||\n typeof options.redactor.redact !== 'function'\n )\n throw new TypeError('Areas and an explicit redactor are required');\n const {\n redactor,\n now = Date.now,\n monotonicNow = () => globalThis.performance?.now() ?? Date.now(),\n scheduler = hostScheduler,\n stormLimit = LOGGING_LIMITS.DEFAULT_STORM_LIMIT,\n } = options;\n const limits = resolveLimits(redactor.limits);\n if (\n !redactor.limits ||\n Object.keys(limits).some((key) => !Object.hasOwn(redactor.limits, key))\n )\n throw new TypeError('Redactor limits are required');\n assertStormLimit(stormLimit);\n const runId = options.createRunId?.() ?? randomHex(16);\n if (typeof runId !== 'string' || !runId)\n throw new TypeError('Invalid run ID');\n const sinks = new Set();\n const roots = new Map();\n const storms = new Map();\n let context = copyBindings(options.context);\n let seq = 0;\n let closed = false;\n let busy = false;\n let scopeReported = false;\n let reporting = false;\n let stormTimer;\n let stopPromise;\n\n function onError(error, source) {\n if (reporting) return;\n reporting = true;\n const wasBusy = busy;\n busy = true;\n report(options.onError, error, source);\n busy = wasBusy;\n reporting = false;\n }\n const levels = createLevels({ ...options, now, scheduler }, onError);\n\n function emit(area, scope, binding, level, message, data, bypass = false) {\n try {\n if (busy) {\n onError(\n loggingError(LOGGING_ERROR_CODES.RECURSIVE_LOGGING),\n LOGGING_ERROR_SOURCES.REENTRY,\n );\n return;\n }\n if (\n closed ||\n options.isActive?.() === false ||\n sinks.size === 0 ||\n (!bypass && !levels.enabled(area, level))\n )\n return;\n if (!bypass && stormLimit !== false) {\n const key = JSON.stringify([area, scope]);\n let counter = storms.get(key);\n if (!counter) {\n const cacheKey =\n storms.size < LOGGING_LIMITS.STORM_SCOPE_PAIRS ? key : 'overflow';\n counter = storms.get(cacheKey);\n if (!counter) {\n counter = {\n area,\n scope,\n start: monotonicNow(),\n count: 0,\n dropped: 0,\n };\n storms.set(cacheKey, counter);\n }\n }\n const time = monotonicNow();\n if (\n time - counter.start >= LOGGING_LIMITS.STORM_WINDOW_MS ||\n time < counter.start\n ) {\n counter.start = time;\n counter.count = 0;\n }\n if (counter.count++ >= stormLimit) {\n counter.dropped++;\n if (stormTimer === undefined)\n stormTimer = scheduler.setTimeout(\n summarize,\n LOGGING_LIMITS.STORM_SUMMARY_DELAY_MS,\n );\n return;\n }\n }\n const registrations = Array.from(sinks);\n busy = true;\n try {\n let value;\n try {\n value = typeof data === 'function' ? data() : data;\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n return;\n }\n if (options.isActive?.() === false || sinks.size === 0) return;\n let record;\n try {\n record = ownRecord(\n redactor.redact({\n runId,\n seq: ++seq,\n at: now(),\n area,\n scope,\n level,\n message,\n context: { ...context, ...binding },\n data: value,\n }),\n limits,\n );\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.REDACTOR);\n return;\n }\n if (options.isActive?.() === false) return;\n for (const registration of registrations) {\n if (options.isActive?.() === false || !sinks.has(registration))\n continue;\n try {\n registration.sink.write(record);\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }\n } finally {\n busy = false;\n }\n } catch (error) {\n busy = false;\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n }\n }\n\n function summarize() {\n stormTimer = undefined;\n for (const counter of storms.values()) {\n if (!counter.dropped) continue;\n const dropped = counter.dropped;\n counter.dropped = 0;\n emit(\n counter.area,\n counter.scope,\n {},\n 'warn',\n 'logging.suppressed',\n { scope: counter.scope, dropped },\n true,\n );\n }\n }\n\n function logger(area, scope, binding = {}) {\n const result = {};\n for (const level of Object.values(LEVELS))\n result[level] = (message, data) =>\n emit(area, scope, binding, level, message, data);\n result.child = ({\n scope: childScope = scope,\n context: childContext = {},\n } = {}) =>\n logger(area, childScope, { ...binding, ...copyBindings(childContext) });\n return Object.freeze(result);\n }\n\n function addSink(sink) {\n if (!sink || typeof sink.write !== 'function')\n throw new TypeError('A sink must have write');\n if (closed) throw loggingError(LOGGING_ERROR_CODES.STOPPED);\n const registration = { sink };\n sinks.add(registration);\n return () => {\n sinks.delete(registration);\n };\n }\n for (const sink of options.sinks ?? []) addSink(sink);\n\n async function lifecycle(registrations, methods) {\n const failures = [];\n for (const method of methods) {\n await Promise.all(\n registrations.map(async ({ sink }) => {\n try {\n const previous = busy;\n busy = true;\n let result;\n try {\n result = sink[method]?.();\n } finally {\n busy = previous;\n }\n await result;\n } catch (error) {\n failures.push(error);\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }),\n );\n }\n if (failures.length)\n throw new AggregateError(failures, 'Logging lifecycle failed');\n }\n return Object.freeze({\n runId,\n getLogger(area, scope) {\n levels.requireArea(area);\n if (typeof scope !== 'string')\n throw new TypeError('Scope must be a string');\n const key = JSON.stringify([area, scope]);\n const cached = roots.get(key);\n if (cached) return cached;\n const created = logger(area, scope);\n if (roots.size < LOGGING_LIMITS.ROOT_LOGGER_CACHE_PAIRS) {\n roots.set(key, created);\n return created;\n }\n if (!scopeReported) {\n scopeReported = true;\n onError(\n loggingError(LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT),\n LOGGING_ERROR_SOURCES.SCOPE,\n );\n }\n return created;\n },\n\n setContext(values) {\n context = { ...context, ...copyBindings(values) };\n for (const key of Object.keys(context))\n if (context[key] === undefined) delete context[key];\n },\n setLevel: levels.setLevel,\n resetLevel: levels.resetLevel,\n reloadLevels: levels.reloadLevels,\n getLevels: levels.getLevels,\n addSink,\n flush() {\n const registrations = Array.from(sinks);\n return Promise.resolve().then(() => lifecycle(registrations, ['flush']));\n },\n\n stop() {\n if (!stopPromise) {\n closed = true;\n levels.stop();\n scheduler.clearTimeout(stormTimer);\n const registrations = Array.from(sinks);\n stopPromise = Promise.resolve().then(() =>\n lifecycle(registrations, ['flush', 'stop']),\n );\n }\n return stopPromise;\n },\n });\n}\n"],"names":["LOGGING_ERROR_CODES","positive","LOGGING_LIMITS","assertLevel","levelRank","define","LOGGING_ERROR_SOURCES","hostScheduler","resolveLimits","assertStormLimit","randomHex","copyBindings","report","ownRecord","LEVELS"],"mappings":";;;;;;AAEO,MAAM,cAAc,mBAAmB,MAAM,CAAC,MAAM,CAAC;AAC5D,EAAE,CAACA,6BAAmB,CAAC,iBAAiB,GAAG,+BAA+B;AAC1E,EAAE,CAACA,6BAAmB,CAAC,uBAAuB;AAC9C,IAAI,sCAAsC;AAC1C,EAAE,CAACA,6BAAmB,CAAC,OAAO,GAAG,oBAAoB;AACrD,CAAC,CAAC;;AAEK,SAAS,YAAY,CAAC,IAAI,EAAE;AACnC,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC;AACjE;;ACRO,SAAS,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE;AACnD,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,OAAO;AACzD,EAAE,MAAM,WAAW,GAAGC,eAAQ;AAC9B,IAAI,OAAO,CAAC,aAAa,IAAIC,wBAAc,CAAC,yBAAyB;AACrE,IAAI,eAAe;AACnB,GAAG;AACH,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE;AAC1B,EAAE,IAAI,OAAO,GAAG,KAAK;AACrB,EAAE,KAAK,MAAM,EAAE,EAAE,EAAE,KAAK,GAAG,MAAM,EAAE,IAAI,KAAK,EAAE;AAC9C,IAAIC,kBAAW,CAAC,KAAK,CAAC;AACtB,IAAI,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CA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AI,UAAU,EAAE,MAAM,CAAC,UAAU;AACjC,IAAI,YAAY,EAAE,MAAM,CAAC,YAAY;AACrC,IAAI,SAAS,EAAE,MAAM,CAAC,SAAS;AAC/B,IAAI,OAAO;AACX,IAAI,KAAK,GAAG;AACZ,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7C,MAAM,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9E,IAAI,CAAC;;AAEL,IAAI,IAAI,GAAG;AACX,MAAM,IAAI,CAAC,WAAW,EAAE;AACxB,QAAQ,MAAM,GAAG,IAAI;AACrB,QAAQ,MAAM,CAAC,IAAI,EAAE;AACrB,QAAQ,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC;AAC1C,QAAQ,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC/C,QAAQ,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;AAC7C,UAAU,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,SAAS;AACT,MAAM;AACN,MAAM,OAAO,WAAW;AACxB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;;"}
|
|
1
|
+
{"version":3,"file":"chunk-ieB8yTEn.cjs","sources":["../src/core/errors.js","../src/core/levels.js","../src/core/hub.js"],"sourcesContent":["import { LOGGING_ERROR_CODES } from './constants.js';\n\nexport const LOGGING_ERRORS = /* @__PURE__ */ Object.freeze({\n [LOGGING_ERROR_CODES.RECURSIVE_LOGGING]: 'Recursive logging is rejected',\n [LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT]:\n 'Root logger cache exceeds 1000 pairs',\n [LOGGING_ERROR_CODES.STOPPED]: 'Logging is stopped',\n});\n\nexport function loggingError(code) {\n return Object.assign(new Error(LOGGING_ERRORS[code]), { code });\n}\n","import { assertLevel, define, levelRank, positive } from './common.js';\nimport { LOGGING_ERROR_SOURCES, LOGGING_LIMITS } from './constants.js';\n\nexport function createLevels(options, reportError) {\n const { now, scheduler, levelStorage, areas } = options;\n const maxDuration = positive(\n options.maxOverrideMs ?? LOGGING_LIMITS.DEFAULT_LEVEL_OVERRIDE_MS,\n 'maxOverrideMs',\n );\n const states = new Map();\n let stopped = false;\n for (const { id, level = 'info' } of areas) {\n assertLevel(level);\n if (typeof id !== 'string' || !id || states.has(id))\n throw new TypeError('Areas must have unique non-empty IDs');\n states.set(id, {\n level,\n defaultLevel: level,\n rank: levelRank(level),\n until: undefined,\n timer: undefined,\n });\n }\n const requireArea = (area) => {\n const state = states.get(area);\n if (!state) throw new TypeError('Unknown log area');\n return state;\n };\n\n function save() {\n if (!levelStorage || stopped) return;\n const overrides = {};\n for (const [id, state] of states)\n if (state.until)\n define(overrides, id, { level: state.level, until: state.until });\n try {\n levelStorage.storage.setItem(levelStorage.key, JSON.stringify(overrides));\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n\n function reset(state) {\n scheduler.clearTimeout(state.timer);\n state.timer = undefined;\n state.until = undefined;\n state.level = state.defaultLevel;\n state.rank = levelRank(state.level);\n }\n\n function apply(state, level, until) {\n reset(state);\n state.level = level;\n state.rank = levelRank(level);\n state.until = until;\n state.timer = scheduler.setTimeout(\n () => {\n if (stopped) return;\n if (until > now()) {\n apply(state, level, until);\n return;\n }\n reset(state);\n save();\n },\n Math.min(LOGGING_LIMITS.MAX_TIMER_DELAY_MS, Math.max(0, until - now())),\n );\n }\n\n function reloadLevels() {\n if (stopped) return;\n for (const state of states.values()) reset(state);\n if (!levelStorage) return;\n try {\n const saved = JSON.parse(\n levelStorage.storage.getItem(levelStorage.key) ?? '{}',\n );\n if (!saved || typeof saved !== 'object') return;\n const time = now();\n for (const [id, state] of states) {\n const override = Object.hasOwn(saved, id) && saved[id];\n if (\n override &&\n levelRank(override.level) >= 0 &&\n Number.isFinite(override.until) &&\n override.until > time\n )\n apply(\n state,\n override.level,\n Math.min(override.until, time + maxDuration),\n );\n }\n } catch (error) {\n reportError(error, LOGGING_ERROR_SOURCES.STORAGE);\n }\n }\n reloadLevels();\n return {\n requireArea,\n enabled(area, level) {\n const state = requireArea(area);\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n return levelRank(level) >= state.rank;\n },\n\n setLevel(area, level, { durationMs = maxDuration } = {}) {\n assertLevel(level);\n positive(durationMs, 'durationMs');\n const state = requireArea(area);\n if (stopped) return;\n apply(state, level, now() + Math.min(durationMs, maxDuration));\n save();\n },\n\n resetLevel(area) {\n if (stopped) return;\n if (area !== undefined) reset(requireArea(area));\n else for (const state of states.values()) reset(state);\n save();\n },\n reloadLevels,\n getLevels() {\n const result = {};\n for (const [id, state] of states) {\n if (state.until && state.until <= now()) {\n reset(state);\n save();\n }\n define(\n result,\n id,\n Object.freeze({\n level: state.level,\n defaultLevel: state.defaultLevel,\n ...(state.until ? { until: state.until } : {}),\n }),\n );\n }\n return Object.freeze(result);\n },\n\n stop() {\n stopped = true;\n for (const state of states.values()) scheduler.clearTimeout(state.timer);\n },\n };\n}\n","import {\n assertStormLimit,\n copyBindings,\n scheduler as hostScheduler,\n randomHex,\n report,\n resolveLimits,\n} from './common.js';\nimport {\n LEVELS,\n LOGGING_ERROR_CODES,\n LOGGING_ERROR_SOURCES,\n LOGGING_LIMITS,\n} from './constants.js';\nimport { ownRecord } from './conversion.js';\nimport { loggingError } from './errors.js';\nimport { createLevels } from './levels.js';\n\nexport function createLogging(options) {\n if (\n !Array.isArray(options?.areas) ||\n !options.redactor ||\n typeof options.redactor.redact !== 'function'\n )\n throw new TypeError('Areas and an explicit redactor are required');\n const {\n redactor,\n now = Date.now,\n monotonicNow = () => globalThis.performance?.now() ?? Date.now(),\n scheduler = hostScheduler,\n stormLimit = LOGGING_LIMITS.DEFAULT_STORM_LIMIT,\n } = options;\n const limits = resolveLimits(redactor.limits);\n if (\n !redactor.limits ||\n Object.keys(limits).some((key) => !Object.hasOwn(redactor.limits, key))\n )\n throw new TypeError('Redactor limits are required');\n assertStormLimit(stormLimit);\n const runId = options.createRunId?.() ?? randomHex(16);\n if (typeof runId !== 'string' || !runId)\n throw new TypeError('Invalid run ID');\n const sinks = new Set();\n const roots = new Map();\n const storms = new Map();\n let context = copyBindings(options.context);\n let seq = 0;\n let closed = false;\n let busy = false;\n let scopeReported = false;\n let reporting = false;\n let stormTimer;\n let stopPromise;\n\n function onError(error, source) {\n if (reporting) return;\n reporting = true;\n const wasBusy = busy;\n busy = true;\n report(options.onError, error, source);\n busy = wasBusy;\n reporting = false;\n }\n for (const sink of options.sinks ?? []) addSink(sink);\n const levels = createLevels({ ...options, now, scheduler }, onError);\n\n function emit(area, scope, binding, level, message, data, bypass = false) {\n try {\n if (busy) {\n onError(\n loggingError(LOGGING_ERROR_CODES.RECURSIVE_LOGGING),\n LOGGING_ERROR_SOURCES.REENTRY,\n );\n return;\n }\n if (\n closed ||\n options.isActive?.() === false ||\n sinks.size === 0 ||\n (!bypass && !levels.enabled(area, level))\n )\n return;\n if (!bypass && stormLimit !== false) {\n const key = JSON.stringify([area, scope]);\n let counter = storms.get(key);\n if (!counter) {\n const cacheKey =\n storms.size < LOGGING_LIMITS.STORM_SCOPE_PAIRS ? key : 'overflow';\n counter = storms.get(cacheKey);\n if (!counter) {\n counter = {\n area,\n scope,\n start: monotonicNow(),\n count: 0,\n dropped: 0,\n };\n storms.set(cacheKey, counter);\n }\n }\n const time = monotonicNow();\n if (\n time - counter.start >= LOGGING_LIMITS.STORM_WINDOW_MS ||\n time < counter.start\n ) {\n counter.start = time;\n counter.count = 0;\n }\n if (counter.count++ >= stormLimit) {\n counter.dropped++;\n if (stormTimer === undefined)\n stormTimer = scheduler.setTimeout(\n summarize,\n LOGGING_LIMITS.STORM_SUMMARY_DELAY_MS,\n );\n return;\n }\n }\n const registrations = Array.from(sinks);\n busy = true;\n try {\n let value;\n try {\n value = typeof data === 'function' ? data() : data;\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n return;\n }\n if (options.isActive?.() === false || sinks.size === 0) return;\n let record;\n try {\n record = ownRecord(\n redactor.redact({\n runId,\n seq: ++seq,\n at: now(),\n area,\n scope,\n level,\n message,\n context: { ...context, ...binding },\n data: value,\n }),\n limits,\n );\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.REDACTOR);\n return;\n }\n if (options.isActive?.() === false) return;\n for (const registration of registrations) {\n if (options.isActive?.() === false || !sinks.has(registration))\n continue;\n try {\n registration.sink.write(record);\n } catch (error) {\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }\n } finally {\n busy = false;\n }\n } catch (error) {\n busy = false;\n onError(error, LOGGING_ERROR_SOURCES.DATA);\n }\n }\n\n function summarize() {\n stormTimer = undefined;\n for (const counter of storms.values()) {\n if (!counter.dropped) continue;\n const dropped = counter.dropped;\n counter.dropped = 0;\n emit(\n counter.area,\n counter.scope,\n {},\n 'warn',\n 'logging.suppressed',\n { scope: counter.scope, dropped },\n true,\n );\n }\n }\n\n function logger(area, scope, binding = {}) {\n const result = {};\n for (const level of Object.values(LEVELS))\n result[level] = (message, data) =>\n emit(area, scope, binding, level, message, data);\n result.child = ({\n scope: childScope = scope,\n context: childContext = {},\n } = {}) =>\n logger(area, childScope, { ...binding, ...copyBindings(childContext) });\n return Object.freeze(result);\n }\n\n function addSink(sink) {\n if (!sink || typeof sink.write !== 'function')\n throw new TypeError('A sink must have write');\n if (closed) throw loggingError(LOGGING_ERROR_CODES.STOPPED);\n const registration = { sink };\n sinks.add(registration);\n return () => {\n sinks.delete(registration);\n };\n }\n\n async function lifecycle(registrations, methods) {\n const failures = [];\n for (const method of methods) {\n await Promise.all(\n registrations.map(async ({ sink }) => {\n try {\n const previous = busy;\n busy = true;\n let result;\n try {\n result = sink[method]?.();\n } finally {\n busy = previous;\n }\n await result;\n } catch (error) {\n failures.push(error);\n onError(error, LOGGING_ERROR_SOURCES.SINK);\n }\n }),\n );\n }\n if (failures.length)\n throw new AggregateError(failures, 'Logging lifecycle failed');\n }\n return Object.freeze({\n runId,\n getLogger(area, scope) {\n levels.requireArea(area);\n if (typeof scope !== 'string')\n throw new TypeError('Scope must be a string');\n const key = JSON.stringify([area, scope]);\n const cached = roots.get(key);\n if (cached) return cached;\n const created = logger(area, scope);\n if (roots.size < LOGGING_LIMITS.ROOT_LOGGER_CACHE_PAIRS) {\n roots.set(key, created);\n return created;\n }\n if (!scopeReported) {\n scopeReported = true;\n onError(\n loggingError(LOGGING_ERROR_CODES.ROOT_LOGGER_CACHE_LIMIT),\n LOGGING_ERROR_SOURCES.SCOPE,\n );\n }\n return created;\n },\n\n setContext(values) {\n context = { ...context, ...copyBindings(values) };\n for (const key of Object.keys(context))\n if (context[key] === undefined) delete context[key];\n },\n setLevel: levels.setLevel,\n resetLevel: levels.resetLevel,\n reloadLevels: levels.reloadLevels,\n getLevels: levels.getLevels,\n addSink,\n flush() {\n const registrations = Array.from(sinks);\n return Promise.resolve().then(() => lifecycle(registrations, ['flush']));\n },\n\n stop() {\n if (!stopPromise) {\n closed = true;\n levels.stop();\n scheduler.clearTimeout(stormTimer);\n const registrations = Array.from(sinks);\n stopPromise = Promise.resolve().then(() =>\n lifecycle(registrations, ['flush', 'stop']),\n );\n }\n return stopPromise;\n },\n });\n}\n"],"names":["LOGGING_ERROR_CODES","positive","LOGGING_LIMITS","assertLevel","levelRank","define","LOGGING_ERROR_SOURCES","hostScheduler","resolveLimits","assertStormLimit","randomHex","copyBindings","report","ownRecord","LEVELS"],"mappings":";;;;;;AAEO,MAAM,cAAc,mBAAmB,MAAM,CAAC,MAAM,CAAC;AAC5D,EAAE,CAACA,6BAAmB,CAAC,iBAAiB,GAAG,+BAA+B;AAC1E,EAAE,CAACA,6BAAmB,CAAC,uBAAuB;AAC9C,IAAI,sCAAsC;AAC1C,EAAE,CAACA,6BAAmB,CAAC,OAAO,GAAG,oBA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AY,CAAC,UAAU,CAAC;AAC1C,QAAQ,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC/C,QAAQ,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;AAC7C,UAAU,SAAS,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,SAAS;AACT,MAAM;AACN,MAAM,OAAO,WAAW;AACxB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var hub = require('../chunk-ieB8yTEn.cjs');
|
|
4
|
+
var history_index = require('../history/index.cjs');
|
|
5
|
+
var upload_index = require('../upload/index.cjs');
|
|
6
|
+
require('../chunk-CXZYNALm.cjs');
|
|
7
|
+
require('../chunk-BLf-eCDO.cjs');
|
|
8
|
+
require('../chunk-CEhpwtwJ.cjs');
|
|
9
|
+
require('@bazariodev/coordination');
|
|
10
|
+
|
|
11
|
+
const CLIENT_DEFAULTS = Object.freeze({
|
|
12
|
+
MAX_HISTORY_RECORDS: 1000,
|
|
13
|
+
MAX_BATCH_RECORDS: 100,
|
|
14
|
+
INTERVAL_MS: 5000,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const HISTORY_METHODS = Object.freeze({
|
|
18
|
+
REQUIRED: Object.freeze(['write', 'query', 'clear']),
|
|
19
|
+
OPTIONAL: Object.freeze(['flush', 'stop', 'getStatus']),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function resolveHistory(history) {
|
|
23
|
+
if (history === false) return undefined;
|
|
24
|
+
if (history === undefined)
|
|
25
|
+
return history_index.createMemoryHistory({
|
|
26
|
+
maxRecords: CLIENT_DEFAULTS.MAX_HISTORY_RECORDS,
|
|
27
|
+
});
|
|
28
|
+
if (!history || typeof history !== 'object')
|
|
29
|
+
throw new TypeError('Invalid history options');
|
|
30
|
+
if (
|
|
31
|
+
!HISTORY_METHODS.REQUIRED.some((method) => method in history) &&
|
|
32
|
+
!HISTORY_METHODS.OPTIONAL.some((method) => method in history)
|
|
33
|
+
)
|
|
34
|
+
return history_index.createMemoryHistory(history);
|
|
35
|
+
if (
|
|
36
|
+
HISTORY_METHODS.REQUIRED.some(
|
|
37
|
+
(method) => typeof history[method] !== 'function',
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
throw new TypeError('A history client requires write, query, and clear');
|
|
41
|
+
for (const method of HISTORY_METHODS.OPTIONAL)
|
|
42
|
+
if (history[method] !== undefined && typeof history[method] !== 'function')
|
|
43
|
+
throw new TypeError(`Invalid history ${method}`);
|
|
44
|
+
return history;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createDocket(options) {
|
|
48
|
+
if (!options || typeof options !== 'object')
|
|
49
|
+
throw new TypeError('Docket options are required');
|
|
50
|
+
const {
|
|
51
|
+
areas,
|
|
52
|
+
redactor,
|
|
53
|
+
sinks: suppliedSinks,
|
|
54
|
+
context,
|
|
55
|
+
levelStorage,
|
|
56
|
+
maxOverrideMs,
|
|
57
|
+
stormLimit,
|
|
58
|
+
scheduler,
|
|
59
|
+
now,
|
|
60
|
+
monotonicNow,
|
|
61
|
+
createRunId,
|
|
62
|
+
onError,
|
|
63
|
+
history: historyOption,
|
|
64
|
+
upload: uploadOption,
|
|
65
|
+
isActive: isApplicationActive,
|
|
66
|
+
} = options;
|
|
67
|
+
const history = resolveHistory(historyOption);
|
|
68
|
+
let upload;
|
|
69
|
+
let uploadOptions;
|
|
70
|
+
let outbox;
|
|
71
|
+
if (uploadOption !== undefined && uploadOption !== false) {
|
|
72
|
+
if (!uploadOption || typeof uploadOption !== 'object')
|
|
73
|
+
throw new TypeError('Invalid upload options');
|
|
74
|
+
outbox = uploadOption.outbox;
|
|
75
|
+
if (
|
|
76
|
+
!outbox ||
|
|
77
|
+
outbox === history ||
|
|
78
|
+
typeof outbox.clear !== 'function' ||
|
|
79
|
+
typeof outbox.stop !== 'function'
|
|
80
|
+
)
|
|
81
|
+
throw new TypeError('Upload requires a separate outbox client');
|
|
82
|
+
const {
|
|
83
|
+
maxBatchRecords = CLIENT_DEFAULTS.MAX_BATCH_RECORDS,
|
|
84
|
+
intervalMs = CLIENT_DEFAULTS.INTERVAL_MS,
|
|
85
|
+
scheduler,
|
|
86
|
+
onError,
|
|
87
|
+
send,
|
|
88
|
+
} = uploadOption;
|
|
89
|
+
if (typeof send !== 'function')
|
|
90
|
+
throw new TypeError('An upload callback is required');
|
|
91
|
+
uploadOptions = {
|
|
92
|
+
maxBatchRecords,
|
|
93
|
+
intervalMs,
|
|
94
|
+
scheduler,
|
|
95
|
+
onError,
|
|
96
|
+
send: (records, signal, token) =>
|
|
97
|
+
send.call(uploadOption, records, signal, token),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const sinks = [...(suppliedSinks ?? [])];
|
|
101
|
+
if (history) sinks.push(history);
|
|
102
|
+
for (const sink of sinks)
|
|
103
|
+
if (!sink || typeof sink.write !== 'function')
|
|
104
|
+
throw new TypeError('A sink must have write');
|
|
105
|
+
let closed = false;
|
|
106
|
+
const logging = hub.createLogging({
|
|
107
|
+
areas,
|
|
108
|
+
redactor,
|
|
109
|
+
context,
|
|
110
|
+
levelStorage,
|
|
111
|
+
maxOverrideMs,
|
|
112
|
+
stormLimit,
|
|
113
|
+
scheduler,
|
|
114
|
+
now,
|
|
115
|
+
monotonicNow,
|
|
116
|
+
createRunId: createRunId ? () => createRunId.call(options) : createRunId,
|
|
117
|
+
onError,
|
|
118
|
+
isActive() {
|
|
119
|
+
if (closed) return false;
|
|
120
|
+
const active = isApplicationActive?.call(options);
|
|
121
|
+
return !closed && active !== false;
|
|
122
|
+
},
|
|
123
|
+
sinks: [],
|
|
124
|
+
});
|
|
125
|
+
const detachments = [];
|
|
126
|
+
try {
|
|
127
|
+
if (uploadOptions) upload = upload_index.createUploadSink(uploadOptions, outbox);
|
|
128
|
+
if (upload) sinks.push(upload);
|
|
129
|
+
for (const sink of sinks) detachments.push(logging.addSink(sink));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
for (const detach of detachments) detach();
|
|
132
|
+
void upload?.stop();
|
|
133
|
+
void logging.stop().catch(() => {});
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
let stopped;
|
|
137
|
+
return Object.freeze({
|
|
138
|
+
...logging,
|
|
139
|
+
history,
|
|
140
|
+
upload,
|
|
141
|
+
outbox,
|
|
142
|
+
stop() {
|
|
143
|
+
if (stopped) return stopped;
|
|
144
|
+
closed = true;
|
|
145
|
+
stopped = Promise.resolve().then(async () => {
|
|
146
|
+
const failures = [];
|
|
147
|
+
try {
|
|
148
|
+
await logging.stop();
|
|
149
|
+
} catch (error) {
|
|
150
|
+
failures.push(error);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
await outbox?.stop();
|
|
154
|
+
} catch (error) {
|
|
155
|
+
failures.push(error);
|
|
156
|
+
}
|
|
157
|
+
if (failures.length)
|
|
158
|
+
throw new AggregateError(failures, 'Docket shutdown failed');
|
|
159
|
+
});
|
|
160
|
+
void upload?.stop();
|
|
161
|
+
return stopped;
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
exports.createDocket = createDocket;
|
|
167
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/client/constants.js","../../src/client/index.js"],"sourcesContent":["export const CLIENT_DEFAULTS = Object.freeze({\n MAX_HISTORY_RECORDS: 1000,\n MAX_BATCH_RECORDS: 100,\n INTERVAL_MS: 5000,\n});\n\nexport const HISTORY_METHODS = Object.freeze({\n REQUIRED: Object.freeze(['write', 'query', 'clear']),\n OPTIONAL: Object.freeze(['flush', 'stop', 'getStatus']),\n});\n","import { createLogging } from '../core/hub.js';\nimport { createMemoryHistory } from '../history/index.js';\nimport { createUploadSink } from '../upload/index.js';\nimport { CLIENT_DEFAULTS, HISTORY_METHODS } from './constants.js';\n\nfunction resolveHistory(history) {\n if (history === false) return undefined;\n if (history === undefined)\n return createMemoryHistory({\n maxRecords: CLIENT_DEFAULTS.MAX_HISTORY_RECORDS,\n });\n if (!history || typeof history !== 'object')\n throw new TypeError('Invalid history options');\n if (\n !HISTORY_METHODS.REQUIRED.some((method) => method in history) &&\n !HISTORY_METHODS.OPTIONAL.some((method) => method in history)\n )\n return createMemoryHistory(history);\n if (\n HISTORY_METHODS.REQUIRED.some(\n (method) => typeof history[method] !== 'function',\n )\n )\n throw new TypeError('A history client requires write, query, and clear');\n for (const method of HISTORY_METHODS.OPTIONAL)\n if (history[method] !== undefined && typeof history[method] !== 'function')\n throw new TypeError(`Invalid history ${method}`);\n return history;\n}\n\nexport function createDocket(options) {\n if (!options || typeof options !== 'object')\n throw new TypeError('Docket options are required');\n const {\n areas,\n redactor,\n sinks: suppliedSinks,\n context,\n levelStorage,\n maxOverrideMs,\n stormLimit,\n scheduler,\n now,\n monotonicNow,\n createRunId,\n onError,\n history: historyOption,\n upload: uploadOption,\n isActive: isApplicationActive,\n } = options;\n const history = resolveHistory(historyOption);\n let upload;\n let uploadOptions;\n let outbox;\n if (uploadOption !== undefined && uploadOption !== false) {\n if (!uploadOption || typeof uploadOption !== 'object')\n throw new TypeError('Invalid upload options');\n outbox = uploadOption.outbox;\n if (\n !outbox ||\n outbox === history ||\n typeof outbox.clear !== 'function' ||\n typeof outbox.stop !== 'function'\n )\n throw new TypeError('Upload requires a separate outbox client');\n const {\n maxBatchRecords = CLIENT_DEFAULTS.MAX_BATCH_RECORDS,\n intervalMs = CLIENT_DEFAULTS.INTERVAL_MS,\n scheduler,\n onError,\n send,\n } = uploadOption;\n if (typeof send !== 'function')\n throw new TypeError('An upload callback is required');\n uploadOptions = {\n maxBatchRecords,\n intervalMs,\n scheduler,\n onError,\n send: (records, signal, token) =>\n send.call(uploadOption, records, signal, token),\n };\n }\n const sinks = [...(suppliedSinks ?? [])];\n if (history) sinks.push(history);\n for (const sink of sinks)\n if (!sink || typeof sink.write !== 'function')\n throw new TypeError('A sink must have write');\n let closed = false;\n const logging = createLogging({\n areas,\n redactor,\n context,\n levelStorage,\n maxOverrideMs,\n stormLimit,\n scheduler,\n now,\n monotonicNow,\n createRunId: createRunId ? () => createRunId.call(options) : createRunId,\n onError,\n isActive() {\n if (closed) return false;\n const active = isApplicationActive?.call(options);\n return !closed && active !== false;\n },\n sinks: [],\n });\n const detachments = [];\n try {\n if (uploadOptions) upload = createUploadSink(uploadOptions, outbox);\n if (upload) sinks.push(upload);\n for (const sink of sinks) detachments.push(logging.addSink(sink));\n } catch (error) {\n for (const detach of detachments) detach();\n void upload?.stop();\n void logging.stop().catch(() => {});\n throw error;\n }\n let stopped;\n return Object.freeze({\n ...logging,\n history,\n upload,\n outbox,\n stop() {\n if (stopped) return stopped;\n closed = true;\n stopped = Promise.resolve().then(async () => {\n const failures = [];\n try {\n await logging.stop();\n } catch (error) {\n failures.push(error);\n }\n try {\n await outbox?.stop();\n } catch (error) {\n failures.push(error);\n }\n if (failures.length)\n throw new AggregateError(failures, 'Docket shutdown failed');\n });\n void upload?.stop();\n return stopped;\n },\n });\n}\n"],"names":["createMemoryHistory","createLogging","createUploadSink"],"mappings":";;;;;;;;;;AAAO,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;AAC7C,EAAE,mBAAmB,EAAE,IAAI;AAC3B,EAAE,iBAAiB,EAAE,GAAG;AACxB,EAAE,WAAW,EAAE,IAAI;AACnB,CAAC,CAAC;;AAEK,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;AAC7C,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACtD,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;;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CAAC,CAAC;AACR,MAAM,KAAK,MAAM,EAAE,IAAI,EAAE;AACzB,MAAM,OAAO,OAAO;AACpB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MemoryHistoryOptions } from "../history/index.cjs";
|
|
2
|
+
import type { Logging, LoggingOptions, LogSink, LogSource } from "../index.cjs";
|
|
3
|
+
import type {
|
|
4
|
+
UploadOutbox,
|
|
5
|
+
UploadSink,
|
|
6
|
+
UploadSinkOptions,
|
|
7
|
+
} from "../upload/index.cjs";
|
|
8
|
+
|
|
9
|
+
export type HistoryClient = LogSink &
|
|
10
|
+
LogSource &
|
|
11
|
+
Readonly<{
|
|
12
|
+
clear(): void | Promise<void>;
|
|
13
|
+
}>;
|
|
14
|
+
export type OutboxClient = UploadOutbox &
|
|
15
|
+
Readonly<{
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
stop(): Promise<void>;
|
|
18
|
+
}>;
|
|
19
|
+
export type DocketUploadOptions = Readonly<{
|
|
20
|
+
outbox: OutboxClient;
|
|
21
|
+
send: UploadSinkOptions['send'];
|
|
22
|
+
maxBatchRecords?: number;
|
|
23
|
+
intervalMs?: number;
|
|
24
|
+
scheduler?: UploadSinkOptions['scheduler'];
|
|
25
|
+
onError?: UploadSinkOptions['onError'];
|
|
26
|
+
}>;
|
|
27
|
+
export type DocketOptions<TArea extends string> = LoggingOptions<TArea> &
|
|
28
|
+
Readonly<{
|
|
29
|
+
history?: false | MemoryHistoryOptions | HistoryClient;
|
|
30
|
+
upload?: false | DocketUploadOptions;
|
|
31
|
+
}>;
|
|
32
|
+
export type Docket<TArea extends string> = Logging<TArea> &
|
|
33
|
+
Readonly<{
|
|
34
|
+
history: HistoryClient | undefined;
|
|
35
|
+
upload: UploadSink | undefined;
|
|
36
|
+
outbox: OutboxClient | undefined;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function createDocket<TArea extends string>(
|
|
39
|
+
options: DocketOptions<TArea>,
|
|
40
|
+
): Docket<TArea>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MemoryHistoryOptions } from '../history/index.js';
|
|
2
|
+
import type { Logging, LoggingOptions, LogSink, LogSource } from '../index.js';
|
|
3
|
+
import type {
|
|
4
|
+
UploadOutbox,
|
|
5
|
+
UploadSink,
|
|
6
|
+
UploadSinkOptions,
|
|
7
|
+
} from '../upload/index.js';
|
|
8
|
+
|
|
9
|
+
export type HistoryClient = LogSink &
|
|
10
|
+
LogSource &
|
|
11
|
+
Readonly<{
|
|
12
|
+
clear(): void | Promise<void>;
|
|
13
|
+
}>;
|
|
14
|
+
export type OutboxClient = UploadOutbox &
|
|
15
|
+
Readonly<{
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
stop(): Promise<void>;
|
|
18
|
+
}>;
|
|
19
|
+
export type DocketUploadOptions = Readonly<{
|
|
20
|
+
outbox: OutboxClient;
|
|
21
|
+
send: UploadSinkOptions['send'];
|
|
22
|
+
maxBatchRecords?: number;
|
|
23
|
+
intervalMs?: number;
|
|
24
|
+
scheduler?: UploadSinkOptions['scheduler'];
|
|
25
|
+
onError?: UploadSinkOptions['onError'];
|
|
26
|
+
}>;
|
|
27
|
+
export type DocketOptions<TArea extends string> = LoggingOptions<TArea> &
|
|
28
|
+
Readonly<{
|
|
29
|
+
history?: false | MemoryHistoryOptions | HistoryClient;
|
|
30
|
+
upload?: false | DocketUploadOptions;
|
|
31
|
+
}>;
|
|
32
|
+
export type Docket<TArea extends string> = Logging<TArea> &
|
|
33
|
+
Readonly<{
|
|
34
|
+
history: HistoryClient | undefined;
|
|
35
|
+
upload: UploadSink | undefined;
|
|
36
|
+
outbox: OutboxClient | undefined;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function createDocket<TArea extends string>(
|
|
39
|
+
options: DocketOptions<TArea>,
|
|
40
|
+
): Docket<TArea>;
|