@snyxex/pipex 1.0.2 → 1.0.4

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 (78) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +1 -1
  3. package/README.md +238 -139
  4. package/dist/compression-B0xKUa-N.d.mts +35 -0
  5. package/dist/compression-C1nLQVur.d.cts +35 -0
  6. package/dist/compression-ChJlMVwP.mjs +1 -0
  7. package/dist/compression-ZHOsKTJC.cjs +1 -0
  8. package/dist/compression.cjs +1 -0
  9. package/dist/compression.d.cts +2 -0
  10. package/dist/compression.d.mts +2 -0
  11. package/dist/compression.mjs +1 -0
  12. package/dist/core-DNchiRD5.mjs +2 -0
  13. package/dist/core-DSIwvTqu.cjs +2 -0
  14. package/dist/dataEngine-6R3J-WtS.cjs +1 -0
  15. package/dist/dataEngine-C-xYat2f.d.cts +223 -0
  16. package/dist/dataEngine-Zap1RwAJ.d.mts +223 -0
  17. package/dist/dataEngine-raQdutX5.mjs +1 -0
  18. package/dist/encryption-CCPoyX4q.d.cts +39 -0
  19. package/dist/encryption-CHvy--rb.mjs +1 -0
  20. package/dist/encryption-D4eC9ubl.d.mts +39 -0
  21. package/dist/encryption-DwdO7Y4J.cjs +1 -0
  22. package/dist/encryption.cjs +1 -0
  23. package/dist/encryption.d.cts +2 -0
  24. package/dist/encryption.d.mts +2 -0
  25. package/dist/encryption.mjs +1 -0
  26. package/dist/hashing-C6TkcsUE.d.cts +30 -0
  27. package/dist/hashing-CEwtXh2V.d.mts +30 -0
  28. package/dist/hashing-DF_guuZf.cjs +1 -0
  29. package/dist/hashing-DU3rmGMP.mjs +1 -0
  30. package/dist/hashing.cjs +1 -0
  31. package/dist/hashing.d.cts +2 -0
  32. package/dist/hashing.d.mts +2 -0
  33. package/dist/hashing.mjs +1 -0
  34. package/dist/index.cjs +1 -0
  35. package/dist/index.d.cts +285 -0
  36. package/dist/index.d.mts +143 -623
  37. package/dist/index.mjs +1 -3
  38. package/dist/kms.cjs +1 -0
  39. package/dist/kms.d.cts +3 -0
  40. package/dist/kms.d.mts +3 -0
  41. package/dist/kms.mjs +1 -0
  42. package/dist/kms_encryption-1G54Lcuo.mjs +1 -0
  43. package/dist/kms_encryption-B07lunjB.cjs +1 -0
  44. package/dist/kms_encryption-BBIHGi_O.d.cts +30 -0
  45. package/dist/kms_encryption-BbtS7rXa.d.mts +30 -0
  46. package/dist/native.cjs +1 -0
  47. package/dist/native.d.cts +2 -0
  48. package/dist/native.d.mts +2 -0
  49. package/dist/native.mjs +1 -0
  50. package/dist/parallel.cjs +1 -0
  51. package/dist/parallel.d.cts +2 -0
  52. package/dist/parallel.d.mts +2 -0
  53. package/dist/parallel.mjs +1 -0
  54. package/dist/plugin-D85NMNiy.d.mts +13 -0
  55. package/dist/plugin-c_iSNY86.d.cts +13 -0
  56. package/dist/resourceLimits-CpDWwraK.mjs +1 -0
  57. package/dist/resourceLimits-lJrEhDE5.cjs +1 -0
  58. package/dist/types-B50Urzn2.d.cts +152 -0
  59. package/dist/types-B50Urzn2.d.mts +152 -0
  60. package/dist/validation-BgdV4KdW.cjs +1 -0
  61. package/dist/validation-BkJxOs7q.mjs +1 -0
  62. package/dist/validation-hcvcixaS.d.cts +29 -0
  63. package/dist/validation-xIBvnsSH.d.mts +29 -0
  64. package/dist/validation.cjs +1 -0
  65. package/dist/validation.d.cts +2 -0
  66. package/dist/validation.d.mts +2 -0
  67. package/dist/validation.mjs +1 -0
  68. package/dist/worker-1Q2hRcRB.cjs +1 -0
  69. package/dist/worker-DT7RYWwo.d.cts +34 -0
  70. package/dist/worker-iSO3KhfN.d.mts +34 -0
  71. package/dist/worker-ul8lQ0SH.mjs +1 -0
  72. package/package.json +128 -31
  73. package/SECURITY.md +0 -41
  74. package/dist/index.d.mts.map +0 -1
  75. package/dist/index.mjs.map +0 -1
  76. package/docs/architecture.md +0 -124
  77. package/docs/encryption-v4-migration.md +0 -45
  78. package/docs/enterprise.md +0 -280
package/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ Changes are documented here for users and downstream maintainers. Versioned rele
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 1.0.4
8
+
9
+ - Updated runtime dependencies and the TypeScript, bundler, and npm toolchain. Added coverage for MessagePack data written by the previous version.
10
+
11
+ ## 1.0.3
12
+
7
13
  - Maintained Jenkins CI now validates current Node.js 22, 24, and 26 lines.
8
14
  - Release checks cover package tarballs, clean consumers, a dependency audit, and repository AI-skill validation.
9
15
  - Added open-source security, contribution, conduct, and release documentation.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 snyxe
3
+ Copyright (c) 2026 Snyxex
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,221 +1,320 @@
1
1
  # PipeX
2
2
 
3
- PipeX is a typed Node.js data-transformation engine for composing compression, authenticated encryption, integrity checks, validation, and custom plugins across buffers, files, and streams.
3
+ PipeX composes compression, authenticated encryption, and HMAC integrity checks into reversible data-processing pipelines for Node.js buffers, files, and streams.
4
4
 
