@loggerjs/codecs 0.0.2 → 0.1.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 (2) hide show
  1. package/README.md +52 -7
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,19 +1,64 @@
1
1
  # @loggerjs/codecs
2
2
 
3
- Additional serialization codecs for transports.
3
+ > High-performance and binary serialization codecs for LoggerJS transports.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@loggerjs/codecs.svg)](https://www.npmjs.com/package/@loggerjs/codecs)
6
+ [![license](https://img.shields.io/npm/l/@loggerjs/codecs)](../../LICENSE)
7
+
8
+ Optional codecs for [LoggerJS](../../README.md) that go beyond the JSON/NDJSON codecs built into `@loggerjs/core`. **Codecs belong to transports** — the pipeline keeps values raw and each destination owns its serialization, so you can pick a different wire format per transport without touching middleware or processors.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @loggerjs/codecs
14
+ ```
15
+
16
+ ## Usage
4
17
 
5
18
  ```ts
6
- import { fastEventJsonCodec, msgpackrCodec, projectorCodec } from "@loggerjs/codecs";
19
+ import { fastEventJsonCodec, projectorCodec } from "@loggerjs/codecs";
20
+ import { nodeHttpTransport } from "@loggerjs/node";
21
+
22
+ // The performance codec for JSON payload transports.
23
+ nodeHttpTransport({
24
+ url: "https://collector.example/logs",
25
+ codec: fastEventJsonCodec(),
26
+ });
27
+
28
+ // Drop envelope fields when downstream does not need them.
29
+ nodeHttpTransport({
30
+ url: "https://collector.example/logs",
31
+ codec: fastEventJsonCodec({ includeId: false, includeSeq: false, includeLevelName: false }),
32
+ });
33
+ ```
34
+
35
+ ## Codecs
7
36
 
8
- const json = fastEventJsonCodec();
9
- const msgpack = msgpackrCodec();
37
+ | Codec | Format | Notes |
38
+ | --- | --- | --- |
39
+ | `fastEventJsonCodec` | JSON | The performance codec — fragment-cached serialization, fast by default, falls back instead of throwing on circular references. Toggle envelope fields (`includeId`, `includeSeq`, `includeLevelName`) to trade detail for speed. |
40
+ | `msgpackrCodec` | MessagePack (binary) | Compact binary encoding via [`msgpackr`](https://github.com/kriszyp/msgpackr); ideal for worker, WebSocket, and HTTP transports that accept binary payloads. |
41
+ | `projectorCodec` | custom | Build a codec from a `project` step (shape the events) plus a `serialize` step (turn them into the wire payload). |
10
42
 
11
- const projected = projectorCodec({
43
+ For line-delimited stdout/file output, use the Node transports' default `ndjsonCodec()` from `@loggerjs/core`; `fastEventJsonCodec()` emits JSON payloads and does not append newlines.
44
+
45
+ ```ts
46
+ const idsOnly = projectorCodec({
12
47
  name: "ids-only",
13
48
  contentType: "application/json",
14
- project: (events) => events,
49
+ project: (events) => events.map((e) => ({ id: e.id, level: e.level, time: e.time })),
15
50
  serialize: JSON.stringify,
16
51
  });
17
52
  ```
18
53
 
19
- Codecs are transport-owned. Middleware should keep raw values and let the chosen transport serialize.
54
+ > Keep raw, structured values flowing through middleware and processors so redaction works on real data and batching can amortize serialization. Never pre-stringify in the pipeline.
55
+
56
+ ## Documentation
57
+
58
+ - [Codecs](../../docs/CODECS.md) — the codec contract and fast-by-default safety semantics
59
+ - [Performance](../../docs/PERFORMANCE.md) — choosing a codec for the hot path
60
+ - [Benchmarks](../../docs/BENCHMARKS.md) · [LoggerJS root README](../../README.md)
61
+
62
+ ## License
63
+
64
+ [MIT](../../LICENSE) © JS Kits
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loggerjs/codecs",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Serialization codecs for loggerjs.",
5
5
  "homepage": "https://github.com/jskits/loggerjs/tree/main/packages/codecs#readme",
6
6
  "bugs": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "msgpackr": "^2.0.4",
38
- "@loggerjs/core": "0.0.2"
38
+ "@loggerjs/core": "0.1.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "pnpm run clean && pnpm run build:js && pnpm run build:types",