@decohere/scribe-console 0.0.1-dev.20261105.97 → 0.0.1-dev.20261106.132

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/scribe-console",
3
- "version": "0.0.1-dev.20261105.97",
3
+ "version": "0.0.1-dev.20261106.132",
4
4
  "description": "JSON console adapter for @decohere/scribe: one JSON line per entry, for Workers, browsers, Deno, Bun and Node",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,15 +26,14 @@
26
26
  "exports": {
27
27
  ".": {
28
28
  "types": "./types/src/index.d.ts",
29
- "import": "./es6/src/index.js",
30
- "require": "./commonjs/src/index.js"
29
+ "import": "./es6/src/index.js"
31
30
  }
32
31
  },
33
32
  "scripts": {
34
33
  "test": "echo \"Error: no test specified\" && exit 1"
35
34
  },
36
35
  "dependencies": {
37
- "@decohere/scribe": "0.0.1-dev.20261105.97"
36
+ "@decohere/scribe": "0.0.1-dev.20261106.132"
38
37
  },
39
38
  "devDependencies": {}
40
39
  }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./json-console.adapter.js"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
13
- }
14
- });
15
- }
16
- });
17
- return from;
18
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "JsonConsoleAdapter", {
6
- enumerable: true,
7
- get: function() {
8
- return JsonConsoleAdapter;
9
- }
10
- });
11
- const _scribe = require("@decohere/scribe");
12
- class JsonConsoleAdapter extends _scribe.LogEntryAdapter {
13
- timestamp;
14
- constructor(options = {}){
15
- super();
16
- this.timestamp = options.timestamp ?? false;
17
- }
18
- write(entry) {
19
- const method = methodFor(this.levels[entry.level] ?? _scribe.LogLevels.info);
20
- console[method](stringify(toLine(entry, this.timestamp)));
21
- }
22
- }
23
- /**
24
- * Custom levels pick the method of the default level at or below them:
25
- * `fatal` and `error` → `console.error`, `warn` → `console.warn`, `info` →
26
- * `console.info`, `debug` and `trace` → `console.debug` (`console.trace` would
27
- * print a stack).
28
- */ function methodFor(value) {
29
- if (value >= _scribe.LogLevels.error) {
30
- return "error";
31
- }
32
- if (value >= _scribe.LogLevels.warn) {
33
- return "warn";
34
- }
35
- if (value >= _scribe.LogLevels.info) {
36
- return "info";
37
- }
38
- return "debug";
39
- }
40
- /** `level`, `name`, `time` and `msg` are the entry's own; a field cannot replace them. */ function toLine(entry, timestamp) {
41
- const line = {
42
- level: entry.level,
43
- name: entry.name
44
- };
45
- if (timestamp) {
46
- line.time = new Date().toISOString();
47
- }
48
- if (entry.msg !== undefined) {
49
- line.msg = entry.msg;
50
- }
51
- for (const [key, value] of Object.entries(entry.fields)){
52
- if (!(key in line)) {
53
- line[key] = value;
54
- }
55
- }
56
- if (entry.err != null) {
57
- line.err = entry.err;
58
- }
59
- return line;
60
- }
61
- /** `JSON.stringify` that survives cycles and bigints, and serializes nested errors. */ function stringify(line) {
62
- const ancestors = [];
63
- return JSON.stringify(line, function(_key, value) {
64
- if (typeof value === "bigint") {
65
- return value.toString();
66
- }
67
- if (value == null || typeof value !== "object") {
68
- return value;
69
- }
70
- while(ancestors.length > 0 && ancestors.at(-1) !== this){
71
- ancestors.pop();
72
- }
73
- if (ancestors.includes(value)) {
74
- return "[Circular]";
75
- }
76
- if (value instanceof Error) {
77
- // Track the error too: its serialized properties may point back at it.
78
- const serialized = (0, _scribe.serializeError)(value);
79
- ancestors.push(value, serialized);
80
- return serialized;
81
- }
82
- ancestors.push(value);
83
- return value;
84
- });
85
- }