5
- ## Requirements
6
-
7
- - Node.js 22 or newer (Jenkins tests current 22.x, 24.x and 26.x)
8
- - ESM (`"type": "module"`)
5
+ [![npm version](https://img.shields.io/npm/v/@snyxex/pipex)](https://www.npmjs.com/package/@snyxex/pipex)
6
+ [![license](https://img.shields.io/github/license/Snyxex/PipeX)](https://github.com/Snyxex/PipeX/blob/main/LICENSE)
7
+ [![CI](https://img.shields.io/badge/CI-Jenkins-informational)](https://github.com/Snyxex/PipeX/commits/main/)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-types-included-blue)](https://github.com/Snyxex/PipeX/blob/main/package.json)
9
+ [![npm package size](https://img.shields.io/npm/unpacked-size/@snyxex/pipex)](https://www.npmjs.com/package/@snyxex/pipex)
9
10
 
10
11
  ## Installation
11
12
 
12
- The npm package is being prepared as `@snyxex/pipex`; publication and
13
- scope ownership must be verified before installing it from the registry.
13
+ ```sh
14
+ npm install @snyxex/pipex
15
+ ```
14
16
 
15
- After publication:
17
+ Requires **Node.js 22 or newer** and ESM. PipeX uses Node.js streams, cryptography, and filesystem facilities; it does not provide a browser build.
16
18
 
17
- ```bash
18
- npm install @snyxex/pipex
19
+ ## Quick Start
20
+
21
+ This in-memory example requires no native filesystem bindings.
22
+
23
+ ```ts
24
+ import { DataEngine, CompressionPlugin } from '@snyxex/pipex';
25
+
26
+ const engine = new DataEngine().use(
27
+ new CompressionPlugin({ type: 'gzip', level: 6 }),
28
+ );
29
+
30
+ const encoded = await engine.binary.run({ id: 42, status: 'ready' });
31
+ const original = await engine.binary.undo<{ id: number; status: string }>(encoded);
32
+
33
+ console.log(original); // { id: 42, status: 'ready' }
19
34
  ```
20
35
 
21
- Until then, install the development version directly from this repository:
36
+ ## Core Concepts
37
+
38
+ - **DataEngine:** Owns the configured plugin chain, resource limits, operation lifecycle, and binary/file/stream controllers.
39
+ - **Controllers:** `engine.binary` processes in-memory values, `engine.file` works with paths under an allowed root, and `engine.stream` connects Node.js streams.
40
+ - **Plugin:** Implements `process(Buffer, context)` and optionally `reverse` or `createStream`.
41
+ - **Transformation:** Plugins run in registration order. Reverse transformations execute reversible plugins in the opposite order.
42
+ - **Capabilities:** Query whether a plugin supports processing, reversal, or native/fallback streaming.
43
+ - **Execution context:** Request-scoped metadata, cancellation signal, limits, and optional logging/tracing.
44
+ - **Source and destination:** The input and output objects passed to the relevant controller; they are concepts, not exported PipeX classes.
45
+
46
+ `pack()` and `unpack()` are **serialization-only** operations; they do not apply the transformation pipeline.
47
+
48
+ ## Transformation Examples
49
+
50
+ ### Compression
22
51
 
23
- ```bash
24
- npm install github:Snyxex/PipeX
52
+ ```ts
53
+ import { DataEngine, CompressionPlugin } from '@snyxex/pipex';
54
+
55
+ const engine = new DataEngine().use(new CompressionPlugin({ type: 'brotli', level: 5 }));
56
+ const result = await engine.binary.run('Repeated application data');
57
+ console.log(await engine.binary.undo<string>(result));
25
58
  ```
26
59
 
27
- The older unscoped package `pipex` belongs to a different npm publisher.
28
- Do not install it expecting this project.
60
+ Compression types: `gzip`, `brotli`, and `none`.
29
61
 
30
- ## Quick start
62
+ ### Encryption
31
63
 
32
64
  ```ts
33
65
  import { randomBytes } from 'node:crypto';
34
- import { DataEngine, CompressionPlugin, EncryptionPlugin } from '@snyxex/pipex';
66
+ import { DataEngine, EncryptionPlugin } from '@snyxex/pipex';
67
+
68
+ // Demonstration only: retain this key securely to decrypt persisted data.
69
+ const key = randomBytes(32);
70
+ const engine = new DataEngine().use(new EncryptionPlugin({
71
+ algorithm: 'aes-256-gcm',
72
+ key,
73
+ allowLegacyDecrypt: false,
74
+ }));
75
+
76
+ const encrypted = await engine.binary.run('confidential');
77
+ const plaintext = await engine.binary.undo<string>(encrypted);
78
+ console.log(plaintext);
79
+ ```
35
80
 
36
- const engine = new DataEngine({
37
- maxInputBytes: 64 * 1024 * 1024,
38
- operationTimeoutMs: 30_000,
39
- })
81
+ Alternative algorithm: `chacha20-poly1305`. Both require a 32-byte key.
82
+
83
+ ### Hashing / HMAC integrity
84
+
85
+ ```ts
86
+ import { DataEngine, HashingPlugin } from '@snyxex/pipex';
87
+
88
+ const engine = new DataEngine().use(new HashingPlugin({
89
+ algorithm: 'sha256',
90
+ secret: process.env.PIPEX_HMAC_SECRET ?? (() => { throw new Error('Missing HMAC key'); })(),
91
+ }));
92
+
93
+ const signed = await engine.binary.run('message');
94
+ const verified = await engine.binary.undo<string>(signed);
95
+ console.log(verified);
96
+ ```
97
+
98
+ `HashingPlugin` **appends a keyed HMAC** and verifies it during reversal. It is not a standalone, one-way digest API. The secret must contain at least 16 characters; use a high-entropy secret in production.
99
+
100
+ ### Combined reversible pipeline
101
+
102
+ ```ts
103
+ import { randomBytes } from 'node:crypto';
104
+ import { DataEngine, CompressionPlugin, EncryptionPlugin, HashingPlugin } from '@snyxex/pipex';
105
+
106
+ const encryptionKey = randomBytes(32);
107
+ const hmacSecret = randomBytes(32).toString('hex');
108
+ const engine = new DataEngine()
40
109
  .use(new CompressionPlugin({ type: 'gzip', level: 6 }))
41
- .use(new EncryptionPlugin({ algorithm: 'aes-256-gcm', key: randomBytes(32) }));
110
+ .use(new EncryptionPlugin({ algorithm: 'aes-256-gcm', key: encryptionKey }))
111
+ .use(new HashingPlugin({ algorithm: 'sha512', secret: hmacSecret }));
42
112
 
43
- const result = await engine.binary.run({ id: 1, username: 'dev' });
44
- const restored = await engine.binary.undo(result, { timeoutMs: 30_000 });
113
+ const result = await engine.binary.run({ event: 'example' });
114
+ const restored = await engine.binary.undo<{ event: string }>(result);
115
+ console.log(restored);
45
116
  ```
46
117
 
47
- Keep encryption keys outside source control and load them from a secret manager or KMS in production.
48
- Generic KMS adapters expose queryable operation capabilities and receive an
49
- `AbortSignal` governed by the engine deadline. See
50
- [Production operations](./docs/enterprise.md#encryption-and-key-management).
118
+ Keep keys outside code and configuration repositories. The HMAC in this example is an optional additional integrity layer; authenticated encryption already authenticates encrypted data.
51
119
 
52
- ## Choosing the right API
120
+ ## Data Interfaces
53
121
 
54
- | Use case | API | Notes |
122
+ | Controller | Use | Runtime considerations |
55
123
  | --- | --- | --- |
56
- | Transform an object or buffer in memory | `binary.run()` / `binary.undo()` | Applies the configured plugin chain |
57
- | Encode or decode MessagePack | `binary.pack()` / `binary.unpack()` | Serialization only; no plugins |
58
- | Transform an existing file | `file.process()` / `file.reverse()` | Atomic output replacement and bounded streaming |
59
- | Encode object frames to a file | `file.pack()` / `file.unpack()` | Serialization only; includes a manifest |
60
- | Transform Node.js byte streams | `stream.pipe()` | Applies plugins with backpressure |
61
- | Encode object streams | `stream.pack()` / `stream.unpack()` | Serialization only; includes a manifest |
124
+ | `engine.binary` | Values and buffers held in memory | Does not load native file bindings |
125
+ | `engine.file` | Files on disk | Uses Koffi-based native filesystem operations |
126
+ | `engine.stream` | Large streams, pipes, sockets | Uses Node.js backpressure and supports `AbortSignal` |
62
127
 
63
- `pack()` and `unpack()` never encrypt, compress, or hash. Use `run()`/`undo()`, `process()`/`reverse()`, or `stream.pipe()` for plugin transformations.
128
+ ### Binary
64
129
 
65
- For results received over a transport or reconstructed from storage, specify an
66
- application-owned type: `engine.binary.undo(received, { expectedType: 'object' })`.
67
- Never derive `expectedType` or the raw-buffer `forceType` from untrusted metadata.
68
- Locally produced results retain an implicit trusted type while their Buffer
69
- identity is preserved. This tightens the decoding contract without changing the
70
- ciphertext format; modified type metadata is rejected before decryption.
130
+ ```ts
131
+ const encoded = await engine.binary.run({ ok: true });
132
+ const decoded = await engine.binary.undo(encoded);
133
+ const serialized = engine.binary.pack({ ok: true });
134
+ const parsed = engine.binary.unpack<{ ok: boolean }>(serialized);
135
+ ```
71
136
 
72
- ## Files
137
+ For data reconstructed after transport or storage, supply a trusted `expectedType` to `undo`; never trust unverified type metadata.
73
138
 
74
- Output paths are constrained to `allowedRoot`. When it is omitted, PipeX uses the current working directory. Parent directories must already exist.
139
+ ### Files
75
140
 
76
141
  ```ts
77
- await engine.file.process('./data/input.bin', './data/input.pipex', './data', { timeoutMs: 60_000 });
78
- await engine.file.reverse('./data/input.pipex', './data/restored.bin', './data');
142
+ await engine.file.process('./data/source.bin', './data/source.px', './data');
143
+ await engine.file.reverse('./data/source.px', './data/restored.bin', './data');
79
144
  ```
80
145
 
81
- PipeX rejects traversal, symlink escapes, special files, and identical or hard-linked
82
- input/output files. File sessions acquire native handles before plugins run.
83
- Windows uses root-relative opens and handle-based replacement; POSIX uses
84
- no-follow directory-relative opens and a private temporary directory. Outputs
85
- are replaced only after successful processing. Koffi supplies the native bindings
86
- and is loaded only when using the file controller. Keep roots under the service
87
- account's exclusive control; see [File-system boundary](./docs/enterprise.md#file-system-boundary).
146
+ Output is staged and atomically replaced. Paths are restricted to `allowedRoot`; create the parent directories first.
88
147
 
89
- ## Streams and cancellation
148
+ ### Streams
90
149
 
91
150
  ```ts
92
151
  import { createReadStream, createWriteStream } from 'node:fs';
93
152
 
94
153
  const controller = new AbortController();
95
154
  await engine.stream.pipe(
96
- createReadStream('./input.bin'),
97
- createWriteStream('./output.pipex'),
155
+ createReadStream('./source.bin'),
156
+ createWriteStream('./output.px'),
98
157
  false,
99
158
  { signal: controller.signal, timeoutMs: 30_000 },
100
159
  );
101
160
  ```
102
161
 
103
- Encryption streams use the versioned `PXAE` format and authenticate bounded
104
- frames before releasing each frame. A final authenticated frame detects
105
- truncation, while sequence numbers detect reordering and duplication. HMAC
106
- verification still withholds the complete bounded message because its appended
107
- digest authenticates the stream only at EOF.
162
+ The `reverse` argument is `true` when decoding. Serialization-only stream adapters are `engine.stream.pack()` and `engine.stream.unpack()`.
108
163
 
109
- `EncryptionPlugin` defaults to 64 KiB plaintext frames (constrained by
110
- `maxFrameBytes`). Its v4 writer never emits the old unversioned format. The
111
- legacy reader is enabled temporarily for migration and can be disabled with
112
- `allowLegacyDecrypt: false`. See [Encryption v4 migration](./docs/encryption-v4-migration.md).
164
+ ## Plugins
113
165
 
114
- ## Configuration
166
+ ### Built-in plugins
115
167
 
116
- Built-in plugins are registered automatically:
168
+ | Plugin | Purpose | Notes |
169
+ | --- | --- | --- |
170
+ | `CompressionPlugin` | Gzip/Brotli transformations | Reversible; native streaming |
171
+ | `EncryptionPlugin` | AES-256-GCM / ChaCha20-Poly1305 | Reversible authenticated frames |
172
+ | `HashingPlugin` | HMAC-SHA-256 / HMAC-SHA-512 | Appends and verifies a keyed digest |
173
+ | `BenchmarkPlugin` | Processing metrics | Observes transformation timings |
174
+ | `ValidationPlugin` | Application schema validation | Integrates Zod |
175
+ | `WorkerPoolPlugin` | Caller-supplied worker module transforms | Opt-in local Piscina pool |
176
+ | `KmsEncryptionPlugin` | Envelope encryption using caller-supplied KMS | Binary-only; needs KMS provider |
117
177
 
118
- ```ts
119
- const engine = await DataEngine.fromConfig({
120
- limits: { maxInputBytes: 32 * 1024 * 1024, operationTimeoutMs: 15_000 },
121
- logger,
122
- auditLogger,
123
- plugins: [
124
- { name: 'compression', options: { type: 'brotli', level: 5 } },
125
- { name: 'hashing', options: { algorithm: 'sha256', secret: process.env.PIPEX_HMAC_SECRET } },
126
- ],
127
- });
178
+ The `Plugins` object exposes these constructors under their shortened names, e.g. `Plugins.Compression`.
128
179
 
129
- console.log(engine.pipeline);
130
- // ['compression@3.0.0', 'hashing@3.0.0']
131
- ```
180
+ ### Plugin lifecycle
132
181
 
133
- Available names are `compression`, `encryption`, `hashing`, `benchmark`, `worker-pool`, `validation`, and `kms-encryption`. Options containing runtime objects, such as Zod schemas or KMS providers, must be supplied programmatically.
182
+ Register with `engine.use(plugin)` in the intended order, or use `DataEngine.fromConfig()` with registered plugin names. Third-party plugins may implement `ProcessorPlugin` or extend `BasePlugin`. Registration validates capability declarations; pipeline configuration cannot change during an active operation. Reverse operations reject pipelines containing non-reversible plugins rather than silently skipping a step.
134
183
 
135
- The local `worker-pool` plugin executes caller-owned worker module exports with
136
- bounded threads, queue admission, task deadlines, and deterministic shutdown.
137
- See [Local worker pools](./docs/enterprise.md#local-worker-pools).
184
+ Read [the full API reference](docs/api.md) for the plugin contract, constructor options, and error types.
138
185
 
139
- `fromConfig()` also accepts `limits`, `logger`, `tracer`, `auditLogger`, `dlq`, `schema`, and `schemaRegistry`. `dlq` is the compatibility name for an optional caller-provided failure sink; PipeX does not persist or replay its contents. Integration objects are validated immediately so configuration mistakes fail during startup.
186
+ ## Streaming & Backpressure
140
187
 
141
- Register a custom plugin with `DataEngine.registerPlugin('redact', RedactPlugin)`.
188
+ `stream.pipe(source, destination, reverse?, options?)` connects a source to the configured transform chain and destination, awaiting completion. Node.js backpressure propagates across native stream plugins. `stream.into(destination)` and `stream.reverseInto(destination)` expose writable adapters for use with Node.js pipelines.
142
189
 
143
- `engine.plugins` and `engine.pipeline` return immutable snapshots. Configure the pipeline before starting work; `use()` rejects changes while any operation is active.
190
+ Plugins lacking `createStream()` use a per-chunk fallback **only when chunk independence is valid**. Such a fallback is not suitable for algorithms requiring whole-message authentication or global framing.
144
191
 
145
- ## Custom plugins
192
+ Authenticated encryption emits bounded frames, each verified before its plaintext is released. Previously authenticated frames can already have been consumed if a later frame or final marker fails: **treat successful stream completion as the transaction commit point**. HMAC verification, unlike per-frame AEAD, withholds complete bounded plaintext until its final digest verifies.
193
+
194
+ Cancellation uses `AbortSignal`; operation limits and deadlines apply to stream processing.
195
+
196
+ ### Lifecycle, cancellation, and cleanup
197
+
198
+ PipeX runs byte-stream transformations through Node.js `stream/promises.pipeline()`. This awaits completion, propagates failures from the source, any plugin transform, or the destination, and destroys connected streams when a stage fails or the operation is aborted.
146
199
 
147
200
  ```ts
148
- import { BasePlugin, type ProcessorContext } from '@snyxex/pipex';
201
+ import { createReadStream, createWriteStream } from 'node:fs';
202
+ import { DataEngine, CompressionPlugin } from '@snyxex/pipex';
149
203
 
150
- class PrefixPlugin extends BasePlugin {
151
- readonly name = 'prefix';
152
- readonly version = '1.0.0';
204
+ const controller = new AbortController();
205
+ const engine = new DataEngine().use(new CompressionPlugin({ type: 'gzip' }));
153
206
 
154
- process(data: Buffer, _context: ProcessorContext): Buffer {
155
- return Buffer.concat([Buffer.from('PX:'), data]);
156
- }
207
+ await engine.stream.pipe(
208
+ createReadStream('./input.bin'),
209
+ createWriteStream('./output.px'),
210
+ false,
211
+ { signal: controller.signal, timeoutMs: 30_000 },
212
+ );
157
213
 
158
- reverse(data: Buffer, _context: ProcessorContext): Buffer {
159
- return data.subarray(3);
160
- }
161
- }
214
+ // controller.abort() cancels an operation in progress.
215
+ ```
216
+
217
+ For a destination you already own, `stream.into(destination, options)` and `stream.reverseInto(destination, options)` expose a writable endpoint. Connect external sources using `pipeline()`, **not** unguarded `.pipe()`:
218
+
219
+ ```ts
220
+ import { pipeline } from 'node:stream/promises';
221
+
222
+ await pipeline(
223
+ createReadStream('./input.bin'),
224
+ engine.stream.into(createWriteStream('./output.px'), { signal: controller.signal }),
225
+ { signal: controller.signal },
226
+ );
162
227
  ```
163
228
 
164
- Plugins without `createStream()` use a chunk-based fallback. They must be safe to run independently for every stream chunk. Plugins that need whole-message semantics should implement a framed native stream or use the binary API.
229
+ Backpressure propagates through the transforms: a slow downstream writable pauses upstream reads instead of buffering the entire input. Memory still depends on configured frame limits and plugin implementations; `binary.run()` is deliberately in-memory, and HMAC verification may hold a bounded complete message until its digest is verified.
230
+
231
+ **Lifecycle rules:** Each invocation requires fresh source and destination stream instances; the same `DataEngine` may process multiple operations. On abort or failure, the source, plugin streams, and destination are destroyed. A failed destination can contain partial output: use the file controller's atomic-output operations when partial files must not become visible. Set `timeoutMs` and resource limits appropriate for large inputs. A caller-owned `AbortSignal` is supported by binary, stream, and file controllers; aborted operations reject rather than producing partial success.
232
+
233
+ ## API Reference
165
234
 
166
- ## Operational hooks
235
+ See **[docs/api.md](docs/api.md)** for public entry points, signatures, options, return values, error classes, and serialization semantics.
167
236
 
168
- PipeX supports structured logging, audit logging, tracing, progress events,
169
- bounded retries, deadlines, concurrency limits, and an optional caller-provided
170
- failure sink. The existing `dlq`/`setDlq()` names remain supported for
171
- compatibility. See [Failure-sink semantics](./docs/enterprise.md#retries-and-caller-provided-failure-sink)
172
- before routing potentially sensitive chunks. Observer callback failures are
173
- isolated from data processing.
237
+ Primary operations:
174
238
 
175
239
  ```ts
176
- engine.setLogger(logger).setAuditLogger(auditLogger).on('error', (error, requestId) => {
177
- console.error({ requestId, error: error.message });
178
- });
240
+ new DataEngine(limits?)
241
+ DataEngine.fromConfig(config)
242
+ engine.use(plugin)
243
+ engine.binary.run(input, options?)
244
+ engine.binary.undo(result, options?)
245
+ engine.binary.pack(data)
246
+ engine.binary.unpack(buffer)
247
+ engine.file.process(inputPath, outputPath, allowedRoot?, options?)
248
+ engine.file.reverse(inputPath, outputPath, allowedRoot?, options?)
249
+ engine.stream.pipe(source, destination, reverse?, options?)
179
250
  ```
180
251
 
181
- See [Architecture](./docs/architecture.md) and [Production operations](./docs/enterprise.md).
252
+ ## Security
253
+
254
+ **Hashing is not encryption.** HMAC detects unauthorized modification when its key remains secret; it does not conceal contents. Authenticated encryption provides confidentiality and integrity. Complete-message integrity for framed encrypted streams is confirmed only after the final authenticated frame and successful completion.
182
255
 
183
- ## Development
256
+ - **Encryption:** AES-256-GCM and ChaCha20-Poly1305 with 32-byte keys; authenticated framing uses the `PXAE` v4 format.
257
+ - **Authentication tags:** A frame is not emitted as plaintext until its AEAD tag verifies. Sequence numbers and a final authenticated frame detect reordering, duplication, and truncation.
258
+ - **Key handling:** Supply keys through a secret manager or application-managed KMS. PipeX is not a key vault. Do not reuse a randomly generated per-process key for data requiring later decryption.
259
+ - **HMAC:** SHA-256 or SHA-512 with a caller-owned secret. A mismatched or truncated digest rejects reversal.
260
+ - **Limits:** Input, output, frame, concurrency, and timeout limits protect the host; configure them for the deployment.
261
+ - **KMS:** External providers are supplied by the application; the KMS plugin is binary-only and requires a working `generateDataKey` capability.
184
262
 
185
- Use Node.js 22 or newer with npm (Jenkins validates current Node.js 22, 24, and 26 releases).
263
+ **Compatibility:** Version 4 encryption writes framed `PXAE` only. Reading legacy unversioned v3 encrypted data is a temporary migration option (`allowLegacyDecrypt`, default `false`; explicitly enable it only during migration); disable it after migration. Format compatibility is not a promise that all future versions or arbitrary plugin combinations can read every older payload. Keep original plugin configuration and secrets where reversibility is required.
186
264
 
187
- ```bash
188
- npm ci --ignore-scripts --no-audit --no-fund
189
- npm run quality:ci
190
- npm audit --audit-level=high
191
- npm pack --dry-run --json --ignore-scripts
265
+ See [Encryption migration](docs/encryption-v4-migration.md) and [Production security](docs/enterprise.md).
266
+
267
+ ## Error Handling
268
+
269
+ Operations reject on invalid configuration, unsupported reverse/stream operations, resource-limit violations, authentication failures, aborted operations, timeouts, and underlying stream/filesystem errors. Typed errors include `PipeXError`, `UnsupportedReverseError`, `UnsupportedStreamingError`, `OperationAbortedError`, `OperationTimeoutError`, and worker/KMS errors. Check `error.code` on `PipeXError` when branching on supported classifications; other errors may be ordinary `Error` instances.
270
+
271
+ ```ts
272
+ import { OperationTimeoutError } from '@snyxex/pipex';
273
+
274
+ try {
275
+ await engine.binary.run('data', { timeoutMs: 1000 });
276
+ } catch (error) {
277
+ if (error instanceof OperationTimeoutError) {
278
+ console.error('Transformation timed out');
279
+ } else {
280
+ throw error;
281
+ }
282
+ }
192
283
  ```
193
284
 
194
- `npm run quality:ci` executes the production typecheck, build, tooling, unit,
195
- integration, security, package, consumer, and short performance suites.
196
- Jenkins is the only configured CI system; the root `Jenkinsfile` tests PRs
197
- and branches and archives an npm tarball but does not publish it.
285
+ ## Optional Features
198
286
 
199
- For release planning see [Release procedure](docs/releasing.md) and
200
- [Release readiness](docs/npm-release-readiness.md). Perform a full secret scan,
201
- verify the npm publishing identity, and use a separately protected release job
202
- before distributing any tarball.
287
+ - **Worker Threads:** `WorkerPoolPlugin` is opt-in at runtime, but `piscina` is presently installed as a regular dependency. Workers execute caller-provided module exports, not a built-in job scheduler.
288
+ - **Native file operations:** `engine.file` uses `koffi`, currently a regular dependency. Binary and stream controllers do not load these native bindings. File operations fail if required native bindings are unavailable; there is no path-only fallback.
289
+ - **KMS:** `KmsEncryptionPlugin` requires a provider implementation supplied by your application.
290
+ - **Validation and observability:** Zod validation, logging, tracing, audit logging, and caller-owned failure sinks are integrated only when configured.
203
291
 
204
- Large throughput benchmarking is intentionally excluded from `npm test` and
205
- CI. Run it manually with `npm run benchmark:large` and
206
- `PIPEX_BENCHMARK_BYTES` as needed.
292
+ ## Performance & Resource Limits
207
293
 
208
- ## License
294
+ Streaming reduces whole-payload buffering, but some operations (including HMAC verification and binary processing) necessarily retain bounded data in memory. The engine enforces finite defaults for input/output bytes, frames, concurrent operations, retry attempts, and deadlines.
209
295
 
210
- MIT © Snyxex
296
+ ```ts
297
+ const limited = new DataEngine({
298
+ maxInputBytes: 64 * 1024 * 1024,
299
+ maxOutputBytes: 256 * 1024 * 1024,
300
+ maxFrameBytes: 8 * 1024 * 1024,
301
+ maxConcurrentOperations: 32,
302
+ operationTimeoutMs: 30_000,
303
+ });
304
+ ```
305
+
306
+ These are example limits, not all defaults. See [resource-limit details](docs/enterprise.md#resource-limits).
211
307
 
212
- ## Contributing and security
308
+ ## Documentation
213
309
 
214
- - [Contributing guide](CONTRIBUTING.md)
215
- - [Support](SUPPORT.md)
216
- - [Security policy and responsible disclosure](SECURITY.md)
217
- - [Code of conduct](CODE_OF_CONDUCT.md)
310
+ - [Complete public API reference](docs/api.md)
311
+ - [Architecture](docs/architecture.md)
312
+ - [Production operations and security](docs/enterprise.md)
313
+ - [Encryption v4 migration](docs/encryption-v4-migration.md)
218
314
  - [Changelog](CHANGELOG.md)
219
- - [Release preparation](docs/releasing.md)
220
315
 
221
- Use GitHub issues for ordinary bugs and features, **not** for undisclosed vulnerabilities. Jenkins is the project CI system; no GitHub Actions workflows are configured.
316
+ ## Contributing & License
317
+
318
+ See [CONTRIBUTING.md](CONTRIBUTING.md), [SUPPORT.md](SUPPORT.md), and [SECURITY.md](SECURITY.md). Report vulnerabilities privately according to the security policy, not in public issues.
319
+
320
+ MIT © Snyxex.
@@ -0,0 +1,35 @@
1
+ import { Duplex } from "node:stream";
2
+ import { t as BasePlugin } from "./plugin-D85NMNiy.mjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.mjs";
4
+ type CompressionType = 'gzip' | 'brotli' | 'none';
5
+ /** Gzip level is validated at runtime to be within 0–9. */
6
+ interface GzipCompressionOptions {
7
+ readonly type: 'gzip';
8
+ readonly level?: number;
9
+ }
10
+ /** Brotli quality is validated at runtime to be within 0–11. */
11
+ interface BrotliCompressionOptions {
12
+ readonly type: 'brotli';
13
+ readonly level?: number;
14
+ }
15
+ /** Pass-through compression never accepts a level option. */
16
+ interface NoCompressionOptions {
17
+ readonly type: 'none';
18
+ readonly level?: never;
19
+ }
20
+ /** Algorithm-discriminated compression configuration. */
21
+ type CompressionOptions = GzipCompressionOptions | BrotliCompressionOptions | NoCompressionOptions;
22
+ /**
23
+ * CompressionPlugin — Standard library plugin for Gzip and Brotli.
24
+ * Prepends a 1-byte header to identify the compression type.
25
+ */
26
+ declare class CompressionPlugin extends BasePlugin {
27
+ protected options: CompressionOptions;
28
+ readonly name = "compression";
29
+ readonly version = "3.0.0";
30
+ constructor(options: CompressionOptions);
31
+ process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
32
+ reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
33
+ createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
34
+ }
35
+ export { GzipCompressionOptions as a, CompressionType as i, CompressionOptions as n, NoCompressionOptions as o, CompressionPlugin as r, BrotliCompressionOptions as t };
@@ -0,0 +1,35 @@
1
+ import { Duplex } from "node:stream";
2
+ import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.cjs";
4
+ type CompressionType = 'gzip' | 'brotli' | 'none';
5
+ /** Gzip level is validated at runtime to be within 0–9. */
6
+ interface GzipCompressionOptions {
7
+ readonly type: 'gzip';
8
+ readonly level?: number;
9
+ }
10
+ /** Brotli quality is validated at runtime to be within 0–11. */
11
+ interface BrotliCompressionOptions {
12
+ readonly type: 'brotli';
13
+ readonly level?: number;
14
+ }
15
+ /** Pass-through compression never accepts a level option. */
16
+ interface NoCompressionOptions {
17
+ readonly type: 'none';
18
+ readonly level?: never;
19
+ }
20
+ /** Algorithm-discriminated compression configuration. */
21
+ type CompressionOptions = GzipCompressionOptions | BrotliCompressionOptions | NoCompressionOptions;
22
+ /**
23
+ * CompressionPlugin — Standard library plugin for Gzip and Brotli.
24
+ * Prepends a 1-byte header to identify the compression type.
25
+ */
26
+ declare class CompressionPlugin extends BasePlugin {
27
+ protected options: CompressionOptions;
28
+ readonly name = "compression";
29
+ readonly version = "3.0.0";
30
+ constructor(options: CompressionOptions);
31
+ process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
32
+ reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
33
+ createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
34
+ }
35
+ export { GzipCompressionOptions as a, CompressionType as i, CompressionOptions as n, NoCompressionOptions as o, CompressionPlugin as r, BrotliCompressionOptions as t };
@@ -0,0 +1 @@
1
+ import{brotliCompress as e,brotliDecompress as t,constants as n,createBrotliCompress as r,createBrotliDecompress as i,createGunzip as a,createGzip as o,gunzip as s,gzip as c}from"node:zlib";import{promisify as l}from"node:util";import{Duplex as u,PassThrough as d,Readable as f,Transform as p,compose as m}from"node:stream";import{b as h,i as g,n as _,o as v,r as y}from"./resourceLimits-CpDWwraK.mjs";import{p as b}from"./core-DNchiRD5.mjs";const x={none:0,gzip:1,brotli:2},S={0:`none`,1:`gzip`,2:`brotli`},C=l(c),w=l(s),T=l(e),E=l(t);var D=class extends g{options;name=`compression`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.type in x))throw new h({transformName:`compression`,stage:`configuration`});if(e.level!==void 0&&!Number.isInteger(e.level)||e.type===`gzip`&&e.level!==void 0&&(e.level<0||e.level>9)||e.type===`brotli`&&e.level!==void 0&&(e.level<0||e.level>11)||e.type===`none`&&e.level!==void 0)throw new v({transformName:`compression`})}async process(e,t){let r=_(t),i=y(t);if(e.length>r)throw new v({transformName:`compression`,stage:`input`});let{type:a,level:o}=this.options,s=Buffer.from([x[a]]);if(e.length>i-s.length&&a===`none`||i<=s.length&&a!==`none`)throw new v({transformName:`compression`,stage:`output`});let c;return c=a===`gzip`?await C(e,{level:o??6,maxOutputLength:i-s.length}):a===`brotli`?await T(e,{params:{[n.BROTLI_PARAM_QUALITY]:o??11},maxOutputLength:i-s.length}):e,Buffer.concat([s,c])}async reverse(e,t){let n=_(t),r=y(t);if(e.length>n)throw new v({transformName:`compression`,stage:`input`});if(e.length<1)throw new v({transformName:`compression`});let i=e.readUInt8(0),a=S[i],o=e.subarray(1);if(a===`gzip`)return await w(o,{maxOutputLength:r});if(a===`brotli`)return await E(o,{maxOutputLength:r});if(a!==`none`)throw new h({transformName:`compression`,stage:`configuration`});if(o.length>r)throw new v({transformName:`compression`,stage:`output`});return o}createStream(e,t){let{type:s,level:c}=this.options,l=_(t),g=y(t);if(e===`compress`){let e=s===`gzip`?o({level:c??6}):s===`brotli`?r({params:{[n.BROTLI_PARAM_QUALITY]:c??11}}):new d,t=!1,i=new p({transform(e,n,r){t||(t=!0,this.push(Buffer.from([x[s]]))),r(null,e)},flush(e){t||this.push(Buffer.from([x[s]])),e()}});return m(b(l,`compression input`),e,i,b(g,`compression output`))}return u.from(async function*(e){let t=e[Symbol.asyncIterator](),n,r=0,o=0;for(;!n;){let e=await t.next();if(e.done)throw new v({transformName:`compression`});let i=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(i.length>l-r)throw new v({transformName:`compression`,stage:`input`});r+=i.length,i.length>0&&(n=i)}let s=S[n.readUInt8(0)];if(!s)throw new h({transformName:`compression`,stage:`decompress`});let c=s===`gzip`?a():s===`brotli`?i():new d;async function*u(){let e=n.subarray(1);for(e.length>0&&(yield e);;){let e=await t.next();if(e.done)return;let n=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(n.length>l-r)throw new v({transformName:`compression`,stage:`input`});r+=n.length,n.length>0&&(yield n)}}try{for await(let e of m(f.from(u()),c)){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length>g-o)throw new v({transformName:`compression`,stage:`output`});o+=t.length,yield t}}finally{c.destroy();try{await t.return?.()}catch{}}})}};export{D as t};
@@ -0,0 +1 @@
1
+ let e=require("node:zlib"),t=require("node:util"),n=require("node:stream");const r=require("./resourceLimits-lJrEhDE5.cjs"),i=require("./core-DSIwvTqu.cjs"),a={none:0,gzip:1,brotli:2},o={0:`none`,1:`gzip`,2:`brotli`},s=(0,t.promisify)(e.gzip),c=(0,t.promisify)(e.gunzip),l=(0,t.promisify)(e.brotliCompress),u=(0,t.promisify)(e.brotliDecompress);var d=class extends r.i{options;name=`compression`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.type in a))throw new r.b({transformName:`compression`,stage:`configuration`});if(e.level!==void 0&&!Number.isInteger(e.level)||e.type===`gzip`&&e.level!==void 0&&(e.level<0||e.level>9)||e.type===`brotli`&&e.level!==void 0&&(e.level<0||e.level>11)||e.type===`none`&&e.level!==void 0)throw new r.o({transformName:`compression`})}async process(t,n){let i=r.n(n),o=r.r(n);if(t.length>i)throw new r.o({transformName:`compression`,stage:`input`});let{type:c,level:u}=this.options,d=Buffer.from([a[c]]);if(t.length>o-d.length&&c===`none`||o<=d.length&&c!==`none`)throw new r.o({transformName:`compression`,stage:`output`});let f;return f=c===`gzip`?await s(t,{level:u??6,maxOutputLength:o-d.length}):c===`brotli`?await l(t,{params:{[e.constants.BROTLI_PARAM_QUALITY]:u??11},maxOutputLength:o-d.length}):t,Buffer.concat([d,f])}async reverse(e,t){let n=r.n(t),i=r.r(t);if(e.length>n)throw new r.o({transformName:`compression`,stage:`input`});if(e.length<1)throw new r.o({transformName:`compression`});let a=e.readUInt8(0),s=o[a],l=e.subarray(1);if(s===`gzip`)return await c(l,{maxOutputLength:i});if(s===`brotli`)return await u(l,{maxOutputLength:i});if(s!==`none`)throw new r.b({transformName:`compression`,stage:`configuration`});if(l.length>i)throw new r.o({transformName:`compression`,stage:`output`});return l}createStream(t,s){let{type:c,level:l}=this.options,u=r.n(s),d=r.r(s);if(t===`compress`){let t=c===`gzip`?(0,e.createGzip)({level:l??6}):c===`brotli`?(0,e.createBrotliCompress)({params:{[e.constants.BROTLI_PARAM_QUALITY]:l??11}}):new n.PassThrough,r=!1,o=new n.Transform({transform(e,t,n){r||(r=!0,this.push(Buffer.from([a[c]]))),n(null,e)},flush(e){r||this.push(Buffer.from([a[c]])),e()}});return(0,n.compose)(i.p(u,`compression input`),t,o,i.p(d,`compression output`))}return n.Duplex.from(async function*(t){let i=t[Symbol.asyncIterator](),a,s=0,c=0;for(;!a;){let e=await i.next();if(e.done)throw new r.o({transformName:`compression`});let t=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(t.length>u-s)throw new r.o({transformName:`compression`,stage:`input`});s+=t.length,t.length>0&&(a=t)}let l=o[a.readUInt8(0)];if(!l)throw new r.b({transformName:`compression`,stage:`decompress`});let f=l===`gzip`?(0,e.createGunzip)():l===`brotli`?(0,e.createBrotliDecompress)():new n.PassThrough;async function*p(){let e=a.subarray(1);for(e.length>0&&(yield e);;){let e=await i.next();if(e.done)return;let t=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(t.length>u-s)throw new r.o({transformName:`compression`,stage:`input`});s+=t.length,t.length>0&&(yield t)}}try{for await(let e of(0,n.compose)(n.Readable.from(p()),f)){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length>d-c)throw new r.o({transformName:`compression`,stage:`output`});c+=t.length,yield t}}finally{f.destroy();try{await i.return?.()}catch{}}})}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./compression-ZHOsKTJC.cjs");exports.CompressionPlugin=e.t;
@@ -0,0 +1,2 @@
1
+ import { a as GzipCompressionOptions, i as CompressionType, n as CompressionOptions, o as NoCompressionOptions, r as CompressionPlugin, t as BrotliCompressionOptions } from "./compression-C1nLQVur.cjs";
2
+ export { type BrotliCompressionOptions, type CompressionOptions, CompressionPlugin, type CompressionType, type GzipCompressionOptions, type NoCompressionOptions };
@@ -0,0 +1,2 @@
1
+ import { a as GzipCompressionOptions, i as CompressionType, n as CompressionOptions, o as NoCompressionOptions, r as CompressionPlugin, t as BrotliCompressionOptions } from "./compression-B0xKUa-N.mjs";
2
+ export { type BrotliCompressionOptions, type CompressionOptions, CompressionPlugin, type CompressionType, type GzipCompressionOptions, type NoCompressionOptions };
@@ -0,0 +1 @@
1
+ export{t as CompressionPlugin}from"./compression-ChJlMVwP.mjs";